jaxx.compiler
Class JAXXEngine

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

public class JAXXEngine
extends 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  String[] classNames
          original list of classes to run
protected  Map<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  Map<String,CompiledObjectDecorator> decorators
          decorators available in engine
protected  List<String> errors
          Errors detected while running.
protected  File[] files
          original list of files to run
protected  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  Map<File,SymbolTable> symbolTables
          Maps the names of classes being compiled to their symbol tables (created after the first compiler pass).
protected  List<String> warnings
          Warnings detected while running.
 
Constructor Summary
protected JAXXEngine(File[] files, String[] classNames, CompilerConfiguration options)
           
 
Method Summary
 void addError(String error)
          Add an error to the engine.
 void addJaxxFile(File jaxxFile)
           
 void addJaxxFileClassName(String className)
           
 void addProfileTime(JAXXCompiler compiler, String key)
          Add a profile time for the given compiler and key.
 void addWarning(String warning)
          Add a warning to the engine.
 boolean containsJaxxFileClassName(String className)
           
static JAXXCompiler createDummyCompiler(ClassLoader classLoader)
          Creates a dummy Compiler for use in unit testing or dettached use of an engine.
static JAXXEngine get()
           
protected  JAXXCompiler getCompiler(String className, String message)
          Obtain the compiler for the given class name.
 JAXXEngine.LifeCycle getCurrentPass()
           
 CompiledObjectDecorator getDecorator(Class<?> type)
          Obtain the decorator of the given type.
 CompiledObjectDecorator getDecorator(String name)
          Obtain the decorator of the given name.
 List<String> getErrors()
           
 JAXXCompiler getJAXXCompiler(String className)
          Obtain the jaxx compiler of the given class name.
 SymbolTable getSymbolTable(String className)
          Obtain the symbo table for the given class name.
 String getVersion()
           
 List<String> getWarnings()
           
static boolean isRegistred()
           
static void loadLibraries(boolean verbose)
          Load the Initializer services found via theServiceLoader mecanism.
protected  JAXXCompiler newCompiler(File parentFile, File file, 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(File[] files, String[] classNames, CompilerConfiguration configuration)
          Create a new launchor and set it as current launchor accessible via method get().
static JAXXEngine newLaunchor(File base, 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 File[] files
original list of files to run


classNames

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


compilers

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


symbolTables

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


warnings

protected List<String> warnings
Warnings detected while running.


errors

protected List<String> errors
Errors detected while running.


profiler

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


decorators

protected Map<String,CompiledObjectDecorator> decorators
decorators available in engine


finalizers

protected List<JAXXCompilerFinalizer> finalizers
finalizers available in engine

Constructor Detail

JAXXEngine

protected JAXXEngine(File[] files,
                     String[] classNames,
                     CompilerConfiguration options)
Method Detail

addJaxxFileClassName

public void addJaxxFileClassName(String className)

addJaxxFile

public void addJaxxFile(File jaxxFile)

containsJaxxFileClassName

public boolean containsJaxxFileClassName(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(File base,
                                     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(File[] files,
                                     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 NullPointerException
Returns:
the current launchor
Throws:
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 String getVersion()

createDummyCompiler

public static JAXXCompiler createDummyCompiler(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(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(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(String name)
                                     throws IllegalArgumentException
Obtain the decorator of the given name.

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

getDecorator

public CompiledObjectDecorator getDecorator(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(String warning)
Add a warning to the engine.

Parameters:
warning - the warning to add

addError

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

Parameters:
error - the error to add

getErrors

public List<String> getErrors()
Returns:
the errors of the engine

getWarnings

public List<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(String className,
                                   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(File parentFile,
                                   File file,
                                   String className)
                            throws InvocationTargetException,
                                   IllegalAccessException,
                                   InstantiationException,
                                   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:
InvocationTargetException - introspection error
IllegalAccessException - introspection error
InstantiationException - introspection error
NoSuchMethodException - introspection error

addProfileTime

public void addProfileTime(JAXXCompiler compiler,
                           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-2010 CodeLutin. All Rights Reserved.