/** * 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 ); } }
/** * 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 ); } }
errors, _mfm, errorHandler, options, null, Collections.singletonList( fileObj.getFirst() ) ); initTypeProcessing( javacTask, Collections.singleton( fqn ) ); javacTask.call(); return _mfm.findCompiledFile( fileObj.getSecond() );