Class GenerateSource
java.lang.Object
|
+--GenerateSource
- public class GenerateSource
- extends java.lang.Object
GenerateSource: generate java source code for multiple API's from
a single source tree using #ifdef, #else, #endif tags.
This class generates the source code for a particular API version from
java source code which has been "enriched" with several tags.
How to use the program:
From usage:
usage: GenerateSource -d output_directory -t tagname1 -t tagnameN [source files]
- -d output_directory
- A required parameter, the directory where the resulting files should be written to.
Note: The current version will happily accept "." as output directory
or the same sourcefile as targetfile, thus overwriting all your files.
High on the TODO list.-
- -t tagname
- Define a tag this way. Multiple tags are defined using multiple -t switches.
Valid tags start with A-Za-z and after that any number of A-Za-z0-9_ chars.
Using tags in the sourcecode:
Currently understood tags are:
- #ifdef <tagname> <more tagnames>
- every line after the #ifdef line is only written if any of
the tagnames are defined.
Valid tags start with A-Za-z and after that any number of A-Za-z0-9_ chars.
Parsing the tagline will stop at the first invalid tag.
So a line like: "#ifdef VERSION_2_1 // only do this in VERSION_2_1" will
be read as "#ifdef VERSION_2_1".
Note that '=' as the begin of a tagName is reserved for future use.
- #else
- with this tag the writeStatus is negated.
If the program was currently writing lines based on the previous #ifdef
condition, it will stop writing.
If on the other hand the program was currently not writing lines
based on the previous #ifdef condition, it will start doing so.
- #endif
- The effect of the previous #ifdef line will be undone
- Example use:
-
#ifdef TagName_1_1 TagName_1_2 // If either of TagName_1_1 or TagName_1_2
// is defined writing will start now
...
#ifdef TagName_2_1 // from now on (TagName_1_1 or Tagname_1_2)
// and TagName_2_1 must be defined
...
#else // from now on (TagName_1_1 or Tagname_1_2)
// and not TagName_2_1 must be defined
...
#endif // If either of TagName_1_1 or TagName_1_2 is
// defined writing will take place
-
Remarks:
- Tags start with a '#' and may be preceded with spaces and tabs.
In fact anything lower than \u0020 is ignored.
- Lines starting with unknown tags are written.
Example: The line "#helloworld ..." is written as "#helloworld..."
- When a known tag is preceded with an extra '#' the line is written
with the extra '#' removed.
Example: A line starting with ##endif... is written as #endif...
- Tags within comments are used
- Example:
-
/**
#ifdef VERSION_2_1
* @deprecated
#else // VERSION_2_0
* A hot new method
#endif
*/
-
- if VERSION_2_1 is defined this is written as:
@deprecated
- And if not:
-
A hot new method
- The reason for this is that sometimes a new api version puts a @deprecated tag withing a comment.
This is also one of the reasons this class was written instead of just using cpp.
Method Summary |
void |
execute()
|
static void |
main(java.lang.String[] args)
|
static void |
usage()
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
VALID_TAG_CHAR_BEGIN
public static final java.lang.String VALID_TAG_CHAR_BEGIN
VALID_TAG_CHAR
public static final java.lang.String VALID_TAG_CHAR
GenerateSource
public GenerateSource(java.lang.String[] args)
throws java.lang.IllegalArgumentException
main
public static void main(java.lang.String[] args)
usage
public static void usage()
execute
public void execute()