Package jaxx.compiler

Class JAXXCompiler


  • public class JAXXCompiler
    extends Object
    Compiles a given jaxxFile into a javaFile.
    Since:
    1.0.0
    Author:
    Tony Chemit - chemit@codelutin.com
    • Field Detail

      • log

        protected static final org.apache.commons.logging.Log log
        Logger
      • 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).
      • INLINE_THRESHOLD

        public static final int INLINE_THRESHOLD
        Maximum length of an inlinable creation method.
        See Also:
        Constant Field Values
      • lineSeparator

        protected static String lineSeparator
        Line separator cached value
      • BORDER_LAYOUT_PREFIX

        public static final String BORDER_LAYOUT_PREFIX
      • firstPassClassTagHandler

        protected final DefaultObjectHandler firstPassClassTagHandler
        The unique object handler used in first pass
      • 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.
      • importedPackages

        protected Set<String> importedPackages
        Contains strings of the form "javax.swing."
      • importedClasses

        protected Set<String> importedClasses
        Contains strings of the form "javax.swing.Timer"
      • openComponents

        protected Stack<CompiledObject> openComponents
        Keeps track of open components (components still having children added).
      • idHelper

        protected final IDHelper idHelper
        to generate ids
      • symbolTable

        protected SymbolTable symbolTable
        table of symbols for this compiler
      • baseDir

        protected File baseDir
        Base directory used for path resolution (normally the directory in which the .jaxx file resides).
      • src

        protected File src
        jaxx file being compiled.
      • document

        protected Document document
        Parsed XML of src file.
      • outputClassName

        protected String outputClassName
        Name of class being compiled.
      • scriptManager

        protected ScriptManager scriptManager
        script manager
      • inlineStyles

        protected List<Rule> inlineStyles
        Contains all attributes defined inline on class tags.
      • eventHandlers

        protected 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 Map<EventHandler,​String> eventHandlerMethodNames
        Map of event handler method names used in compiler
      • classLoader

        protected ClassLoader classLoader
        ClassLoader which searches the user-specified class path in addition to the normal class path
      • initializers

        protected List<Runnable> initializers
        A list of Runnables 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 StringBuilder initializer
        Extra code to be added to the instance initializer.
      • lateInitializer

        protected StringBuilder lateInitializer
        Extra code to be added at the end of the instance initializer.
      • bodyCode

        protected StringBuilder bodyCode
        Extra code to be added to the class body.
      • mainDeclared

        protected boolean mainDeclared
        true if a main() method has been declared in a script
      • javaFile

        protected JavaFile javaFile
        the file to be generated
      • tagsBeingCompiled

        protected Stack<Element> tagsBeingCompiled
        Used for error reporting purposes, so we can report the right line number.
      • sourceFiles

        protected Stack<File> sourceFiles
        Used for error reporting purposes, so we can report the right source file.
      • objects

        protected Map<String,​CompiledObject> objects
        Maps object ID strings to the objects themselves. These are created during the second compilation pass.
      • ids

        protected 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)
      • 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 msut be imported.
        Since:
        2.4
      • EMPTY_STRING_ARRAY

        public static final String[] EMPTY_STRING_ARRAY
      • 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

      • 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()
      • registerStyleSheetFile

        public void registerStyleSheetFile​(File styleFile,
                                           boolean warnAutoCssImport)
                                    throws IOException
        Throws:
        IOException
      • 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()
      • getIdHelper

        public IDHelper getIdHelper()
      • 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
      • isSuperClassAware

        public boolean isSuperClassAware​(Class<?> type)
                                  throws ClassNotFoundException
        Checks if the super class of the mirrored javaFile is aware of the iven 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
        Throws:
        ClassNotFoundException - if could not find class descriptor for super-class
      • 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)
      • hasMethod

        public boolean hasMethod​(String methodName)
      • 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
      • 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)
      • setExtraInterfaces

        public void setExtraInterfaces​(String[] extraInterfaces)
      • getExtraInterfaces

        public String[] getExtraInterfaces()
      • 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()
      • preFinalizeCompiler

        public void preFinalizeCompiler()
                                 throws Exception
        Throws:
        Exception
      • 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()
      • clear

        public void clear()
      • setClassLoader

        public void setClassLoader​(ClassLoader classLoader)
      • 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)
      • getImportManager

        @Deprecated
        public org.nuiton.eugene.java.extension.ImportsManager getImportManager()
        Deprecated.
        since 2.4.1, will be removed in version 3.0 : do not want to expose eugene export manager in rest of api, this is purpose of JavaFile only
        Returns:
        the javafile import manager
        Since:
        2.4
      • isNeedSwingUtil

        @Deprecated
        public boolean isNeedSwingUtil()
        Deprecated.
        since 2.4.1, will be removed in version 3.0, has no effect do not use it...
        Since:
        2.4
      • setNeedSwingUtil

        @Deprecated
        public void setNeedSwingUtil​(boolean needSwingUtil)
        Deprecated.
        since 2.4.1, will be removed in version 3.0, has no effect do not use it...
        Since:
        2.4
      • containsScriptField

        public boolean containsScriptField​(String fieldName)
      • getUiHandler

        public String getUiHandler()
      • setUiHandler

        public void setUiHandler​(String uiHandler)
      • isUseHandler

        public boolean isUseHandler()