Search in sources :

Example 1 with CompileExprException

use of com.alibaba.otter.shared.common.utils.compile.exception.CompileExprException in project otter by alibaba.

the class JdkCompiler method compile.

public Class compile(JavaSource javaSource) {
    try {
        final DiagnosticCollector<JavaFileObject> errs = new DiagnosticCollector<JavaFileObject>();
        JdkCompileTask compileTask = new JdkCompileTask(new JdkCompilerClassLoader(this.getClass().getClassLoader()), options);
        String fullName = javaSource.getPackageName() + "." + javaSource.getClassName();
        Class newClass = compileTask.compile(fullName, javaSource.getSource(), errs);
        return newClass;
    } catch (JdkCompileException ex) {
        DiagnosticCollector<JavaFileObject> diagnostics = ex.getDiagnostics();
        throw new CompileExprException("compile error, source : \n" + javaSource + ", " + diagnostics.getDiagnostics(), ex);
    } catch (Exception ex) {
        throw new CompileExprException("compile error, source : \n" + javaSource, ex);
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) JdkCompilerClassLoader(com.alibaba.otter.shared.common.utils.compile.model.JdkCompilerClassLoader) DiagnosticCollector(javax.tools.DiagnosticCollector) CompileExprException(com.alibaba.otter.shared.common.utils.compile.exception.CompileExprException) JdkCompileException(com.alibaba.otter.shared.common.utils.compile.exception.JdkCompileException) CompileExprException(com.alibaba.otter.shared.common.utils.compile.exception.CompileExprException) JdkCompileException(com.alibaba.otter.shared.common.utils.compile.exception.JdkCompileException)

Aggregations

CompileExprException (com.alibaba.otter.shared.common.utils.compile.exception.CompileExprException)1 JdkCompileException (com.alibaba.otter.shared.common.utils.compile.exception.JdkCompileException)1 JdkCompilerClassLoader (com.alibaba.otter.shared.common.utils.compile.model.JdkCompilerClassLoader)1 DiagnosticCollector (javax.tools.DiagnosticCollector)1 JavaFileObject (javax.tools.JavaFileObject)1