Interface ICompiler
- All Known Implementing Classes:
AbstractCompiler, Compiler, Compiler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceCreatorSpecial value forsetClassFileCreator(ResourceCreator): Indicates that .class resources are to be created in the directory of the .java resource from which they are generated.static final ResourceFinderSpecial value forsetClassFileFinder(ResourceFinder).static final FileSpecial value forsetDestinationDirectory(File, boolean)'s first parameter: Indicates that .class files are to be created in the directory of the .java file from which they are generated. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReads a set of Java compilation units (a.k.a.voidSeecompile(File[]).voidsetBootClassPath(File[] directoriesAndArchives) Equivalent of--boot-class-path.voidsetCharacterEncoding(String characterEncoding) Deprecated.voidsetClassFileCreator(ResourceCreator classFileCreator) ThisResourceCreatoris used to store generated.classfiles.voidsetClassFileFinder(ResourceFinder classFileFinder) ThisResourceFinderis used to check whether a.classresource already exists and is younger than the.javaresource from which it was generated.voidsetClassFileFinder(ResourceFinder classFileFinder, boolean rebuild) Equivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).voidsetClassPath(File[] directoriesAndArchives) Equivalent of --class-path.voidsetCompileErrorHandler(ErrorHandler errorHandler) Installs anErrorHandlerwhich is invoked during compilation on each error.voidsetDebugLines(boolean value) Equivalent of-g:lines.voidsetDebugSource(boolean value) Equivalent of-g:source.voidsetDebugVars(boolean value) Equivalent of-g:vars.voidsetDestinationDirectory(File destinationDirectory, boolean rebuild) Equivalent of -d and-rebuild.voidsetEncoding(Charset encoding) The equivalent of JAVA's "-encoding" command line option.voidsetExtensionDirectories(File[] directories) Equivalent of-extdirs.voidsetSourceCharset(Charset charset) Same assetEncoding(Charset), but with a more precise name.voidsetSourceFinder(ResourceFinder sourceFinder) Finds more.javaresources that need to be compiled, i.e.voidsetSourcePath(File[] directoriesAndArchives) Equivalent of--source-path.voidsetSourceVersion(int version) Specifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option.voidsetTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option.voidsetVerbose(boolean verbose) Equivalent of-verbose.voidsetWarningHandler(WarningHandler warningHandler) By default, warnings are discarded, but an application my install a customWarningHandler.
-
Field Details
-
NO_DESTINATION_DIRECTORY
Special value forsetDestinationDirectory(File, boolean)'s first parameter: Indicates that .class files are to be created in the directory of the .java file from which they are generated. -
FIND_NEXT_TO_SOURCE_FILE
Special value forsetClassFileFinder(ResourceFinder).- See Also:
-
CREATE_NEXT_TO_SOURCE_FILE
Special value forsetClassFileCreator(ResourceCreator): Indicates that .class resources are to be created in the directory of the .java resource from which they are generated.
-
-
Method Details
-
setEncoding
The equivalent of JAVA's "-encoding" command line option.- See Also:
-
setSourceCharset
Same assetEncoding(Charset), but with a more precise name. -
setCharacterEncoding
Deprecated.UsesetSourceCharset(Charset)instead -
setDebugLines
void setDebugLines(boolean value) Equivalent of-g:lines. -
setDebugVars
void setDebugVars(boolean value) Equivalent of-g:vars. -
setDebugSource
void setDebugSource(boolean value) Equivalent of-g:source. -
setSourceVersion
void setSourceVersion(int version) Specifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option. May be ignored by an implementation (e.g. thejaninoimplementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation.-1means to use a default version. -
setTargetVersion
void setTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option. Allowed values depend on the implementation. The default value also depends on the implementation. The only invariant is that the generated class files are suitable for the currently executing JVM.-1means to use a default version. -
setSourceFinder
Finds more.javaresources that need to be compiled, i.e. implements JAVAC's-sourcepathoption. -
setSourcePath
Equivalent of--source-path.Equivalent with
setSourceFinder(new PathResourceFinder(directoriesAndArchives)). -
setBootClassPath
Equivalent of--boot-class-path. -
setExtensionDirectories
Equivalent of-extdirs. -
setClassPath
Equivalent of --class-path. -
setDestinationDirectory
Equivalent of -d and-rebuild.Overrides any previously configured
class file finderandclass file creator.- Parameters:
destinationDirectory-NO_DESTINATION_DIRECTORYmeans "create .class resources in the directory of the .java resource from which they are generated"- See Also:
-
setClassFileFinder
Equivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder). -
setClassFileFinder
ThisResourceFinderis used to check whether a.classresource already exists and is younger than the.javaresource from which it was generated.If it is impossible to check whether an already-compiled class file exists, or if you want to enforce recompilation, pass
ResourceFinder.EMPTY_RESOURCE_FINDERas the classFileFinder.The default is, as for JAVAC,
FIND_NEXT_TO_SOURCE_FILE.- Parameters:
classFileFinder- Special valueFIND_NEXT_TO_SOURCE_FILEmeans ".class file is next to its source file, not in the destination directory"- See Also:
-
setClassFileCreator
ThisResourceCreatoris used to store generated.classfiles.The default is, as for JAVAC,
CREATE_NEXT_TO_SOURCE_FILE.- Parameters:
classFileCreator- Special valueCREATE_NEXT_TO_SOURCE_FILEmeans "create .class file next to its source file, not in the destination directory"- See Also:
-
setVerbose
void setVerbose(boolean verbose) Equivalent of-verbose. -
compile
Reads a set of Java compilation units (a.k.a. "source files") from the file system, compiles them into a set of "class files" and stores these in the file system. Additional source files are parsed and compiled on demand through the "source path" set of directories.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
- A/B/com/acme/Main.java
- ../C/com/acme/Main.java
Notice that it does make a difference whether you pass multiple source files to
compile(File[])or if you invokecompile(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).- Parameters:
sourceFiles- Contain the compilation units to compile- Returns:
truefor backwards compatibility (return value can safely be ignored)- Throws:
CompileException- Fatal compilation error, or theCompileExceptionthrown be the installed compile error handlerIOException- Occurred when reading from the sourceFiles
- A/B/com/acme/Main.java
-
compile
Seecompile(File[]).- Parameters:
sourceResources- Contain the compilation units to compile- Throws:
CompileExceptionIOException
-
setCompileErrorHandler
Installs anErrorHandlerwhich is invoked during compilation on each error. (By default, the compilation throws aCompileExceptionon the first error and terminates.)If the given
ErrorHandlerthrows aCompileException, then the compilation terminates and the exception is propagated.If the given
ErrorHandlerdoes not throw aCompileExceptionbut completes normally, then the compilation may or may not continue, depending on the error. Iff the compilation of a compilation unit completes normally but errors were reported, then it will throw aCompileExceptionindicating the number of errors.In other words: The
ErrorHandlermay throw aCompileExceptionor not, but the compilation will definitely throw aCompileExceptionif one or more compile errors have occurred.- Parameters:
errorHandler-nullto restore the default behavior (throwing aCompileException)
-
setWarningHandler
By default, warnings are discarded, but an application my install a customWarningHandler.- Parameters:
warningHandler-nullto indicate that no warnings be issued
-
setSourceCharset(Charset)instead