public abstract class ICompiler extends Object
| 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)'s parameter: Indicates that .class files are to be
created in the directory of the .java file from which they are generated. |
| Constructor and Description |
|---|
ICompiler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compile(File[] sourceFiles)
Reads a set of Java compilation units (a.k.a.
|
abstract void |
compile(Resource[] sourceResources)
See
compile(File[]). |
abstract void |
setBootClassPath(File[] directoriesAndArchives)
Equivalent of
--boot-class-path. |
void |
setCharacterEncoding(String characterEncoding) |
abstract void |
setClassFileCreator(ResourceCreator classFileCreator) |
abstract void |
setClassFileFinder(ResourceFinder resourceFinder)
This
ResourceFinder is used to check whether a .class resource already exists and is younger than the
.java resource from which it was generated. |
abstract void |
setClassPath(File[] directoriesAndArchives)
Equivalent of
--class-path.
|
abstract void |
setCompileErrorHandler(ErrorHandler errorHandler)
By default,
CompileExceptions are thrown on compile errors, but an application my install its own
ErrorHandler. |
abstract void |
setDebugLines(boolean value)
Equivalent of
-g:lines. |
abstract void |
setDebugSource(boolean value)
Equivalent of
-g:source. |
abstract void |
setDebugVars(boolean value)
Equivalent of
-g:vars. |
void |
setDestinationDirectory(File destinationDirectory)
Equivalent of
-d.
|
abstract void |
setEncoding(Charset encoding)
Equivalent of -encoding.
|
abstract void |
setExtensionDirectories(File[] directories)
Equivalent of
-extdirs. |
void |
setRebuild(boolean value)
Equivalent of
-rebuild. |
abstract void |
setSourceFinder(ResourceFinder sourceFinder)
Finds more .java resources that need to be compiled, i.e. implements the "source path".
|
abstract void |
setSourcePath(File[] directoriesAndArchives)
Equivalent of
--source-path. |
abstract void |
setVerbose(boolean verbose)
Equivalent of
-verbose. |
abstract void |
setWarningHandler(WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
@Nullable public static final File NO_DESTINATION_DIRECTORY
setDestinationDirectory(File)'s parameter: Indicates that .class files are to be
created in the directory of the .java file from which they are generated.@Nullable public static final ResourceFinder FIND_NEXT_TO_SOURCE_FILE
setClassFileFinder(ResourceFinder).setClassFileFinder(ResourceFinder)@Nullable public 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.public abstract void setDebugLines(boolean value)
-g:lines.public abstract void setDebugVars(boolean value)
-g:vars.public abstract void setDebugSource(boolean value)
-g:source.public abstract void setSourcePath(File[] directoriesAndArchives)
--source-path.public abstract void setBootClassPath(File[] directoriesAndArchives)
--boot-class-path.public abstract void setExtensionDirectories(File[] directories)
-extdirs.public abstract void setClassPath(File[] directoriesAndArchives)
public final void setDestinationDirectory(@Nullable File destinationDirectory)
destinationDirectory - NO_DESTINATION_DIRECTORY means "create .class resources in the
directory of the .java resource from which they are generated"NO_DESTINATION_DIRECTORYpublic abstract void setVerbose(boolean verbose)
-verbose.public final void setRebuild(boolean value)
-rebuild.public abstract void setSourceFinder(ResourceFinder sourceFinder)
sourceFinder - public abstract void setClassFileCreator(@Nullable ResourceCreator classFileCreator)
classFileCreator - Sess CREATE_NEXT_TO_SOURCE_FILEpublic final 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 sourceFilespublic abstract void setClassFileFinder(@Nullable ResourceFinder resourceFinder)
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.
resourceFinder - 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_FILEpublic abstract void compile(Resource[] sourceResources) throws CompileException, IOException
compile(File[]).sourceResources - Contain the compilation units to compileCompileExceptionIOExceptionpublic abstract void setCompileErrorHandler(@Nullable ErrorHandler errorHandler)
CompileExceptions are thrown on compile errors, but an application my install its own
ErrorHandler.
Be aware that a single problem during compilation often causes a bunch of compile errors, so a good ErrorHandler counts errors and throws a CompileException when a limit is reached.
If the given ErrorHandler throws CompileExceptions, then the compilation is terminated and
the exception is propagated.
If the given ErrorHandler does not throw CompileExceptions, then the compiler may or may not
continue compilation, but must eventually throw a CompileException.
In other words: The ErrorHandler may throw a CompileException or not, but the compiler must
definitely throw a CompileException if one or more compile errors have occurred.
errorHandler - null to restore the default behavior (throwing a CompileExceptionpublic abstract void setWarningHandler(WarningHandler warningHandler)
WarningHandler.warningHandler - null to indicate that no warnings be issuedCopyright © 2020. All rights reserved.