Package adams.core
Class PropertiesToCode
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.core.PropertiesToCode
-
- All Implemented Interfaces:
Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,SizeOfHandler,Serializable
public class PropertiesToCode extends AbstractOptionHandler
Turns a Properties object into Java code.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Stringm_Commentthe comment to use in the class javadoc.protected Stringm_Copyrightthe copyright string.protected intm_Indentationthe indentation level.protected Stringm_Packagethe package of the class.protected Stringm_SimpleNamethe simple name of the class.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description PropertiesToCode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddClassEnd(StringBuilder output)Adds the end of the enclosing "class" statement.protected voidaddClassJavadoc(StringBuilder output)Adds the Javadoc for the class.protected voidaddClassStart(StringBuilder output, Properties props, List<String> keys)Adds the start of the enclosing "class" statement, including constants and member variables.protected voidaddCopyright(StringBuilder output)Adds the copyright notice.protected voidaddImports(StringBuilder output)Adds the imports.protected voidaddLicensePreamble(StringBuilder output)Adds the license preamble.protected voidaddMethod(StringBuilder output, Properties props, List<String> keys)Adds the method that returns the properties (and instantiates if necessary).protected voidaddPackage(StringBuilder output)Adds the package for the generated code.StringcommentTipText()Returns the tip text for this property.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.Stringgenerate(Properties props)Turns the properties object into Java code.StringgetComment()Returns the comment to use for the class javadoc.StringgetCopyright()Returns the copyright entity.intgetIndentation()Returns the indentation.protected StringgetIndentation(int level)Returns the indentation for code at the specified level.StringgetPackage()Returns the package name to use.protected List<String>getRequiredImports()Returns the classnames that are required for the code to work.StringgetSimpleName()Returns the simple name to use.StringglobalInfo()Returns a string describing the object.StringindentationTipText()Returns the tip text for this property.StringpackageTipText()Returns the tip text for this property.voidsetComment(String value)Sets the comment to use for the class javadoc.voidsetCopyright(String value)Sets the copyright entity.voidsetIndentation(int value)Sets the indentation.voidsetPackage(String value)Sets the package name of the class to generate.voidsetSimpleName(String value)Sets the simple name (without package) of the class to generate.StringsimpleNameTipText()Returns the tip text for this property.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
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.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
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_Comment
protected String m_Comment
the comment to use in the class javadoc.
-
m_Indentation
protected int m_Indentation
the indentation level.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
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- Overrides:
defineOptionsin classAbstractOptionHandler
-
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.
-
setSimpleName
public void setSimpleName(String value)
Sets the simple name (without package) of the class to generate.- Parameters:
value- the simple name
-
getSimpleName
public 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
public void setPackage(String value)
Sets the package name of the class to generate.- Parameters:
value- the package name
-
getPackage
public 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.
-
setComment
public void setComment(String value)
Sets the comment to use for the class javadoc. If left empty, an auto-generated comment is used.- Parameters:
value- the comment
-
getComment
public String getComment()
Returns the comment to use for the class javadoc. If left empty, an auto-generated comment is used.- Returns:
- the comment
-
commentTipText
public String commentTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setIndentation
public void setIndentation(int value)
Sets the indentation.- Parameters:
value- the number of spaces
-
getIndentation
public int getIndentation()
Returns the indentation.- Returns:
- the number of spaces
-
indentationTipText
public String indentationTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getIndentation
protected String getIndentation(int level)
Returns the indentation for code at the specified level.- Parameters:
level- the indentation level- Returns:
- the indentation string
-
addLicensePreamble
protected void addLicensePreamble(StringBuilder output)
Adds the license preamble.- Parameters:
output- the buffer to add to
-
addCopyright
protected void addCopyright(StringBuilder output)
Adds the copyright notice.- Parameters:
output- the buffer to add to
-
addPackage
protected void addPackage(StringBuilder output)
Adds the package for the generated code.- Parameters:
output- the buffer to add to
-
getRequiredImports
protected List<String> getRequiredImports()
Returns the classnames that are required for the code to work.- Returns:
- the classes
-
addImports
protected void addImports(StringBuilder output)
Adds the imports.- Parameters:
output- the buffer to add to
-
addClassJavadoc
protected void addClassJavadoc(StringBuilder output)
Adds the Javadoc for the class.- Parameters:
output- the buffer to add to
-
escapeDoubleQuotes
protected String escapeDoubleQuotes(String s)
Properly escapes double quotes.- Parameters:
s- the string to process- Returns:
- the processed string
-
addClassStart
protected void addClassStart(StringBuilder output, Properties props, List<String> keys)
Adds the start of the enclosing "class" statement, including constants and member variables.- Parameters:
output- the buffer to add toprops- the properties to usekeys- the ordered keys
-
addMethod
protected void addMethod(StringBuilder output, Properties props, List<String> keys)
Adds the method that returns the properties (and instantiates if necessary).- Parameters:
output- the buffer to add toprops- the properties to usekeys- the ordered keys
-
addClassEnd
protected void addClassEnd(StringBuilder output)
Adds the end of the enclosing "class" statement.- Parameters:
output- the buffer to add to
-
generate
public String generate(Properties props)
Turns the properties object into Java code.- Parameters:
props- the properties to convert- Returns:
- the generated code
-
-