public class SequenceCompiler
extends java.lang.Object
implements java.io.Closeable
String.
A simplified version of the javaxtools.compiler.CharSequenceCompiler from Create
dynamic applications with javax.tools.
| Modifier and Type | Field and Description |
|---|---|
private javax.tools.JavaCompiler |
compiler
The Java compiler.
|
private java.util.List<java.lang.String> |
compilerOptions
The options to the compiler.
|
static @Nullable java.lang.String |
debugCompilationFailure
If non-null, do verbose output for compilation failures where the Java source code contains the
string.
|
private javax.tools.JavaFileManager |
fileManager
The
FileManager for this compiler. |
| Constructor and Description |
|---|
SequenceCompiler()
Creates a
SequenceCompiler. |
SequenceCompiler(java.util.List<java.lang.String> compilerOptions)
Creates a
SequenceCompiler. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases any system resources associated with this.
|
private void |
compile(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource)
Compiles the given class.
|
private boolean |
compile(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource,
javax.tools.DiagnosticCollector<javax.tools.JavaFileObject> diagnostics)
A helper method for the
compile(String, String, String) and isCompilable(String, String, String) methods: compiles the given class using the given
diagnostics collector. |
java.lang.Class<?> |
compileAndLoad(@DotSeparatedIdentifiers java.lang.String packageName,
@Identifier java.lang.String classname,
java.lang.String javaSource)
Compiles the given class, leads it, and returns the Class object.
|
(package private) @BinaryName java.lang.String |
fullyQualifiedName(@DotSeparatedIdentifiers java.lang.String packageName,
@Identifier java.lang.String classname)
Constructs a fully-qualified class name from the given package and unqualified class name.
|
boolean |
isCompilable(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource)
Indicates whether the given class is compilable.
|
private static java.lang.Class<?> |
loadClassFile(java.io.File directory,
@BinaryName java.lang.String className)
Given a .class file, returns the corresponding Class object.
|
public static final @Nullable java.lang.String debugCompilationFailure
private final java.util.List<java.lang.String> compilerOptions
private final javax.tools.JavaCompiler compiler
private final javax.tools.JavaFileManager fileManager
FileManager for this compiler.public SequenceCompiler()
SequenceCompiler.public SequenceCompiler(java.util.List<java.lang.String> compilerOptions)
SequenceCompiler.compilerOptions - the compiler optionspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic boolean isCompilable(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource)
packageName - the package name for the class, null if default packageclassname - the simple name of the classjavaSource - the source text of the classprivate void compile(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource)
throws SequenceCompilerException
packageName - the package of the class, null if default packageclassname - the simple name of the classjavaSource - the source text of the classSequenceCompilerException - if the compilation failsprivate boolean compile(java.lang.String packageName,
java.lang.String classname,
java.lang.String javaSource,
javax.tools.DiagnosticCollector<javax.tools.JavaFileObject> diagnostics)
compile(String, String, String) and isCompilable(String, String, String) methods: compiles the given class using the given
diagnostics collector.packageName - the package of the class, null if default packageclassname - the simple name of the classjavaSource - the source text of the classdiagnostics - the DiagnosticsCollector object to use for the compilation. Always
use a new diagnostics collector each compilation to avoid accumulating errors.public java.lang.Class<?> compileAndLoad(@DotSeparatedIdentifiers java.lang.String packageName,
@Identifier java.lang.String classname,
java.lang.String javaSource)
throws SequenceCompilerException
packageName - the package of the class, null if default packageclassname - the simple name of the classjavaSource - the source text of the classSequenceCompilerException - if the compilation failsprivate static java.lang.Class<?> loadClassFile(java.io.File directory,
@BinaryName java.lang.String className)
directory - the directory containing the .class file (possibly in a package-named
subdirectory)className - the binary name of the class defined in the file@BinaryName java.lang.String fullyQualifiedName(@DotSeparatedIdentifiers java.lang.String packageName,
@Identifier java.lang.String classname)
packageName - the package of the class, null if default packageclassname - the name of the class, without the package