![]() |
Qore jni Module 2.4.0
|
Public Member Methods | |
| QoreJavaCompiler () | |
| QoreJavaCompiler (Iterable< String > options) | |
| QoreJavaCompiler (String[] options) | |
| QoreJavaCompiler (QoreURLClassLoader loader, Iterable< String > options) | |
| synchronized CompilerOutput< T > | compile (final String qualifiedClassName, final String javaSource, final Class<?>... types) throws QoreJavaCompilerException, ClassCastException |
| synchronized CompilerOutput< T > | compile (final String qualifiedClassName, final CharSequence javaSource, final Class<?>... types) throws QoreJavaCompilerException, ClassCastException |
| synchronized CompilerOutput< T > | compile (final String qualifiedClassName, final String javaSource, final DiagnosticCollector< JavaFileObject > diagnosticsList, final Class<?>... types) throws QoreJavaCompilerException, ClassCastException |
| synchronized CompilerOutput< T > | compile (final String qualifiedClassName, final CharSequence javaSource, final DiagnosticCollector< JavaFileObject > diagnosticsList, final Class<?>... types) throws QoreJavaCompilerException, ClassCastException |
| synchronized Map< String, CompilerOutput< T > > | compile (final Map< String, CharSequence > classes, final DiagnosticCollector< JavaFileObject > diagnosticsList) throws QoreJavaCompilerException |
| Class< T > | loadClass (final String qualifiedClassName) throws ClassNotFoundException |
| void | addClassPath (String path) |
| ClassLoader | getClassLoader () |
Compile a String or other CharSequence, returning a Java Class instance that may be instantiated as well as the raw bytecode. This class is a Facade around JavaCompiler for a narrower use case, but a bit easier to use.
To compile a String containing source for a Java class which implements MyInterface:
ClassLoader classLoader = MyClass.class.getClassLoader(); // optional; null is also OK
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>(); // optional; null is also OK
QoreJavaCompiler<Object> compiler = new QoreJavaCompiler<MyInterface>(classLoader,
null);
try {
Class<MyInterface> newClass = compiler.compile("com.mypackage.NewClass",
stringContainingSourceForNewClass, diagnostics, MyInterface).cls;
MyInterface instance = newClass.newInstance();
instance.someOperation(someArgs);
} catch (QoreJavaCompilerException e) {
handle(e);
} catch (IllegalAccessException e) {
handle(e);
}
The source can be in a String, StringBuffer, or your own class which implements CharSequence. If you implement your own, it must be thread safe (preferably, immutable.)
|
inline |
Construct a new instance which delegates to a new Qore classloader.
| IllegalStateException | if the Java compiler cannot be loaded. |
|
inline |
Construct a new instance which delegates to a new Qore classloader.
| options | The compiler options (such as "-target" "1.5"). See the usage for javac |
| IllegalStateException | if the Java compiler cannot be loaded. |
|
inline |
Construct a new instance which delegates to a new Qore classloader.
| options | The compiler options (such as "-target" "1.5"). See the usage for javac |
| IllegalStateException | if the Java compiler cannot be loaded. |
|
inline |
Construct a new instance which delegates to the named class loader.
| loader | the application ClassLoader. The compiler will look through to this // class loader for dependent classes |
| options | The compiler options (such as "-target" "1.5"). See the usage for javac |
| IllegalStateException | if the Java compiler cannot be loaded. |
|
inline |
Add a path to the classpath
|
inline |
Compile multiple Java source strings and return a Map containing the resulting classes.
Thread safety: this method is thread safe if the classes and diagnosticsList are isolated to this thread.
| classes | A Map whose keys are qualified class names and whose values are the Java source strings containing the definition of the class. A map value may be null, indicating that compiled class is expected, although no source exists for it (it may be a non-public class contained in one of the other strings.) |
| diagnosticsList | Any diagnostics generated by compiling the source are added to this list. |
| QoreJavaCompilerException | if the source cannot be compiled |
|
inline |
Compile Java source in javaSource</name> and return the resulting class.
Thread safety: this method is thread safe if the javaSource is isolated to this thread.
| qualifiedClassName | The fully qualified class name. |
| javaSource | Complete java source, including a package statement and a class, interface, or annotation declaration. |
| types | zero or more Class objects representing classes or interfaces that the resulting class must be assignable (castable) to. |
| QoreJavaCompilerException | if the source cannot be compiled - for example, if it contains syntax or semantic errors or if dependent classes cannot be found. |
| ClassCastException | if the generated class is not assignable to all the optional types. |
|
inline |
Compile Java source in javaSource</name> and return the resulting class.
Thread safety: this method is thread safe if the javaSource and diagnosticsList are isolated to this thread.
| qualifiedClassName | The fully qualified class name. |
| javaSource | Complete java source, including a package statement and a class, interface, or annotation declaration. |
| diagnosticsList | Any diagnostics generated by compiling the source are added to this collector. |
| types | zero or more Class objects representing classes or interfaces that the resulting class must be assignable (castable) to. |
| QoreJavaCompilerException | if the source cannot be compiled - for example, if it contains syntax or semantic errors or if dependent classes cannot be found. |
| ClassCastException | if the generated class is not assignable to all the optional types. |
|
inline |
Compile Java source in javaSource</name> and return the resulting class.
Thread safety: this method is thread safe if the javaSource is isolated to this thread.
| qualifiedClassName | The fully qualified class name. |
| javaSource | Complete java source, including a package statement and a class, interface, or annotation declaration. |
| types | zero or more Class objects representing classes or interfaces that the resulting class must be assignable (castable) to. |
| QoreJavaCompilerException | if the source cannot be compiled - for example, if it contains syntax or semantic errors or if dependent classes cannot be found. |
| ClassCastException | if the generated class is not assignable to all the optional types. |
|
inline |
Compile Java source in javaSource</name> and return the resulting class.
Thread safety: this method is thread safe if the javaSource and diagnosticsList are isolated to this thread.
| qualifiedClassName | The fully qualified class name. |
| javaSource | Complete java source, including a package statement and a class, interface, or annotation declaration. |
| diagnosticsList | Any diagnostics generated by compiling the source are added to this collector. |
| types | zero or more Class objects representing classes or interfaces that the resulting class must be assignable (castable) to. |
| QoreJavaCompilerException | if the source cannot be compiled - for example, if it contains syntax or semantic errors or if dependent classes cannot be found. |
| ClassCastException | if the generated class is not assignable to all the optional types. |
|
inline |
|
inline |
Load a class that was generated by this instance or accessible from its parent class loader. Use this method if you need access to additional classes compiled by compile(), for example if the primary class contained nested classes or additional non-public classes.
| qualifiedClassName | the name of the compiled class you wish to load |
| ClassNotFoundException | if no such class is found. |