Package adams.core.option
Class AbstractJavaCodeProducer
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.option.AbstractOptionProducer<O,I>
-
- adams.core.option.AbstractRecursiveOptionProducer<O,I>
-
- adams.core.option.AbstractRecursiveOptionProducerWithOptionHandling<String,String>
-
- adams.core.option.AbstractJavaCodeProducer
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,LoggingSupporter
,OptionHandler
,OptionProducer<String,String>
,OptionProducerWithOptionHandling<String,String>
,RecursiveOptionProducer
,SizeOfHandler
,Serializable
- Direct Known Subclasses:
AbstractActorJavaCodeProducer
,AbstractFlowJavaCodeProducer
,JavaInstantiationProducer
public abstract class AbstractJavaCodeProducer extends AbstractRecursiveOptionProducerWithOptionHandling<String,String>
Ancestor for producers that generate Java code.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
JAVA_KEYWORDS
Java keywords.protected int
m_AdditionalImportsInsertLocation
for inserting any additional imports.protected String
m_Copyright
the copyright string.protected int
m_Indentation
the indentation level.protected HashSet<String>
m_JavaKeywords
for checking the keywords.protected StringBuilder
m_OutputBuffer
the buffer for assembling the help.protected boolean
m_OutputDefaultValues
whether to output default values as well.protected String
m_Package
the package of the class.protected Map<String,String>
m_ShortenedImports
for keeping track of the shortened imports.protected String
m_SimpleName
the simple name of the class.protected NamedCounter
m_VarNames
the named counter for the variables.-
Fields inherited from class adams.core.option.AbstractRecursiveOptionProducerWithOptionHandling
m_OptionManager
-
Fields inherited from class adams.core.option.AbstractRecursiveOptionProducer
m_Nesting
-
Fields inherited from class adams.core.option.AbstractOptionProducer
m_Input, m_LastGenerated, m_Output, m_OutputVariableValues, m_SkippedProperties, m_UsePropertyNames
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractJavaCodeProducer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addAdditionalMethods()
Hook-method for adding additional methods necessary to make the class compile.protected void
addClassEnd()
Adds the end of the enclosing "class" statement.protected void
addClassJavadoc()
Adds the Javadoc for the class.protected void
addClassStart()
Adds the start of the enclosing "class" statement.protected void
addConstructor()
Adds the constructor.protected void
addCopyright()
Adds the copyright notice.protected void
addImports()
Adds the imports.protected void
addLicensePreamble()
Adds the license preamble.protected void
addMainMethod()
Hook method for adding a main method.protected abstract void
addMethodEnd()
Closes the method with the generated code.protected abstract void
addMethodStart()
Adds the method that encloses the generated code.protected void
addPackage()
Adds the package for the generated code.String
copyrightTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
escapeDoubleQuotes(String s)
Properly escapes double quotes.protected String
getCast(AbstractArgumentOption option)
Creates the casting string.protected String
getClassname(AbstractArgumentOption option)
Creates the class name.protected String
getClassname(Class cls)
Creates the class name.protected String
getClassname(Object obj)
Creates the class name.String
getCopyright()
Returns the copyright entity.protected String
getCurrentVariable()
Returns the current variable name.protected abstract String
getIndentation()
Returns the indentation for code inside the try-catch-block.protected String
getNextTmpVariable(AbstractOption option)
Generates the next name for a temporary variable.protected String
getNextTmpVariable(Class cls)
Generates the next name for a temporary variable.protected String
getNextTmpVariable(String base)
Generates the next name for a temporary variable.protected abstract String
getOuterVariableName()
The outer most variable name.String
getOutput()
Returns the output generated from the visit.boolean
getOutputDefaultValues()
Returns whyether default values are output as well.protected String
getPackage()
Returns the package name to use.protected List<String>
getRequiredImports()
Returns other necessary imports.protected String
getSimpleName()
Returns the simple name to use.protected void
initialize()
Initializes the visitor.protected String
initOutput()
Initializes the output data structure.protected void
insertAdditionalImports()
Inserts any additional imports, if necessary.protected boolean
isClassName(String s)
Checks whether a string represents a classname.String
outputDefaultValuesTipText()
Returns the tip text for this property.String
packageTipText()
Returns the tip text for this property.protected void
postIndent(Object value)
Hook method that gets called just after the indentation got decreased.protected void
postProduce()
Hook-method after visiting options.protected void
preIndent(Object value)
Hook method that gets called before indentation is increased.protected void
preProduce()
Hook-method before starting visiting options.protected void
preProduce(OptionManager manager, int index)
Hook method that gets called just before an option gets produced.protected void
processClassOption(String variable, Object value)
Processes the value of a class option.String
processOption(AbstractArgumentOption option)
Visits an argument option.String
processOption(BooleanOption option)
Visits a boolean option.String
processOption(ClassOption option)
Visits a class option.void
setCopyright(String value)
Sets the copyright entity.void
setOutputDefaultValues(boolean value)
Sets whether to output default values as well.protected void
setPackage(String value)
Sets the package name of the class to generate.protected void
setSimpleName(String value)
Sets the simple name (without package) of the class to generate.protected String
shortenClassname(String name)
Tries to shorten the classname.String
simpleNameTipText()
Returns the tip text for this property.String
toString()
Returns the output generated from the visit.-
Methods inherited from class adams.core.option.AbstractRecursiveOptionProducerWithOptionHandling
cleanUpOptions, destroy, finishInit, getOptionManager, newOptionManager, toCommandLine
-
Methods inherited from class adams.core.option.AbstractRecursiveOptionProducer
cleanUp, generateLoggingString, getDebugIndentation, getDebugIndentation, getRecursionLevel, reset
-
Methods inherited from class adams.core.option.AbstractOptionProducer
checkInput, doProduce, doProduce, getCurrentValue, getInput, getOptionIdentifier, getOutputVariableValues, getSkippedProperties, getUsePropertyNames, globalInfo, isDefaultValue, loggingLevelTipText, main, outputVariableValuesTipText, postProduce, produce, produce, runProducer, setLoggingLevel, setOutputVariableValues, setSkippedProperties, toString, write
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.option.OptionProducer
cleanUp, doProduce, getInput, getLoggingLevel, getOutputVariableValues, getSkippedProperties, getUsePropertyNames, globalInfo, loggingLevelTipText, outputVariableValuesTipText, produce, setLoggingLevel, setOutputVariableValues, setSkippedProperties, write
-
-
-
-
Field Detail
-
JAVA_KEYWORDS
public static final String[] JAVA_KEYWORDS
Java keywords.
-
m_OutputBuffer
protected StringBuilder m_OutputBuffer
the buffer for assembling the help.
-
m_Copyright
protected String m_Copyright
the copyright string.
-
m_Package
protected String m_Package
the package of the class.
-
m_SimpleName
protected String m_SimpleName
the simple name of the class.
-
m_OutputDefaultValues
protected boolean m_OutputDefaultValues
whether to output default values as well.
-
m_Indentation
protected int m_Indentation
the indentation level.
-
m_ShortenedImports
protected Map<String,String> m_ShortenedImports
for keeping track of the shortened imports.
-
m_AdditionalImportsInsertLocation
protected int m_AdditionalImportsInsertLocation
for inserting any additional imports.
-
m_VarNames
protected NamedCounter m_VarNames
the named counter for the variables.
-
-
Method Detail
-
initOutput
protected String initOutput()
Initializes the output data structure.- Specified by:
initOutput
in classAbstractOptionProducer<String,String>
- Returns:
- the created data structure
-
initialize
protected void initialize()
Initializes the visitor.- Overrides:
initialize
in classAbstractOptionProducer<String,String>
-
defineOptions
public void defineOptions()
Adds options to the internal list of options. Derived classes must override this method to add additional options.- Specified by:
defineOptions
in interfaceOptionHandler
- Specified by:
defineOptions
in interfaceOptionProducerWithOptionHandling<String,String>
- Overrides:
defineOptions
in classAbstractRecursiveOptionProducerWithOptionHandling<String,String>
-
setCopyright
public void setCopyright(String value)
Sets the copyright entity.- Parameters:
value
- the entity owning the copyright
-
getCopyright
public String getCopyright()
Returns the copyright entity.- Returns:
- the entity owning the copyright
-
copyrightTipText
public String copyrightTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setOutputDefaultValues
public void setOutputDefaultValues(boolean value)
Sets whether to output default values as well.- Parameters:
value
- if true then default values are output as well
-
getOutputDefaultValues
public boolean getOutputDefaultValues()
Returns whyether default values are output as well.- Returns:
- true if default values are output as well
-
outputDefaultValuesTipText
public String outputDefaultValuesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getOutput
public String getOutput()
Returns the output generated from the visit.- Specified by:
getOutput
in interfaceOptionProducer<String,String>
- Overrides:
getOutput
in classAbstractOptionProducer<String,String>
- Returns:
- the output
- See Also:
AbstractOptionProducer.initOutput()
-
setSimpleName
protected void setSimpleName(String value)
Sets the simple name (without package) of the class to generate.- Parameters:
value
- the simple name
-
getSimpleName
protected String getSimpleName()
Returns the simple name to use.- Returns:
- the simple name
-
simpleNameTipText
public String simpleNameTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPackage
protected void setPackage(String value)
Sets the package name of the class to generate.- Parameters:
value
- the package name
-
getPackage
protected String getPackage()
Returns the package name to use.- Returns:
- the package name
-
packageTipText
public String packageTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getOuterVariableName
protected abstract String getOuterVariableName()
The outer most variable name.- Returns:
- the variable name
-
getCurrentVariable
protected String getCurrentVariable()
Returns the current variable name.- Returns:
- the variable name
- See Also:
getOuterVariableName()
-
getIndentation
protected abstract String getIndentation()
Returns the indentation for code inside the try-catch-block.- Returns:
- the indentation string
-
shortenClassname
protected String shortenClassname(String name)
Tries to shorten the classname. If it's possible, the class is added as an additional import and the simple name of the class is used (no package).- Parameters:
name
- the classname to shorten- Returns:
- the potentially shortened classname
-
getClassname
protected String getClassname(Class cls)
Creates the class name.- Parameters:
cls
- the class to create the class name string for- Returns:
- the class name string
- See Also:
shortenClassname(String)
-
getClassname
protected String getClassname(AbstractArgumentOption option)
Creates the class name.- Parameters:
option
- the option to create the class name string for- Returns:
- the class name string
-
getClassname
protected String getClassname(Object obj)
Creates the class name.- Parameters:
obj
- the object to create the class name string for- Returns:
- the class name string
-
getCast
protected String getCast(AbstractArgumentOption option)
Creates the casting string.- Parameters:
option
- the option to create the casting string for- Returns:
- the casting string
-
getNextTmpVariable
protected String getNextTmpVariable(String base)
Generates the next name for a temporary variable.- Parameters:
base
- the base name of the temp variable- Returns:
- the actual name of the temp variable
-
getNextTmpVariable
protected String getNextTmpVariable(AbstractOption option)
Generates the next name for a temporary variable.- Parameters:
option
- the option to generate the variable for- Returns:
- the name of the temp variable
-
getNextTmpVariable
protected String getNextTmpVariable(Class cls)
Generates the next name for a temporary variable.- Parameters:
cls
- the class this temp variable is for- Returns:
- the name of the temp variable
-
processOption
public String processOption(BooleanOption option)
Visits a boolean option.- Specified by:
processOption
in interfaceOptionProducer<String,String>
- Specified by:
processOption
in classAbstractOptionProducer<String,String>
- Parameters:
option
- the boolean option- Returns:
- the last internal data structure that was generated
-
isClassName
protected boolean isClassName(String s)
Checks whether a string represents a classname. Simply tries to instantiate a class with that name.- Parameters:
s
- the string to check- Returns:
- true if string resembles a class name
-
preIndent
protected void preIndent(Object value)
Hook method that gets called before indentation is increased.
Default implementation does nothing.- Parameters:
value
- the current object
-
postIndent
protected void postIndent(Object value)
Hook method that gets called just after the indentation got decreased.
Default implementation does nothing.- Parameters:
value
- the current object
-
processClassOption
protected void processClassOption(String variable, Object value)
Processes the value of a class option.- Parameters:
variable
- the name of the tmp variable to usevalue
- the actual value
-
processOption
public String processOption(ClassOption option)
Visits a class option.- Specified by:
processOption
in interfaceOptionProducer<String,String>
- Specified by:
processOption
in classAbstractOptionProducer<String,String>
- Parameters:
option
- the class option- Returns:
- the last internal data structure that was generated
-
escapeDoubleQuotes
protected String escapeDoubleQuotes(String s)
Properly escapes double quotes.- Parameters:
s
- the string to process- Returns:
- the processed string
-
processOption
public String processOption(AbstractArgumentOption option)
Visits an argument option.- Specified by:
processOption
in interfaceOptionProducer<String,String>
- Specified by:
processOption
in classAbstractOptionProducer<String,String>
- Parameters:
option
- the argument option- Returns:
- the last internal data structure that was generated
-
preProduce
protected void preProduce(OptionManager manager, int index)
Hook method that gets called just before an option gets produced.
Default implementation does nothing- Overrides:
preProduce
in classAbstractOptionProducer<String,String>
- Parameters:
manager
- the option managerindex
- the index of the option
-
getRequiredImports
protected List<String> getRequiredImports()
Returns other necessary imports.- Returns:
- the class names
-
addLicensePreamble
protected void addLicensePreamble()
Adds the license preamble.
-
addCopyright
protected void addCopyright()
Adds the copyright notice.
-
addPackage
protected void addPackage()
Adds the package for the generated code.
-
addImports
protected void addImports()
Adds the imports.
-
addClassJavadoc
protected void addClassJavadoc()
Adds the Javadoc for the class.
-
addClassStart
protected void addClassStart()
Adds the start of the enclosing "class" statement.
Default implementation does not derive the class from another superclass.
-
addConstructor
protected void addConstructor()
Adds the constructor.
Default implementation merely adds a default constructor.
-
addAdditionalMethods
protected void addAdditionalMethods()
Hook-method for adding additional methods necessary to make the class compile.
Default implementation adds nothgin.
-
addMethodStart
protected abstract void addMethodStart()
Adds the method that encloses the generated code.
-
preProduce
protected void preProduce()
Hook-method before starting visiting options.- Overrides:
preProduce
in classAbstractOptionProducer<String,String>
- See Also:
AbstractOptionProducer.initOutput()
-
addMethodEnd
protected abstract void addMethodEnd()
Closes the method with the generated code.
-
addMainMethod
protected void addMainMethod()
Hook method for adding a main method.
Default implementation merely instantiates a new instance of the class.
-
addClassEnd
protected void addClassEnd()
Adds the end of the enclosing "class" statement.
-
insertAdditionalImports
protected void insertAdditionalImports()
Inserts any additional imports, if necessary.
-
postProduce
protected void postProduce()
Hook-method after visiting options.- Overrides:
postProduce
in classAbstractOptionProducer<String,String>
-
toString
public String toString()
Returns the output generated from the visit.- Specified by:
toString
in interfaceOptionProducer<String,String>
- Specified by:
toString
in classAbstractOptionProducer<String,String>
- Returns:
- the output, null in case of an error
-
-