org.mozilla.javascript.optimizer
Class ClassCompiler
java.lang.Object
org.mozilla.javascript.optimizer.ClassCompiler
public class ClassCompiler
extends java.lang.Object
Generates class files from script sources.
since 1.5 Release 5
Object[] | compileToClassFiles(String source, String sourceLocation, int lineno, String mainClassName) - Compile JavaScript source into one or more Java class files.
|
CompilerEnvirons | getCompilerEnv() - Get the compiler environment the compiler uses.
|
String | getMainMethodClass() - Get the name of the class for main method implementation.
|
Class | getTargetExtends() - Get the class that the generated target will extend.
|
Class[] | getTargetImplements() - Get the interfaces that the generated target will implement.
|
protected String | makeAuxiliaryClassName(String mainClassName, String auxMarker) - Build class name for a auxiliary class generated by compiler.
|
void | setMainMethodClass(String className) - Set the class name to use for main method implementation.
|
void | setTargetExtends(Class extendsClass) - Set the class that the generated target will extend.
|
void | setTargetImplements(Class[] implementsClasses) - Set the interfaces that the generated target will implement.
|
ClassCompiler
public ClassCompiler(CompilerEnvirons compilerEnv)
Construct ClassCompiler that uses the specified compiler environment
when generating classes.
compileToClassFiles
public Object[] compileToClassFiles(String source,
String sourceLocation,
int lineno,
String mainClassName)
Compile JavaScript source into one or more Java class files.
The first compiled class will have name mainClassName.
If the results of
getTargetExtends()
or
getTargetImplements()
are not null, then the first compiled
class will extend the specified super class and implement
specified interfaces.
- array where elements with even indexes specifies class name
and the following odd index gives class file body as byte[]
array. The initial element of the array always holds
mainClassName and array[1] holds its byte code.
getCompilerEnv
public CompilerEnvirons getCompilerEnv()
Get the compiler environment the compiler uses.
getMainMethodClass
public String getMainMethodClass()
Get the name of the class for main method implementation.
getTargetExtends
public Class getTargetExtends()
Get the class that the generated target will extend.
getTargetImplements
public Class[] getTargetImplements()
Get the interfaces that the generated target will implement.
makeAuxiliaryClassName
protected String makeAuxiliaryClassName(String mainClassName,
String auxMarker)
Build class name for a auxiliary class generated by compiler.
If the compiler needs to generate extra classes beyond the main class,
it will call this function to build the auxiliary class name.
The default implementation simply appends auxMarker to mainClassName
but this can be overridden.
setMainMethodClass
public void setMainMethodClass(String className)
Set the class name to use for main method implementation.
The class must have a method matching
public static void main(Script sc, String[] args), it will be
called when main(String[] args) is called in the generated
class. The class name should be fully qulified name and include the
package name like in org.foo.Bar.
setTargetExtends
public void setTargetExtends(Class extendsClass)
Set the class that the generated target will extend.
extendsClass
- the class it extends
setTargetImplements
public void setTargetImplements(Class[] implementsClasses)
Set the interfaces that the generated target will implement.
implementsClasses
- an array of Class objects, one for each
interface the target will extend