Package eu.bandm.tools.option
Class Compiler
java.lang.Object
eu.bandm.tools.option.Compiler
Compile java source for different front-ends for editing,
saving, decoding etc. program options, from an abstract option and type description.
The abstract description is given as an XML document. Its document type and semantics are discussed in the user documentation.
The compiled code is executed on the basis of the run-time system in package
Each run generates code for one class derivend from
The process of parsing is a complicated ping-pong between runtime class and generated code and documented with
The abstract description is given as an XML document. Its document type and semantics are discussed in the user documentation.
The compiled code is executed on the basis of the run-time system in package
eu.bandm.tools.option.runtime
Each run generates code for one class derivend from
Model
and one
optional from Gui
. Both will be in the same package, so that
"protected" fields and methods are mutally accessible.
The process of parsing is a complicated ping-pong between runtime class and generated code and documented with
Model
.
In BandM meta-tools one currently finds examples for all important special cases:
fragmentedLists | xslt/base/Options.xml : sourceRoots, etc. |
option w/o argument ("switch") | tdom_withOptions : patterns, noCompress, etc. |
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Base class for compiler phases.protected class
Zeroth phase, collect and generate code for enumerations.protected class
Compile code for the gui class.protected class
Create a parsing method for each option, and two "switch" methods calling these, one for short and one for long names.protected class
Minus-first phase, make crossref in which arguments an enum occurs.protected class
Common superclass forCompiler.Phase_usage_enumerations
andCompiler.Phase_usage_options
.protected class
Deliver the documentation text table for all enumeration types.protected class
Make one defaultusage()
function and many specials for each language appearing at least once in the collection of descriptions.protected class
First and main code generation phase.
Creates code for
(1) checks uniqueness and correctness of names and abbrevs.
(2) collects documentation intodesrcibes_argument_types
.
(3) makes value fields and getter methods for all option arguments
(4) generates code for enabling conditions.
(currently only simple "equal()" have been tested. -
Field Summary
Modifier and TypeFieldDescriptionprotected GeneratedAnnotation
protected GeneratedAnnotation
(package private) final Class
(package private) final Class
Maps option qualifiers to user readable option indication.'static final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentstatic final EnvironmentClass
Evidentprotected Map<Element_comment,
String> All comments (=separator lines) are collected in a first visit and used in subsequent GUI generation.(package private) final String
Default string printed at the top of the usage() output, if no language-specific value is specified inElement_printout_title
.protected CatalogByString
Inter-phase information transfer: all collected multi-lingual description texts.Human readable documentation text describing the option.static final String
static final int
All defined enumeration types.protected boolean
Whether lists may come in more than one portions.protected Format
Copy of argument needed only for Phase_enum.protected GeneratedClass
Inter-phase information transfer: the currently defined gui class.protected boolean
Whether the code for Rationals must be imported.protected static final int
Format of the generated java source files.static final String
Language selection for generating source comments and for the unparamterizedusage()
method.protected GeneratedMethod
protected GeneratedMethod
protected GeneratedClass
Inter-phase information transfer: the currently defined model class.protected MessageReceiver<SimpleMessage<XMLDocumentIdentifier>>
final String
Must correspond toeu.bandm.tools.option.runtime
final String
Must correspond toeu.bandm.tools.option.runtime
final String
Must correspond toeu.bandm.tools.option.runtime
static final String
Used only as argument toFormats.generationComment(String,String,int,boolean,String[])
.protected final String
Text used if even the language fallback mechanism fails to find a description.Lists with "plus" operator (not "star"), finally checked for non-emptynessprotected Map<Element_option,
GeneratedClass> The class generated to represent the repeting group of arguments.protected boolean
Whether there is at least one repeting group, requiring import of metaools ops.protected Map<Integer,
Element_option> All options which are positional, sorted by their index (short name).List of all options declared@required='yes'
Must not appear as names of user-defined enumerations.static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
add_comment_for_sourcetext
(@Opt Element_desc desc, GeneratedAnnotationTarget target) Add the description in theLINGUA_FRANCA
, if any, to the generated java object "target", by callingadd_comment_for_sourcetext(String,Element_desc, GeneratedAnnotationTarget)
protected void
add_comment_for_sourcetext
(@Opt String prefix, @Opt Element_desc desc, GeneratedAnnotationTarget target) Adds formatted user-level (=payload) comment to a generated method or field.protected boolean
For recognizing an option with at most one argument.(package private) static boolean
checkStar
(Element_rep el) Whether the repeting group is of "star" kind, not of "plus" kind.void
compile
(Element_optionlist data0, String packagename0, String classname_model, @Opt String classname_gui, String destdir, Format genComment, String inputfilename, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgr) Create source text for a model, and for a gui, if required.protected Format
expression
(String code) protected String
find_printout_title
(Element_optionlist olist, String lang) Looks in the header of the option list for the title text of the usage() output.protected Format
Generate a literal format containing a string in double quotes.protected boolean
listByAbbrev
(String enumname) Decides between different presentation formats in usage().static void
Execute compilation of the xml source to Java sources.protected void
make_usage
(Element_optionlist olist) CallVisitor.visit(Element_optionlist)
for all languages appearing at least once in the collection of descriptions.protected String
Prepend the correct number of lead-in minus signs to long name or abbrev name.protected void
Generate the parsing method for the positional options/arguments.protected Format
protected Format
statements
(String code) protected boolean
For recognizing totally empty type (no types nor rep group).protected static void
usage()
Print the usage information of this tool to stderr.
-
Field Details
-
NAME_PROGRAM
Used only as argument toFormats.generationComment(String,String,int,boolean,String[])
. Therefore an html encoding is sensible.- See Also:
-
VERSION_PROGRAM
- See Also:
-
formatCache
-
LINGUA_FRANCA
Language selection for generating source comments and for the unparamterizedusage()
method. Since the lingua franca of the computer area is English, these documentation texts are taken for program documentation = API documentation (NOT user documentation like "usage()" and error messages). It will also be used as the fall-back forusage()
if some doc text in the required language does not exist. If even a text inLINGUA_FRANCA
does not exist, a language will be chosen by random.- See Also:
-
BASECLASS_MODEL
-
BASECLASS_GUI
-
NAME_OF_DESCRIPTION_CATALOG_CLASS
Must correspond toeu.bandm.tools.option.runtime
- See Also:
-
NAME_OF_DESCRIPTION_CATALOG_FIELD
Must correspond toeu.bandm.tools.option.runtime
- See Also:
-
NAME_OF_MODEL_ACCESS_FUNCTION
Must correspond toeu.bandm.tools.option.runtime
- See Also:
-
RESERVED_TYPE_NAMES
Must not appear as names of user-defined enumerations. (This exclusion is for readability of documentation only.) -
ENUM_ITEMS_INLINE_THRESHOLD
public static final int ENUM_ITEMS_INLINE_THRESHOLD- See Also:
-
ENUM_ITEMS_INLINE_SEPARATOR
- See Also:
-
msgr
-
generationComment
Copy of argument needed only for Phase_enum. -
modelclass
Inter-phase information transfer: the currently defined model class. -
guiclass
Inter-phase information transfer: the currently defined gui class. -
descriptions
Inter-phase information transfer: all collected multi-lingual description texts. Filled byCompiler.Phase1
forElement_option
and inCompiler.Phase_enum
forElement_enum
andElement_enumitem
. -
annotationOverride
-
annotationDeprecated_has
-
maybeinactive
-
evalforinactive
-
meth_checkActive
-
meth_displayActive
-
option2tailClass
The class generated to represent the repeting group of arguments. -
desrcibes_argument_types
Human readable documentation text describing the option. One string contains the long and the short name, if present, followed bs the option's arguments' type signature. Is filled by Phase1 and read when makingusage(..)
, etc. -
element_conditionUsage
-
enums2options
-
enums
All defined enumeration types. -
enumClasses
-
enumsWithDocText
-
enumsWithItemDocText
-
enumValuesList
-
comment_name
All comments (=separator lines) are collected in a first visit and used in subsequent GUI generation. -
positionals
All options which are positional, sorted by their index (short name). -
overall_has_repeting
protected boolean overall_has_repetingWhether there is at least one repeting group, requiring import of metaools ops. -
fragmentedLists
protected boolean fragmentedListsWhether lists may come in more than one portions. -
hasRationals
protected boolean hasRationalsWhether the code for Rationals must be imported. -
nonEmptyGroups
Lists with "plus" operator (not "star"), finally checked for non-emptyness -
bothTags
Maps option qualifiers to user readable option indication.' -
CL_boolean
Evident -
CL_int
Evident -
CL_double
Evident -
CL_rational
Evident -
CL_char
Evident -
CL_String
Evident -
CL_List
Evident -
CL_LinkedList
Evident -
CL_EnumSet
Evident -
CL_Function
Evident -
CL_ArrayList
Evident -
CL_Component
Evident -
default_usage_header
Default string printed at the top of the usage() output, if no language-specific value is specified inElement_printout_title
.- See Also:
-
required
List of all options declared@required='yes'
-
noDoc
Text used if even the language fallback mechanism fails to find a description. Is included in usage() and (marked as bold) in generated api doc. (Can only happen if no text is included at all, ie. the option list contains only un-documented enumeration definitions.)- See Also:
-
LINEWIDTH
protected static final int LINEWIDTHFormat of the generated java source files.- See Also:
-
-
Constructor Details
-
Compiler
public Compiler()
-
-
Method Details
-
compile
public void compile(Element_optionlist data0, String packagename0, String classname_model, @Opt @Opt String classname_gui, String destdir, Format genComment, String inputfilename, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgr) Create source text for a model, and for a gui, if required.- Parameters:
data0
- the top-level element of the option specification filepackagename0
- where to to generate the sourceclassname_model
- the name of the generated classclassname_gui
- the name of the generated gui class.
May be==null
to suppress code generation.destdir
- where the java source hierarchy startsmsgr
- for error messages and warnings
-
expression
-
statement
-
statements
-
format_dquoted
Generate a literal format containing a string in double quotes. Can only be applied to keys, enum values etc. which definitely do not contain special characters. -
typeNotEmpty
For recognizing totally empty type (no types nor rep group). -
argnumberRedundant
For recognizing an option with at most one argument. Can LATER be used to shorten the usage-documentation of conditions. -
name2tag
Prepend the correct number of lead-in minus signs to long name or abbrev name. -
checkStar
Whether the repeting group is of "star" kind, not of "plus" kind. -
listByAbbrev
Decides between different presentation formats in usage(). -
find_printout_title
Looks in the header of the option list for the title text of the usage() output. -
add_comment_for_sourcetext
protected void add_comment_for_sourcetext(@Opt @Opt Element_desc desc, GeneratedAnnotationTarget target) Add the description in theLINGUA_FRANCA
, if any, to the generated java object "target", by callingadd_comment_for_sourcetext(String,Element_desc, GeneratedAnnotationTarget)
-
add_comment_for_sourcetext
protected void add_comment_for_sourcetext(@Opt @Opt String prefix, @Opt @Opt Element_desc desc, GeneratedAnnotationTarget target) Adds formatted user-level (=payload) comment to a generated method or field. Only theLINGUA_FRANCA
(currently English) is output, since all other text generated by the tooljavadoc
is in this language. The text is wrapped in a<span class="bandmUser">
xhtml tag for css style formatting.- Parameters:
prefix
- prepended to the found text, also contained in the wrapping tag.
-
make_usage
CallVisitor.visit(Element_optionlist)
for all languages appearing at least once in the collection of descriptions. -
parsePositional
protected void parsePositional()Generate the parsing method for the positional options/arguments. -
usage
protected static void usage()Print the usage information of this tool to stderr. -
main
Execute compilation of the xml source to Java sources. Additionally the xml source is copied into the "doc-files" subdirectory of that directory to where the package code is written (roughly spoken = "concat(args[4]+args[1])").args[0] = inputfile args[1] = packagename args[2] = classname of the generated model class args[3] = classname oc the generated gui class (when = empty string "", then no no gui will be generated) args[4] = outputroot
- Throws:
SAXException
-