|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.teatrove.tea.compiler.Compiler
public abstract class Compiler
The Tea compiler. This class is abstract, and a few concrete implementations can be found in the org.teatrove.tea.util package.
A Compiler instance should be used for only one "build" because some information is cached internally like parse trees and error count.
FileCompiler,
ResourceCompiler| Constructor Summary | |
|---|---|
Compiler()
|
|
Compiler(Map<String,Template> parseTreeMap)
This constructor allows template signatures to be shared among compiler instances. |
|
| Method Summary | |
|---|---|
void |
addErrorListener(ErrorListener listener)
Add an ErrorListener in order receive events of compile-time errors. |
void |
addImportedPackage(String imported)
Add an imported package that all templates will have. |
void |
addImportedPackages(String[] imports)
Add all imported packages that all templates will have. |
void |
addStatusListener(StatusListener listener)
Add a StatusListener in order to receive events of compilation progress. |
String[] |
compile(String name)
Compile a single compilation unit. |
String[] |
compile(String[] names)
Compile a list of compilation units. |
protected CodeGenerator |
createCodeGenerator(CompilationUnit unit)
Default implementation returns a new JavaClassGenerator. |
protected abstract CompilationUnit |
createCompilationUnit(String name)
|
protected Parser |
createParser(Scanner scanner,
CompilationUnit unit)
|
protected Scanner |
createScanner(SourceReader reader,
CompilationUnit unit)
|
protected SourceReader |
createSourceReader(CompilationUnit unit)
Default implementation returns a SourceReader that uses "<%" and "%>" as code delimiters. |
protected TypeChecker |
createTypeChecker(CompilationUnit unit)
|
ClassLoader |
getClassLoader()
Returns the ClassLoader used by the Compiler, or null if none set. |
CompilationUnit |
getCompilationUnit(String name,
CompilationUnit from)
Returns a compilation unit associated with the given name, or null if not found or the compilation unit is . |
int |
getErrorCount()
|
String[] |
getImportedPackages()
Returns the list of imported packages that all templates have. |
Template |
getParseTree(CompilationUnit unit)
Called by the Compiler or by a CompilationUnit when its parse tree is requested. |
Class<?> |
getRuntimeContext()
Return a class that defines a template's runtime context. |
Method[] |
getRuntimeContextMethods()
Returns all the methods available in the runtime context. |
String |
getRuntimeReceiver()
Return the name of a method in the runtime context to bind to for receiving objects emitted by templates. |
String |
getRuntimeStringConverter()
Return the name of a method in the runtime context to bind to for converting objects and primitives to strings. |
Method[] |
getStringConverterMethods()
Returns the set of methods that are used to perform conversion to strings. |
boolean |
isCodeGenerationEnabled()
Returns true if code generation is enabled. |
boolean |
isExceptionGuardianEnabled()
Returns true if the exception guardian is enabled. |
Class<?> |
loadClass(String name)
Loads and returns a class by the fully qualified name given. |
void |
preserveParseTree(String name)
After a template is compiled, all but the root node of its parse tree is clipped, in order to save memory. |
void |
removeErrorListener(ErrorListener listener)
|
void |
removeStatusListener(StatusListener listener)
|
void |
setClassLoader(ClassLoader loader)
Sets the ClassLoader to use to load classes with. |
void |
setCodeGenerationEnabled(boolean flag)
By default, code generation is enabled. |
void |
setExceptionGuardianEnabled(boolean flag)
|
void |
setRuntimeContext(Class<?> contextClass)
Call to override the default runtime context class that a template is compiled to use. |
abstract boolean |
sourceExists(String name)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Compiler()
public Compiler(Map<String,Template> parseTreeMap)
parseTreeMap - map should be thread-safe| Method Detail |
|---|
public void addErrorListener(ErrorListener listener)
ConsoleErrorReporterpublic void removeErrorListener(ErrorListener listener)
public void addStatusListener(StatusListener listener)
public void removeStatusListener(StatusListener listener)
public void setCodeGenerationEnabled(boolean flag)
public boolean isCodeGenerationEnabled()
public void setExceptionGuardianEnabled(boolean flag)
public boolean isExceptionGuardianEnabled()
public void setClassLoader(ClassLoader loader)
public ClassLoader getClassLoader()
public Class<?> loadClass(String name)
throws ClassNotFoundException
ClassNotFoundExceptionsetClassLoader(ClassLoader)public void preserveParseTree(String name)
name - fully qualified name of template whose parse tree is to be
preserved.
public String[] compile(String name)
throws IOException
name - the fully qualified template name
IOException
public String[] compile(String[] names)
throws IOException
names - an array of fully qualified template names
IOExceptionpublic int getErrorCount()
public CompilationUnit getCompilationUnit(String name,
CompilationUnit from)
name - the requested namefrom - optional CompilationUnit is passed because requested name
should be found relative to it.public String[] getImportedPackages()
public void addImportedPackage(String imported)
imported - The fully-qualified package namepublic void addImportedPackages(String[] imports)
imports - The fully-qualified package namepublic Class<?> getRuntimeContext()
Default implementation returns org.teatrove.tea.runtime.UtilityContext.
UtilityContextpublic void setRuntimeContext(Class<?> contextClass)
Contextpublic final Method[] getRuntimeContextMethods()
public String getRuntimeReceiver()
Default implementation returns "print".
public String getRuntimeStringConverter()
Default implementation returns "toString". Returning null indicates that a static String.valueOf method should be invoked.
public final Method[] getStringConverterMethods()
public abstract boolean sourceExists(String name)
protected abstract CompilationUnit createCompilationUnit(String name)
protected SourceReader createSourceReader(CompilationUnit unit)
throws IOException
IOException
protected Scanner createScanner(SourceReader reader,
CompilationUnit unit)
throws IOException
IOException
protected Parser createParser(Scanner scanner,
CompilationUnit unit)
throws IOException
IOExceptionprotected TypeChecker createTypeChecker(CompilationUnit unit)
protected CodeGenerator createCodeGenerator(CompilationUnit unit)
throws IOException
IOExceptionJavaClassGeneratorpublic Template getParseTree(CompilationUnit unit)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||