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_KEYWORDSJava keywords.protected intm_AdditionalImportsInsertLocationfor inserting any additional imports.protected Stringm_Copyrightthe copyright string.protected intm_Indentationthe indentation level.protected HashSet<String>m_JavaKeywordsfor checking the keywords.protected StringBuilderm_OutputBufferthe buffer for assembling the help.protected booleanm_OutputDefaultValueswhether to output default values as well.protected Stringm_Packagethe package of the class.protected Map<String,String>m_ShortenedImportsfor keeping track of the shortened imports.protected Stringm_SimpleNamethe simple name of the class.protected NamedCounterm_VarNamesthe 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 voidaddAdditionalMethods()Hook-method for adding additional methods necessary to make the class compile.protected voidaddClassEnd()Adds the end of the enclosing "class" statement.protected voidaddClassJavadoc()Adds the Javadoc for the class.protected voidaddClassStart()Adds the start of the enclosing "class" statement.protected voidaddConstructor()Adds the constructor.protected voidaddCopyright()Adds the copyright notice.protected voidaddImports()Adds the imports.protected voidaddLicensePreamble()Adds the license preamble.protected voidaddMainMethod()Hook method for adding a main method.protected abstract voidaddMethodEnd()Closes the method with the generated code.protected abstract voidaddMethodStart()Adds the method that encloses the generated code.protected voidaddPackage()Adds the package for the generated code.StringcopyrightTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.protected StringescapeDoubleQuotes(String s)Properly escapes double quotes.protected StringgetCast(AbstractArgumentOption option)Creates the casting string.protected StringgetClassname(AbstractArgumentOption option)Creates the class name.protected StringgetClassname(Class cls)Creates the class name.protected StringgetClassname(Object obj)Creates the class name.StringgetCopyright()Returns the copyright entity.protected StringgetCurrentVariable()Returns the current variable name.protected abstract StringgetIndentation()Returns the indentation for code inside the try-catch-block.protected StringgetNextTmpVariable(AbstractOption option)Generates the next name for a temporary variable.protected StringgetNextTmpVariable(Class cls)Generates the next name for a temporary variable.protected StringgetNextTmpVariable(String base)Generates the next name for a temporary variable.protected abstract StringgetOuterVariableName()The outer most variable name.StringgetOutput()Returns the output generated from the visit.booleangetOutputDefaultValues()Returns whyether default values are output as well.protected StringgetPackage()Returns the package name to use.protected List<String>getRequiredImports()Returns other necessary imports.protected StringgetSimpleName()Returns the simple name to use.protected voidinitialize()Initializes the visitor.protected StringinitOutput()Initializes the output data structure.protected voidinsertAdditionalImports()Inserts any additional imports, if necessary.protected booleanisClassName(String s)Checks whether a string represents a classname.StringoutputDefaultValuesTipText()Returns the tip text for this property.StringpackageTipText()Returns the tip text for this property.protected voidpostIndent(Object value)Hook method that gets called just after the indentation got decreased.protected voidpostProduce()Hook-method after visiting options.protected voidpreIndent(Object value)Hook method that gets called before indentation is increased.protected voidpreProduce()Hook-method before starting visiting options.protected voidpreProduce(OptionManager manager, int index)Hook method that gets called just before an option gets produced.protected voidprocessClassOption(String variable, Object value)Processes the value of a class option.StringprocessOption(AbstractArgumentOption option)Visits an argument option.StringprocessOption(BooleanOption option)Visits a boolean option.StringprocessOption(ClassOption option)Visits a class option.voidsetCopyright(String value)Sets the copyright entity.voidsetOutputDefaultValues(boolean value)Sets whether to output default values as well.protected voidsetPackage(String value)Sets the package name of the class to generate.protected voidsetSimpleName(String value)Sets the simple name (without package) of the class to generate.protected StringshortenClassname(String name)Tries to shorten the classname.StringsimpleNameTipText()Returns the tip text for this property.StringtoString()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:
initOutputin classAbstractOptionProducer<String,String>- Returns:
- the created data structure
-
initialize
protected void initialize()
Initializes the visitor.- Overrides:
initializein 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:
defineOptionsin interfaceOptionHandler- Specified by:
defineOptionsin interfaceOptionProducerWithOptionHandling<String,String>- Overrides:
defineOptionsin 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:
getOutputin interfaceOptionProducer<String,String>- Overrides:
getOutputin 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:
processOptionin interfaceOptionProducer<String,String>- Specified by:
processOptionin 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:
processOptionin interfaceOptionProducer<String,String>- Specified by:
processOptionin 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:
processOptionin interfaceOptionProducer<String,String>- Specified by:
processOptionin 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:
preProducein 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:
preProducein 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:
postProducein classAbstractOptionProducer<String,String>
-
toString
public String toString()
Returns the output generated from the visit.- Specified by:
toStringin interfaceOptionProducer<String,String>- Specified by:
toStringin classAbstractOptionProducer<String,String>- Returns:
- the output, null in case of an error
-
-