Class JAXXCompiler
- java.lang.Object
-
- org.nuiton.jaxx.compiler.JAXXCompiler
-
public class JAXXCompiler extends Object
- Since:
- 1.0.0
- Author:
- Tony Chemit - dev@tchemit.fr
-
-
Field Summary
Fields Modifier and Type Field Description protected FilebaseDirBase directory used for path resolution (normally the directory in which the .jaxx file resides).protected DataBindingHelperbindingHelperBinding Utilprotected StringBuilderbodyCodeExtra code to be added to the class body.static StringBORDER_LAYOUT_PREFIXprotected ClassLoaderclassLoaderClassLoader which searches the user-specified class path in addition to the normal class pathprotected CompilerConfigurationdefaultConfigurationprotected CompiledObjectDecoratordefaultDecoratordefault decorator to use if none specifiedprotected DocumentdocumentParsed XML of src file.protected JAXXEngineengineengine which references this compiler (can be null if compiler is standalone)protected Map<EventHandler,String>eventHandlerMethodNamesMap of event handler method names used in compilerprotected Map<String,Map<ClassDescriptor,List<EventHandler>>>eventHandlersMaps objects (expressed in Java code) to event listener classes (e.g.protected booleanfailedflag to detect if an error occurs while compiling jaxx fileprotected DefaultObjectHandlerfirstPassClassTagHandlerThe unique object handler used in first passprotected booleanidentCssFoundFlag to know if jaxx file ident css was found, otherwise add it at the end of the second compile pass.protected IDHelperidHelperto generate idsprotected Map<CompiledObject,String>idsMaps objects to their ID strings.protected Set<String>importedClassesContains strings of the form "javax.swing.Timer"protected Set<String>importedPackagesContains strings of the form "javax.swing."protected StringBuilderinitializerExtra code to be added to the instance initializer.protected List<Runnable>initializersA list of Runnable which will be run after the first compilation pass.static intINLINE_THRESHOLDMaximum length of an inline creation method.protected List<Rule>inlineStylesContains all attributes defined inline on class tags.protected JavaFilejavaFilethe file to be generatedstatic StringJAXX_INTERNAL_NAMESPACEstatic StringJAXX_NAMESPACEprotected JAXXCompilerFilejaxxFileprotected StringBuilderlateInitializerExtra code to be added at the end of the instance initializer.protected static StringlineSeparatorLine separator cached valueprotected static org.apache.logging.log4j.LoggerlogLoggerprotected booleanmainDeclaredtrue if a main() method has been declared in a scriptprotected booleanneedSwingUtilDeprecated.since 2.4.1, will be removed in version 3.0, it is not a good idea to do special treatment for a particular class, to use SwingUtil, do like for other class : import it!protected Map<String,CompiledObject>objectsMaps object ID strings to the objects themselves.protected Stack<CompiledObject>openComponentsKeeps track of open components (components still having children added).protected StringoutputClassNameName of class being compiled.protected CompiledObjectrootObject corresponding to the root tag in the document.protected ScriptManagerscriptManagerscript managerprotected Stack<File>sourceFilesUsed for error reporting purposes, so we can report the right source file.protected Filesrcjaxx file being compiled.static booleanSTRICT_CHECKSTrue to throw exceptions when we encounter unresolvable classes, false to ignore.protected StylesheetstylesheetCombination of all stylesheets registered usingregisterStylesheet(Stylesheet).protected SymbolTablesymbolTabletable of symbols for this compilerprotected Stack<Element>tagsBeingCompiledUsed for error reporting purposes, so we can report the right line number.protected StringuiHandler
-
Constructor Summary
Constructors Constructor Description JAXXCompiler()JAXXCompiler(JAXXEngine engine, JAXXCompilerFile jaxxFile, List<String> defaultImports)Creates a new JAXXCompiler.
-
Method Summary
-
-
-
Field Detail
-
JAXX_NAMESPACE
public static final String JAXX_NAMESPACE
- See Also:
- Constant Field Values
-
JAXX_INTERNAL_NAMESPACE
public static final String JAXX_INTERNAL_NAMESPACE
- See Also:
- Constant Field Values
-
INLINE_THRESHOLD
public static final int INLINE_THRESHOLD
Maximum length of an inline creation method.- See Also:
- Constant Field Values
-
BORDER_LAYOUT_PREFIX
public static final String BORDER_LAYOUT_PREFIX
-
log
protected static final org.apache.logging.log4j.Logger log
Logger
-
lineSeparator
protected static final String lineSeparator
Line separator cached value
-
STRICT_CHECKS
public static boolean STRICT_CHECKS
True to throw exceptions when we encounter unresolvable classes, false to ignore.This is currently set to false until JAXX has full support for inner classes (including enumerations), because currently they don't always resolve (but will generally run without error anyway).
-
firstPassClassTagHandler
protected final DefaultObjectHandler firstPassClassTagHandler
The unique object handler used in first pass
-
importedPackages
protected final Set<String> importedPackages
Contains strings of the form "javax.swing."
-
importedClasses
protected final Set<String> importedClasses
Contains strings of the form "javax.swing.Timer"
-
openComponents
protected final Stack<CompiledObject> openComponents
Keeps track of open components (components still having children added).
-
idHelper
protected final IDHelper idHelper
to generate ids
-
bindingHelper
protected final DataBindingHelper bindingHelper
Binding Util
-
symbolTable
protected final SymbolTable symbolTable
table of symbols for this compiler
-
baseDir
protected final File baseDir
Base directory used for path resolution (normally the directory in which the .jaxx file resides).
-
src
protected final File src
jaxx file being compiled.
-
outputClassName
protected final String outputClassName
Name of class being compiled.
-
scriptManager
protected final ScriptManager scriptManager
script manager
-
inlineStyles
protected final List<Rule> inlineStyles
Contains all attributes defined inline on class tags.
-
eventHandlers
protected final Map<String,Map<ClassDescriptor,List<EventHandler>>> eventHandlers
Maps objects (expressed in Java code) to event listener classes (e.g. MouseListener) to Lists of EventHandlers. The final list contains all event handlers of a particular type attached to a particular object (again, as represented by a Java expression).
-
eventHandlerMethodNames
protected final Map<EventHandler,String> eventHandlerMethodNames
Map of event handler method names used in compiler
-
initializers
protected final List<Runnable> initializers
A list of Runnable which will be run after the first compilation pass.This is primarily used to trigger the creation of CompiledObjects, which cannot be created during the first pass and must be created in document order.
-
initializer
protected final StringBuilder initializer
Extra code to be added to the instance initializer.
-
lateInitializer
protected final StringBuilder lateInitializer
Extra code to be added at the end of the instance initializer.
-
bodyCode
protected final StringBuilder bodyCode
Extra code to be added to the class body.
-
tagsBeingCompiled
protected final Stack<Element> tagsBeingCompiled
Used for error reporting purposes, so we can report the right line number.
-
sourceFiles
protected final Stack<File> sourceFiles
Used for error reporting purposes, so we can report the right source file.
-
objects
protected final Map<String,CompiledObject> objects
Maps object ID strings to the objects themselves.These are created during the second compilation pass.
-
ids
protected final Map<CompiledObject,String> ids
Maps objects to their ID strings.These are created during the second compilation pass.
-
engine
protected final JAXXEngine engine
engine which references this compiler (can be null if compiler is standalone)
-
defaultConfiguration
protected final CompilerConfiguration defaultConfiguration
-
jaxxFile
protected final JAXXCompilerFile jaxxFile
-
failed
protected boolean failed
flag to detect if an error occurs while compiling jaxx file
-
root
protected CompiledObject root
Object corresponding to the root tag in the document.
-
document
protected Document document
Parsed XML of src file.
-
stylesheet
protected Stylesheet stylesheet
Combination of all stylesheets registered usingregisterStylesheet(Stylesheet).
-
classLoader
protected ClassLoader classLoader
ClassLoader which searches the user-specified class path in addition to the normal class path
-
mainDeclared
protected boolean mainDeclared
true if a main() method has been declared in a script
-
javaFile
protected JavaFile javaFile
the file to be generated
-
defaultDecorator
protected CompiledObjectDecorator defaultDecorator
default decorator to use if none specified
-
identCssFound
protected boolean identCssFound
Flag to know if jaxx file ident css was found, otherwise add it at the end of the second compile pass.- Since:
- 2.0.2
-
needSwingUtil
@Deprecated protected boolean needSwingUtil
Deprecated.since 2.4.1, will be removed in version 3.0, it is not a good idea to do special treatment for a particular class, to use SwingUtil, do like for other class : import it!A flag to know if SwingUtil must be imported.- Since:
- 2.4
-
uiHandler
protected String uiHandler
-
-
Constructor Detail
-
JAXXCompiler
public JAXXCompiler()
-
JAXXCompiler
public JAXXCompiler(JAXXEngine engine, JAXXCompilerFile jaxxFile, List<String> defaultImports)
Creates a new JAXXCompiler.- Parameters:
engine- engine which use the compiler (could be null if not attach to any engine)jaxxFile- the file to compiledefaultImports- list of default imports to add to java files
-
-
Method Detail
-
getLineSeparator
public static String getLineSeparator()
Returns the system line separator string.- Returns:
- the string used to separate lines
-
getCanonicalName
public static String getCanonicalName(ClassDescriptor clazz)
-
getCanonicalName
public static String getCanonicalName(CompiledObject compiled)
-
escapeJavaString
public static String escapeJavaString(String raw)
Escapes a string using standard Java escape sequences, generally in preparation to including it in a string literal in a compiled Java file.- Parameters:
raw- the raw string to be escape- Returns:
- a string in which all 'dangerous' characters have been replaced by equivalent Java escape sequences
-
getSAXParser
public static SAXParser getSAXParser()
-
parseDocument
public static Document parseDocument(InputStream in) throws IOException, SAXException
- Throws:
IOExceptionSAXException
-
runInitializers
public void runInitializers()
-
registerInitializer
public void registerInitializer(Runnable r)
Registers aRunnablewhich will be executed after the first compilation pass is complete.- Parameters:
r- runnable to register
-
compileFirstPass
public void compileFirstPass(Element tag) throws IOException
- Throws:
IOException
-
compileSecondPass
public void compileSecondPass(Element tag) throws IOException
- Throws:
IOException
-
compileFirstPass
public void compileFirstPass() throws IOException- Throws:
IOException
-
compileSecondPass
public void compileSecondPass() throws IOException- Throws:
IOException
-
openComponent
public void openComponent(CompiledObject component) throws CompilerException
- Throws:
CompilerException
-
openComponent
public void openComponent(CompiledObject component, String constraints) throws CompilerException
- Throws:
CompilerException
-
openInvisibleComponent
public void openInvisibleComponent(CompiledObject component)
-
getOpenComponent
public CompiledObject getOpenComponent()
-
closeComponent
public void closeComponent(CompiledObject component)
-
registerCompiledObject
public void registerCompiledObject(CompiledObject object)
-
getCompiledObject
public CompiledObject getCompiledObject(String id)
-
inlineCreation
public boolean inlineCreation(CompiledObject object)
-
checkOverride
public void checkOverride(CompiledObject object) throws CompilerException
- Throws:
CompilerException
-
getBindingHelper
public DataBindingHelper getBindingHelper()
-
registerEventHandler
public void registerEventHandler(EventHandler handler)
-
getEventHandlerMethodName
public String getEventHandlerMethodName(EventHandler handler)
-
addScriptField
public void addScriptField(FieldDescriptor field)
-
addScriptMethod
public void addScriptMethod(MethodDescriptor method)
-
registerScript
public void registerScript(String script) throws CompilerException
- Throws:
CompilerException
-
registerScript
public void registerScript(String script, File sourceFile) throws CompilerException
- Throws:
CompilerException
-
preprocessScript
public String preprocessScript(String script) throws CompilerException
- Throws:
CompilerException
-
isIdentCssFound
public boolean isIdentCssFound()
-
detectIdentStyleSheetFile
public void detectIdentStyleSheetFile()
-
detectIdentCommonStyleSheetFile
public void detectIdentCommonStyleSheetFile()
-
registerStyleSheetFile
public void registerStyleSheetFile(URL styleFile, boolean warnAutoCssImport)
-
applyStylesheets
public void applyStylesheets()
-
registerStylesheet
public void registerStylesheet(Stylesheet stylesheet)
-
addInlineStyle
public void addInlineStyle(CompiledObject object, String propertyName, boolean dataBinding)
-
reportWarning
public void reportWarning(String warning)
-
reportError
public void reportError(String error)
-
reportError
public void reportError(CompilerException ex)
-
reportError
public void reportError(String extraMessage, CompilerException ex)
-
reportError
public void reportError(int lineNumber, String error)
-
getObjects
public Map<String,CompiledObject> getObjects()
-
getEventHandlers
public Map<String,Map<ClassDescriptor,List<EventHandler>>> getEventHandlers()
-
getConfiguration
public CompilerConfiguration getConfiguration()
-
getOutputClassName
public String getOutputClassName()
-
getBaseDir
public File getBaseDir()
-
getObjectCreationOrder
public Iterator<CompiledObject> getObjectCreationOrder()
-
getRootObject
public CompiledObject getRootObject()
-
getScriptManager
public ScriptManager getScriptManager()
-
getSymbolTable
public SymbolTable getSymbolTable()
-
getStylesheet
public Stylesheet getStylesheet()
-
getScriptField
public FieldDescriptor getScriptField(String fieldName)
-
getScriptMethod
public MethodDescriptor getScriptMethod(String methodName)
-
isFailed
public boolean isFailed()
-
getClassLoader
public ClassLoader getClassLoader()
Returns aClassLoaderwhich searches the user-specified class path in addition to the normal system class path.- Returns:
ClassLoaderto use while resolving class references
-
setClassLoader
public void setClassLoader(ClassLoader classLoader)
-
isSuperClassAware
public boolean isSuperClassAware(Class<?> type)
Checks if the super class of the mirrored javaFile is aware of the giventype.Note: If no super-class exist, then returns
false.- Parameters:
type- the type to check against super class- Returns:
trueif super class exists and is assignable against the given type,falseotherwise
-
getJAXXObjectDescriptor
public JAXXObjectDescriptor getJAXXObjectDescriptor()
-
getInitializer
public StringBuilder getInitializer()
-
getLateInitializer
public StringBuilder getLateInitializer()
-
getBodyCode
public StringBuilder getBodyCode()
-
isMainDeclared
public boolean isMainDeclared()
-
setMainDeclared
public void setMainDeclared(boolean mainDeclared)
-
appendInitializerCode
public void appendInitializerCode(String code)
-
appendBodyCode
public void appendBodyCode(String code)
-
appendLateInitializer
public void appendLateInitializer(String code)
-
addImport
public void addImport(Class<?> clazz)
-
addImport
public void addImport(String text)
-
addDefaultImport
protected void addDefaultImport(String text)
-
addDependencyClass
public void addDependencyClass(String className)
-
loadFile
public String loadFile(File file)
Loads the given file and returns its content.Note: If any errors encounters, then report an error in the compiler and returns an empty string.
- Parameters:
file- the file to load- Returns:
- the content of the file or empty string if something was wrong
-
checkJavaCode
public String checkJavaCode(String javaCode)
Verifies that a snippet of Java code parses correctly.A warning is generated if the string has enclosing curly braces.
- Parameters:
javaCode- the Java code snippet to test- Returns:
- a "cooked" version of the string which has enclosing curly braces removed.
- Throws:
CompilerException- if the code cannot be parsed
-
checkJavaCode
public String checkJavaCode(String javaCode, boolean warnOnBrace)
Verifies that a snippet of Java code parses correctly.A warning is generated if the string has enclosing curly braces.
- Parameters:
javaCode- the Java code snippet to testwarnOnBrace- flag to warn if curly braces are found- Returns:
- a "cooked" version of the string which has enclosing curly braces removed.
- Throws:
CompilerException- if the code cannot be parsed
-
checkReference
public boolean checkReference(Element tag, String reference, boolean strict, String attribute)
Check that a reference exists in symbol table on second compil pass- Parameters:
tag- the current tagreference- the required referencestrict- flag to report an error if reference was not foundattribute- (if not null reference the attribute where is defined the reference)- Returns:
trueif reference was found,falseotherwise and add an error in compiler
-
getExtraInterfaces
public String[] getExtraInterfaces()
-
setExtraInterfaces
public void setExtraInterfaces(String[] extraInterfaces)
-
isAbstractClass
public boolean isAbstractClass()
-
setAbstractClass
public void setAbstractClass(boolean abstractClass)
-
getGenericType
public String getGenericType()
-
setGenericType
public void setGenericType(String genericType)
-
getSuperGenericType
public String getSuperGenericType()
-
setSuperGenericType
public void setSuperGenericType(String superGenericType)
-
addSimpleField
public void addSimpleField(JavaField javaField)
-
getJavaFile
public JavaFile getJavaFile()
-
generate
public void generate(JavaFileGenerator generator) throws IOException
- Throws:
IOException
-
getEngine
public JAXXEngine getEngine()
-
clear
public void clear()
-
getImportedType
public String getImportedType(Class<?> type)
Try to import the given type into the underlying java file of this compiler.If import can not be done, will then returns the fully qualified name of the type.
- Parameters:
type- the type to simplify- Returns:
- the simplify type or the fqn if type could not be imported for the underlying java file.
- Since:
- 2.4.1
-
getImportedType
public String getImportedType(String type)
Try to import the given type into the underlying java file of this compiler.If import can not be done, will then returns the fully qualified name of the type.
- Parameters:
type- the fqn of the type to simplify- Returns:
- the simplify type or the fqn if type could not be imported for the underlying java file.
- Since:
- 2.4.1
-
getUiHandler
public String getUiHandler()
-
setUiHandler
public void setUiHandler(String uiHandler)
-
getUIHandlerWithGeneric
public String getUIHandlerWithGeneric()
-
isUseHandler
public boolean isUseHandler()
-
computeI18nProperty
public String computeI18nProperty(CompiledObject editorName)
-
getI18nProperty
public String getI18nProperty(CompiledObject compiledObject)
-
processDataBindings
public String processDataBindings(String stringValue) throws CompilerException
- Throws:
CompilerException
-
isI18nInit
public boolean isI18nInit()
-
setI18n
public void setI18n(String i18n)
-
registerBeanScope
public void registerBeanScope(BeanScope beanScope)
-
removeBeanScope
public void removeBeanScope()
-
getParentI18nKeysFileModel
public I18nKeysFileModel getParentI18nKeysFileModel(boolean load)
-
getI18nKeysFileModel
public I18nKeysFileModel getI18nKeysFileModel(boolean load)
-
-