public interface ICompiler
| Modifier and Type | Field and Description |
|---|---|
static ResourceCreator |
CREATE_NEXT_TO_SOURCE_FILE
Special value for
setClassFileCreator(ResourceCreator): Indicates that .class resources are to be
created in the directory of the .java resource from which they are generated. |
static ResourceFinder |
FIND_NEXT_TO_SOURCE_FILE
Special value for
setClassFileFinder(ResourceFinder). |
static File |
NO_DESTINATION_DIRECTORY
Special value for
setDestinationDirectory(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. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compile(File[] sourceFiles)
Reads a set of Java compilation units (a.k.a.
|
void |
compile(Resource[] sourceResources)
See
compile(File[]). |
void |
setBootClassPath(File[] directoriesAndArchives)
Equivalent of
--boot-class-path. |
void |
setCharacterEncoding(String characterEncoding)
Deprecated.
Use
setSourceCharset(Charset) instead |
void |
setClassFileCreator(ResourceCreator classFileCreator)
This
ResourceCreator is used to store generated .class files. |
void |
setClassFileFinder(ResourceFinder classFileFinder)
This
ResourceFinder is used to check whether a .class resource already exists and is younger
than the .java resource from which it was generated. |
void |
setClassFileFinder(ResourceFinder classFileFinder,
boolean rebuild)
Equivalent with {@code setClassFileFinder(rebuild ?
|
void |
setClassPath(File[] directoriesAndArchives)
Equivalent of
--class-path.
|
void |
setCompileErrorHandler(ErrorHandler errorHandler)
Installs an
ErrorHandler which is invoked during compilation on each error. |
void |
setDebugLines(boolean value)
Equivalent of
-g:lines. |
void |
setDebugSource(boolean value)
Equivalent of
-g:source. |
void |
setDebugVars(boolean value)
Equivalent of
-g:vars. |
void |
setDestinationDirectory(File destinationDirectory,
boolean rebuild)
Equivalent of
-d and
-rebuild. |
void |
setEncoding(Charset encoding)
The equivalent of JAVA's "
-encoding" command line option. |
void |
setExtensionDirectories(File[] directories)
Equivalent of
-extdirs. |
void |
setSourceCharset(Charset charset)
Same as
setEncoding(Charset), but with a more precise name. |
void |
setSourceFinder(ResourceFinder sourceFinder)
Finds more
.java resources that need to be compiled, i.e. implements JAVAC's -sourcepath option. |
void |
setSourcePath(File[] directoriesAndArchives)
Equivalent of
--source-path. |
void |
setSourceVersion(int version)
Specifies the version of source code accepted, in analogy with JAVAC's
-source command line option. |
void |
setTargetVersion(int version)
Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's
-target command line option. |
void |
setVerbose(boolean verbose)
Equivalent of
-verbose. |
void |
setWarningHandler(WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
@Nullable static final File NO_DESTINATION_DIRECTORY
setDestinationDirectory(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.static final ResourceFinder FIND_NEXT_TO_SOURCE_FILE
setClassFileFinder(ResourceFinder).setClassFileFinder(ResourceFinder)static final ResourceCreator CREATE_NEXT_TO_SOURCE_FILE
setClassFileCreator(ResourceCreator): Indicates that .class resources are to be
created in the directory of the .java resource from which they are generated.void setEncoding(Charset encoding)
-encoding" command line option.setSourceCharset(Charset)void setSourceCharset(Charset charset)
setEncoding(Charset), but with a more precise name.@Deprecated void setCharacterEncoding(@Nullable String characterEncoding)
setSourceCharset(Charset) insteadvoid setDebugLines(boolean value)
-g:lines.void setDebugVars(boolean value)
-g:vars.void setDebugSource(boolean value)
-g:source.void setSourceVersion(int version)
-source command line option.
May be ignored by an implementation (e.g. the janino implementation always accepts the language features
as described on the home page).
Allowed values, and the default value, depend on the implementation.
-1 means to use a default version.void setTargetVersion(int version)
-target command 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.
-1 means to use a default version.void setSourceFinder(ResourceFinder sourceFinder)
.java resources that need to be compiled, i.e. implements JAVAC's -sourcepath option.void setSourcePath(File[] directoriesAndArchives)
--source-path.
Equivalent with setSourceFinder(new PathResourceFinder(directoriesAndArchives)).
void setBootClassPath(File[] directoriesAndArchives)
--boot-class-path.void setExtensionDirectories(File[] directories)
-extdirs.void setClassPath(File[] directoriesAndArchives)
void setDestinationDirectory(@Nullable File destinationDirectory, boolean rebuild)
-rebuild.
Overrides any previously configured class file finder and class file creator.
destinationDirectory - NO_DESTINATION_DIRECTORY means "create .class resources in
the directory of the .java resource from which they are generated"NO_DESTINATION_DIRECTORY,
setClassFileFinder(ResourceFinder),
setClassFileCreator(ResourceCreator)void setClassFileFinder(ResourceFinder classFileFinder, boolean rebuild)
setClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).void setClassFileFinder(ResourceFinder classFileFinder)
ResourceFinder is used to check whether a .class resource already exists and is younger
than the .java resource 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_FINDER as the classFileFinder.
The default is, as for JAVAC, FIND_NEXT_TO_SOURCE_FILE.
classFileFinder - Special value FIND_NEXT_TO_SOURCE_FILE means ".class file is next to
its source file, not in the destination directory"FIND_NEXT_TO_SOURCE_FILEvoid setClassFileCreator(ResourceCreator classFileCreator)
ResourceCreator is used to store generated .class files.
The default is, as for JAVAC, CREATE_NEXT_TO_SOURCE_FILE.
classFileCreator - Special value CREATE_NEXT_TO_SOURCE_FILE means "create .class file
next to its source file, not in the destination directory"CREATE_NEXT_TO_SOURCE_FILEvoid setVerbose(boolean verbose)
-verbose.boolean compile(File[] sourceFiles) throws CompileException, IOException
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
Notice that it does make a difference whether you pass multiple source files to 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 compiletrue for backwards compatibility (return value can safely be ignored)CompileException - Fatal compilation error, or the CompileException thrown be the installed
compile error handlerIOException - Occurred when reading from the sourceFilesvoid compile(Resource[] sourceResources) throws CompileException, IOException
compile(File[]).sourceResources - Contain the compilation units to compileCompileExceptionIOExceptionvoid setCompileErrorHandler(@Nullable ErrorHandler errorHandler)
ErrorHandler which is invoked during compilation on each error. (By default, the compilation
throws a CompileException on the first error and terminates.)
If the given ErrorHandler throws a CompileException, then the compilation terminates and
the exception is propagated.
If the given ErrorHandler does not throw a CompileException but 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 a CompileException indicating the
number of errors.
In other words: The ErrorHandler may throw a CompileException or not, but the compilation will
definitely throw a CompileException if one or more compile errors have occurred.
errorHandler - null to restore the default behavior (throwing a CompileException)void setWarningHandler(WarningHandler warningHandler)
WarningHandler.warningHandler - null to indicate that no warnings be issuedCopyright © 2023. All rights reserved.