1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
Class GenerateSource
java.lang.Object
|
+----GenerateSource
_________________________________________________________________
public class GenerateSource
extends 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.
_________________________________________________________________
Variable Index
o VALID_TAG_CHAR
o VALID_TAG_CHAR_BEGIN
Constructor Index
o GenerateSource(String[])
Method Index
o execute()
o main(String[])
o usage()
Variables
o VALID_TAG_CHAR_BEGIN
public static final String VALID_TAG_CHAR_BEGIN
o VALID_TAG_CHAR
public static final String VALID_TAG_CHAR
Constructors
o GenerateSource
public GenerateSource(String args[]) throws IllegalArgumentException
Methods
o main
public static void main(String args[])
o usage
public static void usage()
o execute
public void execute()
|