jaxx.compiler
Class JAXXEngine

java.lang.Object
  extended by jaxx.compiler.JAXXEngine

public class JAXXEngine
extends java.lang.Object

Since:
2.0.0 was previously JAXXCompilerLaunchor
Author:
chemit

Nested Class Summary
protected static class JAXXEngine.LifeCycle
          Different passes of the engine.
 
Field Summary
protected  java.lang.String[] classNames
          original list of classes to run
protected  java.util.Map<java.lang.String,JAXXCompiler> compilers
          Maps the names of classes being compiled to the compiler instance handling the compilation.
protected  CompilerConfiguration configuration
          configuration of the launchor and underlines compilers
protected  java.util.Map<java.lang.String,CompiledObjectDecorator> decorators
          decorators available in engine
protected  java.util.List<java.lang.String> errors
          Errors detected while running.
protected  java.io.File[] files
          original list of files to run
protected  java.util.List<JAXXCompilerFinalizer> finalizers
          finalizers available in engine
protected  JAXXProfile profiler
          profile attached to the engine (can be null)
protected static JAXXEngine singleton
          shared instance of unique launchor at a givne time.
protected  java.util.Map<java.io.File,SymbolTable> symbolTables
          Maps the names of classes being compiled to their symbol tables (created after the first compiler pass).
protected  java.util.List<java.lang.String> warnings
          Warnings detected while running.
 
Constructor Summary
protected JAXXEngine(java.io.File[] files, java.lang.String[] classNames, CompilerConfiguration options)
           
 
Method Summary
 void addError(java.lang.String error)
          Add an error to the engine.
 void addJaxxFile(java.io.File jaxxFile)
           
 void addJaxxFileClassName(java.lang.String className)
           
 void addProfileTime(JAXXCompiler compiler, java.lang.String key)
          Add a profile time for the given compiler and key.
 void addWarning(java.lang.String warning)
          Add a warning to the engine.
 boolean containsJaxxFileClassName(java.lang.String className)
           
static JAXXCompiler createDummyCompiler(java.lang.ClassLoader classLoader)
          Creates a dummy Compiler for use in unit testing or dettached use of an engine.
static JAXXEngine get()
           
protected  JAXXCompiler getCompiler(java.lang.String className, java.lang.String message)
          Obtain the compiler for the given class name.
 JAXXEngine.LifeCycle getCurrentPass()
           
 CompiledObjectDecorator getDecorator(java.lang.Class<?> type)
          Obtain the decorator of the given type.
 CompiledObjectDecorator getDecorator(java.lang.String name)
          Obtain the decorator of the given name.
 java.util.List<java.lang.String> getErrors()
           
 JAXXCompiler getJAXXCompiler(java.lang.String className)
          Obtain the jaxx compiler of the given class name.
 SymbolTable getSymbolTable(java.lang.String className)
          Obtain the symbo table for the given class name.
 java.lang.String getVersion()
           
 java.util.List<java.lang.String> getWarnings()
           
static boolean isRegistred()
           
static void loadLibraries(boolean verbose)
          Load the Initializer services found via theServiceLoader mecanism.
protected  JAXXCompiler newCompiler(java.io.File parentFile, java.io.File file, java.lang.String className)
          Create a new compiler.
static JAXXEngine newLaunchor()
          Create a new empty launchor and set it as current launchor accessible via method get()
static JAXXEngine newLaunchor(java.io.File[] files, java.lang.String[] classNames, CompilerConfiguration configuration)
          Create a new launchor and set it as current launchor accessible via method get().
static JAXXEngine newLaunchor(java.io.File base, java.lang.String[] relativePaths, CompilerConfiguration configuration)
          Create a new launchor and set it as current launchor accessible via method get().
protected  void reset()
          Resets all state in preparation for a new compilation session.
 int run()
          Compiled a set of files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

protected static JAXXEngine singleton
shared instance of unique launchor at a givne time.


configuration

protected CompilerConfiguration configuration
configuration of the launchor and underlines compilers


files

protected final java.io.File[] files
original list of files to run


classNames

protected final java.lang.String[] classNames
original list of classes to run


compilers

protected java.util.Map<java.lang.String,JAXXCompiler> compilers
Maps the names of classes being compiled to the compiler instance handling the compilation.


symbolTables

protected java.util.Map<java.io.File,SymbolTable> symbolTables
Maps the names of classes being compiled to their symbol tables (created after the first compiler pass).


warnings

protected java.util.List<java.lang.String> warnings
Warnings detected while running.


errors

protected java.util.List<java.lang.String> errors
Errors detected while running.


profiler

protected JAXXProfile profiler
profile attached to the engine (can be null)


decorators

protected java.util.Map<java.lang.String,CompiledObjectDecorator> decorators
decorators available in engine


finalizers

protected java.util.List<JAXXCompilerFinalizer> finalizers
finalizers available in engine

Constructor Detail

JAXXEngine

protected JAXXEngine(java.io.File[] files,
                     java.lang.String[] classNames,
                     CompilerConfiguration options)
Method Detail

addJaxxFileClassName

public void addJaxxFileClassName(java.lang.String className)

addJaxxFile

public void addJaxxFile(java.io.File jaxxFile)

containsJaxxFileClassName

public boolean containsJaxxFileClassName(java.lang.String className)

getCurrentPass

public JAXXEngine.LifeCycle getCurrentPass()

newLaunchor

public static JAXXEngine newLaunchor()
Create a new empty launchor and set it as current launchor accessible via method get()

Returns:
the new instanciated launchor

newLaunchor

public static JAXXEngine newLaunchor(java.io.File base,
                                     java.lang.String[] relativePaths,
                                     CompilerConfiguration configuration)
Create a new launchor and set it as current launchor accessible via method get().

The launchor will be prepared to run a set of files, expressed as paths relative to a base directory. The class names of the compiled files are derived from the relative path strings (e.g. "example/Foo.jaxx" compiles into a class named "example.Foo").

Parameters:
base - the directory against which to resolve relative paths
relativePaths - a list of relative paths to .jaxx files being compiled
configuration - the compiler configuration to use
Returns:
the new instanciated launchor

newLaunchor

public static JAXXEngine newLaunchor(java.io.File[] files,
                                     java.lang.String[] classNames,
                                     CompilerConfiguration configuration)
Create a new launchor and set it as current launchor accessible via method get().

The launchor will be prepared to run a set of files, with the class names specified explicitly. The class compiled from files[i] will be named classNames[i].

Parameters:
files - the .jaxx files to run
classNames - the names of the classes being compiled
configuration - the compiler configuration to use
Returns:
the new instanciated launchor

get

public static JAXXEngine get()
                      throws java.lang.NullPointerException
Returns:
the current launchor
Throws:
java.lang.NullPointerException - if no launchor was registred via a newLaunchor-like method.

isRegistred

public static boolean isRegistred()
Returns:
if there is a launchor registred, false otherwise.

loadLibraries

public static void loadLibraries(boolean verbose)
Load the Initializer services found via theServiceLoader mecanism.

Parameters:
verbose - true to print initializers

reset

protected void reset()
Resets all state in preparation for a new compilation session.


getVersion

public java.lang.String getVersion()

createDummyCompiler

public static JAXXCompiler createDummyCompiler(java.lang.ClassLoader classLoader)
Creates a dummy Compiler for use in unit testing or dettached use of an engine.

Parameters:
classLoader - class loader to use
Returns:
the compiler

getJAXXCompiler

public JAXXCompiler getJAXXCompiler(java.lang.String className)
Obtain the jaxx compiler of the given class name.

Parameters:
className - the name of the class to use
Returns:
the compiler instance which is processing the specified JAXX class. Each class is compiled by a different compiler instance.

getSymbolTable

public SymbolTable getSymbolTable(java.lang.String className)
Obtain the symbo table for the given class name.

Parameters:
className - the name of the class to use
Returns:
the symbol table for the specified JAXX class. Must be called during the second compiler pass. Returns null if no such symbol table could be found.

getDecorator

public CompiledObjectDecorator getDecorator(java.lang.String name)
                                     throws java.lang.IllegalArgumentException
Obtain the decorator of the given name.

Parameters:
name - the name of the decorator
Returns:
the decorator found.
Throws:
java.lang.IllegalArgumentException - if decorator not found for the given name.

getDecorator

public CompiledObjectDecorator getDecorator(java.lang.Class<?> type)
Obtain the decorator of the given type.

Parameters:
type - the type of the decorator (syas his fqn)
Returns:
the decorator found

addWarning

public void addWarning(java.lang.String warning)
Add a warning to the engine.

Parameters:
warning - the warning to add

addError

public void addError(java.lang.String error)
Add an error to the engine.

Parameters:
error - the error to add

getErrors

public java.util.List<java.lang.String> getErrors()
Returns:
the errors of the engine

getWarnings

public java.util.List<java.lang.String> getWarnings()
Returns:
the warnings of the engine

run

public int run()
Compiled a set of files.

Returns:
-1 if errors appears, the number of generated files otherwise.

getCompiler

protected JAXXCompiler getCompiler(java.lang.String className,
                                   java.lang.String message)
                            throws CompilerException
Obtain the compiler for the given class name.

Parameters:
className - the class name of the searched compiler
message - the message to throw if compiler not found
Returns:
the compiler found
Throws:
CompilerException - if compiler not found

newCompiler

protected JAXXCompiler newCompiler(java.io.File parentFile,
                                   java.io.File file,
                                   java.lang.String className)
                            throws java.lang.reflect.InvocationTargetException,
                                   java.lang.IllegalAccessException,
                                   java.lang.InstantiationException,
                                   java.lang.NoSuchMethodException
Create a new compiler.

Parameters:
parentFile - the directory where to generate the java file
file - the path of file to generate
className - name of the class to generate in the file
Returns:
the new compiler
Throws:
java.lang.reflect.InvocationTargetException - introspection error
java.lang.IllegalAccessException - introspection error
java.lang.InstantiationException - introspection error
java.lang.NoSuchMethodException - introspection error

addProfileTime

public void addProfileTime(JAXXCompiler compiler,
                           java.lang.String key)
Add a profile time for the given compiler and key. Note: if profiler is null, do nothing

Parameters:
compiler - the compiler to profile
key - the key of profiling


Copyright © 2008-2009 CodeLutin. All Rights Reserved.