|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
org.codehaus.janino.Compiler
public class Compiler
A simplified substitute for the javac tool. Usage:
java org.codehaus.janino.Compiler \ [ -d destination-dir ] \ [ -sourcepath dirlist ] \ [ -classpath dirlist ] \ [ -extdirs dirlist ] \ [ -bootclasspath dirlist ] \ [ -encoding encoding ] \ [ -verbose ] \ [ -g:none ] \ [ -g:{source,lines,vars} ] \ [ -warn:pattern-list ] \ source-file ... java org.codehaus.janino.Compiler -help
Nested Class Summary | |
---|---|
static class |
Compiler.SimpleWarningHandler
Prints warnings to STDERR. |
Field Summary | |
---|---|
static ResourceCreator |
CREATE_NEXT_TO_SOURCE_FILE
Special value for "classFileResourceCreator". |
static StringPattern[] |
DEFAULT_WARNING_HANDLE_PATTERNS
The default value for the warningHandlerPatterns parameter of Compiler(File[], File[],
File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean) . |
static ResourceFinder |
FIND_NEXT_TO_SOURCE_FILE
Special value for "classFileResourceFinder". |
static |
NO_DESTINATION_DIRECTORY
Backwards compatibility -- previously, "null" was officially documented. |
Constructor Summary | |
---|---|
Compiler([] optionalSourcePath,
[] classPath,
[] optionalExtDirs,
[] optionalBootClassPath,
destinationDirectory,
optionalCharacterEncoding,
boolean verbose,
boolean debugSource,
boolean debugLines,
boolean debugVars,
StringPattern[] warningHandlePatterns,
boolean rebuild)
Initialize a Java™ compiler with the given parameters. |
|
Compiler(ResourceFinder sourceFinder,
IClassLoader iClassLoader,
ResourceFinder classFileFinder,
ResourceCreator classFileCreator,
optionalCharacterEncoding,
boolean verbose,
boolean debugSource,
boolean debugLines,
boolean debugVars,
WarningHandler optionalWarningHandler)
To mimic the behavior of JAVAC with a missing "-d" command line option, pass FIND_NEXT_TO_SOURCE_FILE as the classFileResourceFinder and
CREATE_NEXT_TO_SOURCE_FILE as the classFileResourceCreator . |
Method Summary | |
---|---|
boolean |
compile([] sourceFiles)
Reads a set of Java™ compilation units (a.k.a. |
boolean |
compile(Resource[] sourceResources)
See compile(File[]) . |
static |
getClassFile( className,
sourceFile,
optionalDestinationDirectory)
Construct the name of a file that could store the byte code of the class with the given name. |
static void |
main([] args)
Command line interface. |
void |
setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
Install a custom ErrorHandler . |
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a custom Compiler.SimpleWarningHandler . |
void |
storeClassFile(ClassFile classFile,
sourceFile)
Store the byte code of this ClassFile in the file system. |
Methods inherited from class java.lang. |
---|
, , , , , , , , , , |
Field Detail |
---|
public static final ResourceFinder FIND_NEXT_TO_SOURCE_FILE
public static final ResourceCreator CREATE_NEXT_TO_SOURCE_FILE
public static final NO_DESTINATION_DIRECTORY
public static final StringPattern[] DEFAULT_WARNING_HANDLE_PATTERNS
warningHandlerPatterns
parameter of Compiler(File[], File[],
File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean)
.
Constructor Detail |
---|
public Compiler([] optionalSourcePath, [] classPath, [] optionalExtDirs, [] optionalBootClassPath, destinationDirectory, optionalCharacterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild)
Classes are searched in the following order:
optionalBootClassPath
is null
:
optionalBootClassPath
is not null
:
optionalBootClassPath
optionalExtDirs
is not null
:
optionalExtDirs
classPath
optionalSourcePath
is null
:
classPath
optionalSourcePath
is not null
:
sourcePath
The file name of a class file that represents class "pkg.Example" is determined as follows:
optionalDestinationDirectory
is not NO_DESTINATION_DIRECTORY
:
<i>optionalDestinationDirectory</i>/pkg/Example.class
optionalDestinationDirectory
is NO_DESTINATION_DIRECTORY
:
dir1/dir2/Example.class
(Assuming that the file name of the
source file that declares the class was
dir1/dir2/Any.java
.)
DEFAULT_WARNING_HANDLE_PATTERNS
public Compiler(ResourceFinder sourceFinder, IClassLoader iClassLoader, ResourceFinder classFileFinder, ResourceCreator classFileCreator, optionalCharacterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, WarningHandler optionalWarningHandler)
FIND_NEXT_TO_SOURCE_FILE
as the classFileResourceFinder
and
CREATE_NEXT_TO_SOURCE_FILE
as the classFileResourceCreator
.
If it is impossible to check whether an already-compiled class file
exists, or if you want to enforce recompilation, pass
ResourceFinder.EMPTY_RESOURCE_FINDER
as the
classFileResourceFinder
.
sourceFinder
- Finds extra Java compilation units that need to be compiled (a.k.a. "-sourcepath")iClassLoader
- Loads auxiliary IClass
es (a.k.a. "-classpath"), e.g. new
ClassLoaderIClassLoader(ClassLoader)
classFileFinder
- Where to look for up-to-date class files that need not be compiled (a.k.a. "-d")classFileCreator
- Used to store generated class files (a.k.a. "-d")optionalWarningHandler
- Used to issue warningsMethod Detail |
---|
public static void main([] args)
public void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
ErrorHandler
. The default ErrorHandler
prints the first 20 compile errors to
and then throws a CompileException
.
Passing null
restores the default ErrorHandler
.
Notice that scan and parse errors are not redirected to this ErrorHandler
, instead, they cause a
CompileException
to be thrown. Also, the Compiler
may choose to throw CompileException
s
in certain, fatal compile error situations, even if an ErrorHandler
is installed.
In other words: In situations where compilation can reasonably continue after a compile error, the ErrorHandler
is called; all other error conditions cause a CompileException
to be thrown.
public void setWarningHandler(WarningHandler optionalWarningHandler)
Compiler.SimpleWarningHandler
.
optionalWarningHandler
- null
to indicate that no warnings be issuedpublic boolean compile([] sourceFiles) throws CompileException,
For example, if the source path comprises the directories "A/B" and "../C", then the source file for class "com.acme.Main" is searched in
compile(File[])
or if you invoke
compile(File[])
multiply: In the former case, the source
files may contain arbitrary references among each other (even circular
ones). In the latter case, only the source files on the source path
may contain circular references, not the sourceFiles
.
This method must be called exactly once after object construction.
Compile errors are reported as described at
setCompileErrorHandler(ErrorHandler)
.
sourceFiles
- Contain the compilation units to compile
true
for backwards compatibility (return value can safely be ignored)
CompileException
- Fatal compilation error, or the CompileException
thrown be the installed compile
error handler
- Occurred when reading from the sourceFiles
public boolean compile(Resource[] sourceResources) throws CompileException,
compile(File[])
.
sourceResources
- Contain the compilation units to compile
true
for backwards compatibility (return value can safely be ignored)
CompileException
public static getClassFile( className, sourceFile, optionalDestinationDirectory)
If optionalDestinationDirectory
is non-null, the returned path is the
optionalDestinationDirectory
plus the package of the class (with dots replaced
with file separators) plus the class name plus ".class". Example:
"destdir/pkg1/pkg2/Outer$Inner.class"
If optionalDestinationDirectory
is null, the returned path is the
directory of the sourceFile
plus the class name plus ".class". Example:
"srcdir/Outer$Inner.class"
className
- E.g. "pkg1.pkg2.Outer$Inner"sourceFile
- E.g. "srcdir/Outer.java"optionalDestinationDirectory
- E.g. "destdir"public void storeClassFile(ClassFile classFile, sourceFile) throws
ClassFile
in the file system. Directories are created
as necessary.
classFile
- sourceFile
- Required to compute class file path if no destination directory given
|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |