GetMark -- get marked lines.
GetMark is a general tool for including/excluding parts of a file.
It can be used, for example, to extract parts of a file for use
in documentation, or to delete parts of a file such as the working
part of a solution.
The marks that it looks for are simple, and can be left in the
master source (they never print). The mark //+ (as looked for
with line.trim().equals("//+) in Java) begins printing, and the
opposite mark //- stops printing.
So, for a course exercise, you would develop the working
solution and comment it neatly, and add a //- mark after the TODO
comments but before the working solution, and a //+ mark after it.
For example:
public methodA() {
// TODO:
// Look up the object to be invoked.
// Use a Lookup Name of "ex31object"
//-
Object o = Naming.lookup("ex31object");
//+
// TODO #2
// Downcast the looked up object using the IIOP portability
//-
Ex31Object obj = (Ex31Object)PortableRemoteObject.narrow(
o, Ex31Object.class);
//+
}
When run through GetMark in "exclude" mode, the above will produce:
public methodA() {
// TODO:
// Look up the object to be invoked.
// Use a Lookup Name of "ex31object"
// TODO #2
// Downcast the looked up object using the IIOP portability
}
You could use this in a script:
for f in *.java
do
echo $f
java GetMark $f > ../solutions/$f
done
For an example of using GetMark for extraction
(GetMark first appeared in my
Java Cookbook),
see the comments in the code for GetMark itself.
In this version, the mode (include or extract) and the strings for
the marks are hard-coded; ideally they would come
from a Properties or Preferences object and/or from the command line. |