com.sun.tools.javac.api.BasicJavacTask Java Examples
The following examples show how to use
com.sun.tools.javac.api.BasicJavacTask.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicProxyFactory.java From manifold with Apache License 2.0 | 6 votes |
private static boolean hasCallHandlerFromExtension( Class rootClass ) { Boolean isCallHandler = ICALL_HANDLER_MAP.get( rootClass ); if( isCallHandler != null ) { return isCallHandler; } String fqn = rootClass.getCanonicalName(); BasicJavacTask javacTask = RuntimeManifoldHost.get().getJavaParser().getJavacTask(); Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, fqn ); Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> callHandlerSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, ICallHandler.class.getCanonicalName() ); if( Types.instance( javacTask.getContext() ).isAssignable( classSymbol.getFirst().asType(), callHandlerSymbol.getFirst().asType() ) ) { // Nominally implements ICallHandler isCallHandler = true; } else { // Structurally implements ICallHandler isCallHandler = hasCallMethod( javacTask, classSymbol.getFirst() ); } ICALL_HANDLER_MAP.put( rootClass, isCallHandler ); return isCallHandler; }
Example #2
Source File: TestClose.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #3
Source File: TestClose.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #4
Source File: TestClose.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #5
Source File: TestClose.java From hottub with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #6
Source File: TestClose.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #7
Source File: TestClose.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #8
Source File: ClassSymbols.java From manifold with Apache License 2.0 | 6 votes |
public SrcClass makeSrcClassStub( String fqn, JavaFileManager.Location location, DiagnosticListener<JavaFileObject> errorHandler ) { BasicJavacTask javacTask = /*location != null && JavacPlugin.instance() != null ? JavacPlugin.instance().getJavacTask() :*/ getJavacTask_PlainFileMgr(); Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> pair = getClassSymbol( javacTask, (JavaFileManager.Location)null /*location*/, fqn ); if( pair == null ) { //## todo: revisit this, but for now we need to return null to handle inner class extensions return null; // throw new IllegalStateException( "Failed to find class, '" + fqn + "'" ); } Symbol.ClassSymbol classSymbol = pair.getFirst(); if( classSymbol == null ) { // For the case where the class is generated from a type manifold esp. from a IExtensionClassProducer return makeSrcClassStubFromProducedClass( fqn, location, errorHandler ); } return SrcClassUtil.instance().makeStub( fqn, classSymbol, pair.getSecond(), getJavacTask_PlainFileMgr(), _module, location, errorHandler ); }
Example #9
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 6 votes |
private Symbol.MethodSymbol findConstructor( IModule module, String fqn, BasicJavacTask javacTask ) { manifold.rt.api.util.Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( module ).getClassSymbol( javacTask, fqn ); Symbol.ClassSymbol cs = classSymbol.getFirst(); Symbol.MethodSymbol ctor = null; for( Symbol sym: cs.getEnclosedElements() ) { if( sym instanceof Symbol.MethodSymbol && sym.flatName().toString().equals( "<init>" ) ) { if( ctor == null ) { ctor = (Symbol.MethodSymbol)sym; } else { ctor = mostAccessible( ctor, (Symbol.MethodSymbol)sym ); } if( Modifier.isPublic( (int)ctor.flags() ) ) { return ctor; } } } return ctor; }
Example #10
Source File: TestClose.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #11
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 6 votes |
private String genSuperCtorCall( IModule module, SrcClass srcClass, BasicJavacTask javacTask ) { String bodyStmt; SrcType superClass = srcClass.getSuperClass(); if( superClass == null ) { bodyStmt = ""; } else { Symbol.MethodSymbol superCtor = findConstructor( module, superClass.getFqName(), javacTask ); if( superCtor == null ) { bodyStmt = ""; } else { bodyStmt = genSuperCtorCall( superCtor ); } } return bodyStmt; }
Example #12
Source File: JavaParser.java From manifold with Apache License 2.0 | 6 votes |
/** * Compiles a collection of java source files, intended for use a command line compiler. */ public Collection<InMemoryClassJavaFileObject> compile( Collection<JavaFileObject> files, Iterable<String> options, DiagnosticCollector<JavaFileObject> errorHandler ) { init(); int check = _mfm.pushRuntimeMode(); try { StringWriter errors = new StringWriter(); BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, options, null, files ); initTypeProcessing( javacTask, files.stream().map( this::getTypeForFile ).collect( Collectors.toSet() ) ); javacTask.call(); return _mfm.getCompiledFiles(); } finally { _mfm.popRuntimeMode( check ); } }
Example #13
Source File: JavaParser.java From manifold with Apache License 2.0 | 6 votes |
/** * Compiles fresh, no caching. Intended for use with parser feedback tooling e.g., a Java editor. */ public InMemoryClassJavaFileObject compile( JavaFileObject jfo, String fqn, Iterable<String> options, DiagnosticCollector<JavaFileObject> errorHandler ) { init(); int check = _mfm.pushRuntimeMode(); try { StringWriter errors = new StringWriter(); BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, options, null, Collections.singletonList( jfo ) ); initTypeProcessing( javacTask, Collections.singleton( fqn ) ); javacTask.call(); return _mfm.findCompiledFile( fqn ); } finally { _mfm.popRuntimeMode( check ); } }
Example #14
Source File: TestClose.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void add(ProcessingEnvironment env, Runnable r) { // ensure this class in this class loader can access javac internals try { JavacTask task = JavacTask.instance(env); TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next(); // The TaskListener is an instanceof TestClose, but when using the // default class loaders. the taskListener uses a different // instance of Class<TestClose> than the anno processor. // If you try to evaluate // TestClose tc = (TestClose) (l). // you get the following somewhat confusing error: // java.lang.ClassCastException: TestClose cannot be cast to TestClose // The workaround is to access the fields of TestClose with reflection. Field f = l.getClass().getField("runnables"); @SuppressWarnings("unchecked") List<Runnable> runnables = (List<Runnable>) f.get(l); runnables.add(r); } catch (Throwable t) { t.printStackTrace(); } }
Example #15
Source File: JavacPlugin.java From manifold with Apache License 2.0 | 6 votes |
@Override public void init( JavacTask task, String... args ) { INSTANCE = this; // calling this here because the line below this references the type `BasicJavacTask`, which is in a jdk module needing exposure NecessaryEvilUtil.bypassJava9Security(); _javacTask = (BasicJavacTask)task; JavacProcessingEnvironment jpe = JavacProcessingEnvironment.instance( _javacTask.getContext() ); IS_JAVA_8 = jpe.getSourceVersion() == SourceVersion.RELEASE_8; processArgs( jpe, args ); _host = new JavacManifoldHost(); _fileFragmentResources = new ArrayList<>(); _javaSourcePath = Collections.emptySet(); assignBootclasspath(); hijackJavacFileManager(); task.addTaskListener( this ); }
Example #16
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
@Override public void visitAssignop( JCTree.JCAssignOp tree ) { super.visitAssignop( tree ); if( _tp.isGenerate() && !shouldProcessForGeneration() ) { // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method return; } if( isJailbreakReceiver( tree ) ) { // +=, -=, etc. operators not supported with jailbreak, only direct assignment _tp.report( tree, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_COMPOUND_OP_NOT_ALLOWED_REFLECTION.get() ); Types types = Types.instance( ((BasicJavacTask)_tp.getJavacTask()).getContext() ); tree.type = types.createErrorType( tree.type ); result = tree; } else { result = tree; } }
Example #17
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private JCExpression makeClassExpr( JCTree tree, Type type ) { BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); Types types = Types.instance( javacTask.getContext() ); type = types.erasure( type ); JCExpression classExpr; if( isPrimitiveOrPrimitiveArray( type ) || (JreUtil.isJava8() && type.tsym.getModifiers().contains( javax.lang.model.element.Modifier.PUBLIC )) ) { // class is publicly accessible, assume we can use class literal classExpr = _tp.getTreeMaker().ClassLiteral( type ); classExpr.pos = tree.pos; } else { // generate `ReflectUtil.type( typeName )` classExpr = classForNameCall( type, tree ); } return classExpr; }
Example #18
Source File: ClassSymbols.java From manifold with Apache License 2.0 | 5 votes |
private Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( Context ctx, Object moduleCtx, String fqn ) { Symbol.ClassSymbol typeElement = IDynamicJdk.instance().getTypeElement( ctx, moduleCtx, fqn ); if( typeElement == null ) { // For the case where the class is generated from a type manifold esp. from a IExtensionClassProducer return getClassSymbolForProducedClass( fqn, new BasicJavacTask[1] ); //## want this instead, but the typeElement is not complete in this case, investigate this // if( JavacPlugin.instance() != null ) // { // typeElement = IDynamicJdk.instance().getTypeElement( JavacPlugin.instance().getContext(), moduleCtx, fqn ); // typeElement.complete(); // } } JavacTrees trees = JavacTrees.instance( ctx ); TreePath path = trees.getPath( typeElement ); if( path != null ) { return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() ); } else { // TreePath is only applicable to a source file; // if fqn is not a source file, there is no compilation unit available return new Pair<>( typeElement, null ); } }
Example #19
Source File: AbstractCodingRulesAnalyzer.java From hottub with GNU General Public License v2.0 | 5 votes |
public void init(JavacTask task, String... args) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); trees = Trees.instance(task); messages = new Messages(); task.addTaskListener(new PostAnalyzeTaskListener()); }
Example #20
Source File: ClassSymbols.java From manifold with Apache License 2.0 | 5 votes |
private SrcClass makeSrcClassStubFromProducedClass( String fqn, JavaFileManager.Location location, DiagnosticListener<JavaFileObject> errorHandler ) { BasicJavacTask[] task = new BasicJavacTask[1]; Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> pair = getClassSymbolForProducedClass( fqn, task ); if( pair == null ) { throw new NullPointerException( "Could not find ClassSymbol for: " + fqn ); } Symbol.ClassSymbol classSymbol = pair.getFirst(); return SrcClassUtil.instance().makeStub( fqn, classSymbol, pair.getSecond(), task[0], _module, location, errorHandler ); }
Example #21
Source File: DocEnv.java From hottub with GNU General Public License v2.0 | 5 votes |
void initDoclint(Collection<String> opts, Collection<String> customTagNames) { ArrayList<String> doclintOpts = new ArrayList<String>(); for (String opt: opts) { doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt); } if (doclintOpts.isEmpty()) { doclintOpts.add(DocLint.XMSGS_OPTION); } else if (doclintOpts.size() == 1 && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) { return; } String sep = ""; StringBuilder customTags = new StringBuilder(); for (String customTag : customTagNames) { customTags.append(sep); customTags.append(customTag); sep = DocLint.TAGS_SEPARATOR; } doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); JavacTask t = BasicJavacTask.instance(context); doclint = new DocLint(); // standard doclet normally generates H1, H2 doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); }
Example #22
Source File: AbstractCodingRulesAnalyzer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void init(JavacTask task, String... args) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); trees = Trees.instance(task); messages = new Messages(); task.addTaskListener(new PostAnalyzeTaskListener()); }
Example #23
Source File: JavaParser.java From manifold with Apache License 2.0 | 5 votes |
public boolean parseText( String src, List<CompilationUnitTree> trees, Consumer<SourcePositions> sourcePositions, Consumer<DocTrees> docTrees, DiagnosticCollector<JavaFileObject> errorHandler ) { init(); ArrayList<JavaFileObject> javaStringObjects = new ArrayList<>(); javaStringObjects.add( new StringJavaFileObject( "sample", src ) ); StringWriter errors = new StringWriter(); BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, Collections.singletonList( "-proc:none" ), null, javaStringObjects ); try { initTypeProcessing( javacTask, Collections.singleton( "sample" ) ); Iterable<? extends CompilationUnitTree> iterable = javacTask.parse(); if( errors.getBuffer().length() > 0 ) { System.err.println( errors.getBuffer() ); } for( CompilationUnitTree x : iterable ) { trees.add( x ); } if( sourcePositions != null ) { sourcePositions.accept( Trees.instance( javacTask ).getSourcePositions() ); } if( docTrees != null ) { docTrees.accept( DocTrees.instance( javacTask ) ); } return true; } catch( Exception e ) { return false; } }
Example #24
Source File: JavaParser.java From manifold with Apache License 2.0 | 5 votes |
public boolean parseType( String fqn, List<CompilationUnitTree> trees, DiagnosticCollector<JavaFileObject> errorHandler ) { init(); Pair<JavaFileObject, String> pair = findJavaSource( fqn, errorHandler ); if( pair == null ) { return false; } StringWriter errors = new StringWriter(); BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, Collections.singletonList( "-proc:none" ), null, Collections.singletonList( pair.getFirst() ) ); try { initTypeProcessing( javacTask, Collections.singleton( fqn ) ); Iterable<? extends CompilationUnitTree> iterable = javacTask.parse(); for( CompilationUnitTree x : iterable ) { trees.add( x ); } return true; } catch( Exception e ) { return false; } }
Example #25
Source File: CompiledTypeProcessor.java From manifold with Apache License 2.0 | 5 votes |
CompiledTypeProcessor( IManifoldHost host, BasicJavacTask javacTask ) { _host = host; _javacTask = javacTask; javacTask.addTaskListener( this ); _issueReporter = new IssueReporter<>( _javacTask::getContext ); _typesToProcess = new HashMap<>(); _innerClassForGeneration = new HashMap<>(); _parents = new ParentMap(); }
Example #26
Source File: AbstractCodingRulesAnalyzer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void init(JavacTask task, String... args) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); trees = Trees.instance(task); messages = new Messages(); task.addTaskListener(new PostAnalyzeTaskListener()); }
Example #27
Source File: StructuralTypeProxyGenerator.java From manifold with Apache License 2.0 | 5 votes |
private Symbol.ClassSymbol getRootClassSymbol() { if( _rootClassSymbol == null ) { ClassSymbols classSymbols = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ); BasicJavacTask javacTask = classSymbols.getJavacTask_PlainFileMgr(); _rootClassSymbol = classSymbols.getClassSymbol( javacTask, _rootClass.getCanonicalName() ).getFirst(); } return _rootClassSymbol; }
Example #28
Source File: DocEnv.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void initDoclint(Collection<String> opts, Collection<String> customTagNames) { ArrayList<String> doclintOpts = new ArrayList<String>(); for (String opt: opts) { doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt); } if (doclintOpts.isEmpty()) { doclintOpts.add(DocLint.XMSGS_OPTION); } else if (doclintOpts.size() == 1 && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) { return; } String sep = ""; StringBuilder customTags = new StringBuilder(); for (String customTag : customTagNames) { customTags.append(sep); customTags.append(customTag); sep = DocLint.TAGS_SEPARATOR; } doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); JavacTask t = BasicJavacTask.instance(context); doclint = new DocLint(); // standard doclet normally generates H1, H2 doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); }
Example #29
Source File: AbstractCodingRulesAnalyzer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void init(JavacTask task, String... args) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); trees = Trees.instance(task); messages = new Messages(); task.addTaskListener(new PostAnalyzeTaskListener()); }
Example #30
Source File: JavaParser.java From manifold with Apache License 2.0 | 5 votes |
/** * Compiles specified Java class name. Maintains cache between calls to this method, therefore subsequent calls to this * method will consult the cache and return the previously compiled class if cached. */ public InMemoryClassJavaFileObject compile( String fqn, Iterable<String> options, DiagnosticCollector<JavaFileObject> errorHandler ) { init(); InMemoryClassJavaFileObject compiledClass = _mfm.findCompiledFile( fqn ); if( compiledClass != null ) { return compiledClass; } Pair<JavaFileObject, String> fileObj = findJavaSource( fqn, errorHandler ); if( fileObj == null ) { return null; } int check = _mfm.pushRuntimeMode(); try { StringWriter errors = new StringWriter(); BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, options, null, Collections.singletonList( fileObj.getFirst() ) ); initTypeProcessing( javacTask, Collections.singleton( fqn ) ); javacTask.call(); return _mfm.findCompiledFile( fileObj.getSecond() ); } finally { _mfm.popRuntimeMode( check ); } }