Class JAXXCompiler


  • public class JAXXCompiler
    extends Object
    Compiles a given jaxxFile into a javaFile.
    Since:
    1.0.0
    Author:
    Tony Chemit - dev@tchemit.fr
    • Field Detail

      • 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
      • 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.
      • actionsInitializer

        protected final StringBuilder actionsInitializer
        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)
      • 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.
      • 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
      • 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 compile
        defaultImports - 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​(Class<?> clazz)
      • 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
      • URLtoFile

        public static File URLtoFile​(URL url)
      • URLtoFile

        public static File URLtoFile​(String urlString)
      • getSAXParser

        public static SAXParser getSAXParser()
      • runInitializers

        public void runInitializers()
      • registerInitializer

        public void registerInitializer​(Runnable r)
        Registers a Runnable which will be executed after the first compilation pass is complete.
        Parameters:
        r - runnable to register
      • openInvisibleComponent

        public void openInvisibleComponent​(CompiledObject component)
      • closeComponent

        public void closeComponent​(CompiledObject component)
      • registerCompiledObject

        public void registerCompiledObject​(CompiledObject object)
      • inlineCreation

        public boolean inlineCreation​(CompiledObject object)
      • registerEventHandler

        public void registerEventHandler​(EventHandler handler)
      • getEventHandlerMethodName

        public String getEventHandlerMethodName​(EventHandler handler)
      • 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)
      • reportWarning

        public void reportWarning​(Element tag,
                                  String warning,
                                  int lineOffset)
      • reportError

        public void reportError​(String error)
      • reportError

        public void reportError​(Element tag,
                                String error)
      • reportError

        public void reportError​(Element tag,
                                String error,
                                int lineOffset)
      • reportError

        public void reportError​(int lineNumber,
                                String error)
      • getOutputClassName

        public String getOutputClassName()
      • getBaseDir

        public File getBaseDir()
      • getImportedClasses

        public Set<String> getImportedClasses()
      • getImportedPackages

        public Set<String> getImportedPackages()
      • getSourceFiles

        public Stack<File> getSourceFiles()
      • getStylesheet

        public Stylesheet getStylesheet()
      • isFailed

        public boolean isFailed()
      • getClassLoader

        public ClassLoader getClassLoader()
        Returns a ClassLoader which searches the user-specified class path in addition to the normal system class path.
        Returns:
        ClassLoader to 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 given type.

        Note: If no super-class exist, then returns false.

        Parameters:
        type - the type to check against super class
        Returns:
        true if super class exists and is assignable against the given type, false otherwise
      • getActionsInitializer

        public StringBuilder getActionsInitializer()
      • 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)
      • appendActionInitializer

        public void appendActionInitializer​(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 test
        warnOnBrace - 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 tag
        reference - the required reference
        strict - flag to report an error if reference was not found
        attribute - (if not null reference the attribute where is defined the reference)
        Returns:
        true if reference was found, false otherwise and add an error in compiler
      • getUniqueId

        public String getUniqueId​(Object object)
      • 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()
      • 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
      • getImportedTypeForSimpleName

        public String getImportedTypeForSimpleName​(String type)
      • getUiHandler

        public String getUiHandler()
      • setUiHandler

        public void setUiHandler​(String uiHandler)
      • getUIHandlerWithGeneric

        public String getUIHandlerWithGeneric()
      • isUseHandler

        public boolean isUseHandler()
      • computeI18nProperty

        public String computeI18nProperty​(String editorName)
      • 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)