| Modifier and Type | Field and Description |
|---|---|
protected File[] |
bootClassPath
This is always non-
null for JVMs that support BOOTCLASSPATH (1.0-1.8), and
this is always null for JVMs that don't (9+). |
protected ResourceCreator |
classFileCreator |
protected ResourceFinder |
classFileFinder |
protected File[] |
classPath
The classpath of the currently executing JRE.
|
protected ErrorHandler |
compileErrorHandler |
protected boolean |
debugLines |
protected boolean |
debugSource |
protected boolean |
debugVars |
Charset |
encoding |
protected File[] |
extensionDirectories
The list of extension directories of the currently executing JRE.
|
protected ResourceFinder |
sourceFinder |
protected WarningHandler |
warningHandler |
CREATE_NEXT_TO_SOURCE_FILE, FIND_NEXT_TO_SOURCE_FILE, NO_DESTINATION_DIRECTORY| Constructor and Description |
|---|
AbstractCompiler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compile(File[] sourceFiles)
Reads a set of Java compilation units (a.k.a.
|
void |
setBootClassPath(File[] directoriesAndArchives)
Equivalent of
--boot-class-path. |
void |
setCharacterEncoding(String characterEncoding)
Equivalent with
setEncoding(Charset.forName(characterEncoding)). |
void |
setClassFileCreator(ResourceCreator classFileCreator) |
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 destination,
boolean rebuild)
Equivalent with {@code setClassFileFinder(rebuild ?
|
void |
setClassPath(File[] directoriesAndArchives)
Equivalent of
--class-path.
|
void |
setCompileErrorHandler(ErrorHandler compileErrorHandler)
By default,
CompileExceptions are thrown on compile errors, but an application my install its own
ErrorHandler. |
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)
Equivalent of -encoding.
|
void |
setExtensionDirectories(File[] directories)
Equivalent of
-extdirs. |
void |
setSourceFinder(ResourceFinder sourceFinder)
Finds more .java resources that need to be compiled, i.e. implements the "source path".
|
void |
setSourcePath(File[] directoriesAndArchives)
Equivalent of
--source-path. |
void |
setWarningHandler(WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompile, setVerboseprotected ResourceFinder sourceFinder
protected ResourceFinder classFileFinder
protected ResourceCreator classFileCreator
public Charset encoding
protected boolean debugSource
protected boolean debugLines
protected boolean debugVars
protected File[] extensionDirectories
protected File[] classPath
@Nullable protected File[] bootClassPath
null for JVMs that support BOOTCLASSPATH (1.0-1.8), and
this is always null for JVMs that don't (9+).@Nullable protected ErrorHandler compileErrorHandler
@Nullable protected WarningHandler warningHandler
public void setSourceFinder(ResourceFinder sourceFinder)
ICompilersetSourceFinder in interface ICompilerpublic final void setClassFileFinder(ResourceFinder destination, boolean rebuild)
ICompilersetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : destination).setClassFileFinder in interface ICompilerpublic void setClassFileFinder(ResourceFinder classFileFinder)
ICompilerResourceFinder 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, ICompiler.FIND_NEXT_TO_SOURCE_FILE.
setClassFileFinder in interface ICompilerclassFileFinder - Special value ICompiler.FIND_NEXT_TO_SOURCE_FILE means ".class file is next to
its source file, not in the destination directory"ICompiler.FIND_NEXT_TO_SOURCE_FILEpublic final void setClassFileCreator(ResourceCreator classFileCreator)
setClassFileCreator in interface ICompilerclassFileCreator - Stores the generated class files (a.k.a. "-d"); special value ICompiler.CREATE_NEXT_TO_SOURCE_FILE means "create each .class file in the same directory as
its source file"public final boolean compile(File[] sourceFiles) throws CompileException, IOException
ICompilerFor 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 ICompiler.compile(File[]) or if
you invoke ICompiler.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 ICompiler.setCompileErrorHandler(ErrorHandler).
compile in interface ICompilersourceFiles - 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 void setEncoding(Charset encoding)
ICompilersetEncoding in interface ICompilerpublic void setCharacterEncoding(@Nullable String characterEncoding)
ICompilersetEncoding(Charset.forName(characterEncoding)).setCharacterEncoding in interface ICompilerpublic void setDebugLines(boolean value)
ICompiler-g:lines.setDebugLines in interface ICompilerpublic void setDebugVars(boolean value)
ICompiler-g:vars.setDebugVars in interface ICompilerpublic void setDebugSource(boolean value)
ICompiler-g:source.setDebugSource in interface ICompilerpublic void setSourcePath(File[] directoriesAndArchives)
ICompiler--source-path.
Equivalent with setSourceFinder(new PathResourceFinder(directoriesAndArchives)).
setSourcePath in interface ICompilerpublic void setBootClassPath(File[] directoriesAndArchives)
ICompiler--boot-class-path.setBootClassPath in interface ICompilerpublic void setExtensionDirectories(File[] directories)
ICompiler-extdirs.setExtensionDirectories in interface ICompilerpublic void setClassPath(File[] directoriesAndArchives)
ICompilersetClassPath in interface ICompilerpublic final void setDestinationDirectory(@Nullable File destinationDirectory, boolean rebuild)
ICompiler-rebuild.
Overrides any previously configured class file finder and class file creator.
setDestinationDirectory in interface ICompilerdestinationDirectory - ICompiler.NO_DESTINATION_DIRECTORY means "create .class resources in
the directory of the .java resource from which they are generated"ICompiler.NO_DESTINATION_DIRECTORY,
ICompiler.setClassFileFinder(ResourceFinder),
ICompiler.setClassFileCreator(ResourceCreator)public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
ICompilerCompileExceptions 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.
setCompileErrorHandler in interface ICompilercompileErrorHandler - null to restore the default behavior (throwing a CompileExceptionpublic void setWarningHandler(@Nullable WarningHandler warningHandler)
ICompilerWarningHandler.setWarningHandler in interface ICompilerwarningHandler - null to indicate that no warnings be issuedCopyright © 2019. All rights reserved.