Search in sources :

Example 6 with Processor

use of javax.annotation.processing.Processor in project androidannotations by androidannotations.

the class ProcessorTestHelper method compileFiles.

public CompileResult compileFiles(Collection<File> compilationUnits) {
    DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null)) {
        CompilationTask task = compiler.getTask(null, fileManager, diagnosticCollector, compilerOptions, null, fileManager.getJavaFileObjectsFromFiles(compilationUnits));
        List<Processor> processors = new ArrayList<>();
        for (Class<? extends Processor> processorClass : processorsClasses) {
            try {
                processors.add(processorClass.newInstance());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        task.setProcessors(processors);
        task.call();
    } catch (IOException e) {
    // we should always be able to close the manager
    }
    return new CompileResult(diagnosticCollector.getDiagnostics());
}
Also used : Processor(javax.annotation.processing.Processor) ArrayList(java.util.ArrayList) JavaCompiler(javax.tools.JavaCompiler) IOException(java.io.IOException) CompilationTask(javax.tools.JavaCompiler.CompilationTask) IOException(java.io.IOException) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) DiagnosticCollector(javax.tools.DiagnosticCollector)

Example 7 with Processor

use of javax.annotation.processing.Processor in project gradle by gradle.

the class IncrementalAnnotationProcessingCompileTask method setupProcessors.

private void setupProcessors() {
    processorClassloader = new URLClassLoader(DefaultClassPath.of(annotationProcessorPath).getAsURLArray());
    List<Processor> processors = new ArrayList<Processor>(processorDeclarations.size());
    for (AnnotationProcessorDeclaration declaredProcessor : processorDeclarations) {
        try {
            Class<?> processorClass = processorClassloader.loadClass(declaredProcessor.getClassName());
            Processor processor = (Processor) processorClass.newInstance();
            processor = decorateIfIncremental(processor, declaredProcessor.getType());
            processors.add(processor);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
    delegate.setProcessors(processors);
}
Also used : IsolatingProcessor(org.gradle.api.internal.tasks.compile.processing.IsolatingProcessor) Processor(javax.annotation.processing.Processor) AggregatingProcessor(org.gradle.api.internal.tasks.compile.processing.AggregatingProcessor) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Aggregations

Processor (javax.annotation.processing.Processor)7 ArrayList (java.util.ArrayList)3 PathClassLoader (com.google.devtools.j2objc.util.PathClassLoader)2 File (java.io.File)2 IOException (java.io.IOException)2 JavaFileObject (javax.tools.JavaFileObject)2 InputFile (com.google.devtools.j2objc.file.InputFile)1 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)1 ProcessingContext (com.google.devtools.j2objc.pipeline.ProcessingContext)1 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)1 PrintWriter (java.io.PrintWriter)1 URLClassLoader (java.net.URLClassLoader)1 Path (java.nio.file.Path)1 Locale (java.util.Locale)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DiagnosticCollector (javax.tools.DiagnosticCollector)1 JavaCompiler (javax.tools.JavaCompiler)1 CompilationTask (javax.tools.JavaCompiler.CompilationTask)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1