use of com.google.devtools.j2objc.util.PathClassLoader in project j2objc by google.
the class AnnotationPreProcessor method hasAnnotationProcessors.
/**
* Check whether any javax.annotation.processing.Processor services are defined on
* the declared classpath. This is checked here to avoid batch compiling sources
* in case any might have annotations that should be processed.
*/
private boolean hasAnnotationProcessors() {
PathClassLoader loader = new PathClassLoader(options.fileUtil().getClassPathEntries());
loader.addPaths(options.getProcessorPathEntries());
ServiceLoader<Processor> serviceLoader = ServiceLoader.load(Processor.class, loader);
Iterator<Processor> iterator = serviceLoader.iterator();
return iterator.hasNext();
}
use of com.google.devtools.j2objc.util.PathClassLoader in project j2objc by google.
the class JavacParser method processAnnotations.
@Override
public ProcessingResult processAnnotations(Iterable<String> fileArgs, List<ProcessingContext> inputs) {
final List<ProcessingContext> generatedInputs = Lists.newArrayList();
PathClassLoader loader = new PathClassLoader(options.fileUtil().getClassPathEntries());
loader.addPaths(options.getProcessorPathEntries());
Iterator<Processor> serviceIterator = ServiceLoader.load(Processor.class, loader).iterator();
if (serviceIterator.hasNext() || options.getProcessors() != null) {
List<File> inputFiles = new ArrayList<>();
for (ProcessingContext input : inputs) {
inputFiles.add(new File(input.getFile().getAbsolutePath()));
}
try {
JavacEnvironment env = createEnvironment(inputFiles, null, true);
env.task().parse();
env.task().analyze();
processDiagnostics(env.diagnostics());
// The source output directory is created and set in createEnvironment().
File sourceOutputDirectory = env.fileManager().getLocation(StandardLocation.SOURCE_OUTPUT).iterator().next();
collectGeneratedInputs(sourceOutputDirectory, "", generatedInputs);
return new JavacProcessingResult(generatedInputs, sourceOutputDirectory);
} catch (IOException e) {
ErrorUtil.fatalError(e, "javac file manager error");
}
}
// No annotation processors on classpath, or processing errors reported.
return new JavacProcessingResult(generatedInputs, null);
}
Aggregations