1 12 13 package org.eclipse.jdt.internal.apt.pluggable.core.dispatch; 14 15 import java.util.Iterator ; 16 import java.util.Map ; 17 import java.util.Map.Entry; 18 19 import javax.annotation.processing.Processor; 20 21 import org.eclipse.core.resources.IFile; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader; 24 import org.eclipse.jdt.apt.core.internal.IServiceFactory; 25 import org.eclipse.jdt.apt.core.internal.util.FactoryPath; 26 import org.eclipse.jdt.apt.core.internal.util.FactoryPath.Attributes; 27 import org.eclipse.jdt.core.IJavaProject; 28 import org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin; 29 import org.eclipse.jdt.internal.compiler.Compiler; 30 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager; 31 import org.eclipse.jdt.internal.compiler.apt.dispatch.ProcessorInfo; 32 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; 33 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 34 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 35 import org.eclipse.jdt.internal.core.CompilationUnitProblemFinder; 36 import org.eclipse.jdt.internal.core.builder.ICompilationUnitLocator; 37 38 42 public class IdeAnnotationProcessorManager extends BaseAnnotationProcessorManager { 43 44 private IJavaProject _javaProject; 45 private ICompilationUnitLocator _cuLocator; 46 private Map <IServiceFactory, FactoryPath.Attributes> _processorFactories; 47 private Iterator <Entry<IServiceFactory, Attributes>> _processorIter; 48 49 61 @Override 62 public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) { 63 _javaProject = (IJavaProject) javaProject; 64 _cuLocator = (ICompilationUnitLocator) compilationUnitLocator; 65 if (null != _processingEnv) { 66 throw new IllegalStateException ( 67 "Calling configure() more than once on an AnnotationProcessorManager is not supported"); } 69 if (compiler instanceof CompilationUnitProblemFinder) { 71 _processingEnv = new IdeReconcileProcessingEnvImpl(this, _javaProject, compiler); 72 } else { 73 _processingEnv = new IdeBuildProcessingEnvImpl(this, _javaProject, compiler); 74 } 75 if (Apt6Plugin.DEBUG) { 76 Apt6Plugin.trace("Java 6 annotation processor manager initialized for compiler " + 77 compiler.toString() + " on project " + _javaProject.getElementName()); 78 } 79 } 80 81 85 @Override 86 public ProcessorInfo discoverNextProcessor() { 87 if (_processorIter.hasNext()) { 89 Entry<IServiceFactory, Attributes> entry = _processorIter.next(); 90 Processor p; 91 try { 92 p = (Processor)entry.getKey().newInstance(); 93 p.init(_processingEnv); 94 ProcessorInfo pi = new ProcessorInfo(p); 95 if (Apt6Plugin.DEBUG) { 96 Apt6Plugin.trace("Discovered processor " + p.toString()); 97 } 98 _processors.add(pi); 99 return pi; 100 } catch (CoreException e) { 101 Apt6Plugin.log(e, "Unable to create instance of annotation processor " + entry.getKey()); } 103 } 104 return null; 105 } 106 107 @Override 108 public void reportProcessorException(Processor p, Exception e) { 109 Apt6Plugin.log(e, "Exception thrown by Java annotation processor " + p); } 111 112 116 public ICompilationUnit findCompilationUnit(IFile file) { 117 return _cuLocator.fromIFile(file); 118 } 119 120 127 @Override 128 public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) { 129 if (null == _processorFactories ) { 130 _processorFactories = AnnotationProcessorFactoryLoader.getLoader().getJava6FactoriesAndAttributesForProject(_javaProject); 131 _processorIter = _processorFactories.entrySet().iterator(); 132 } 133 if (!_processorFactories.isEmpty()) { 134 super.processAnnotations(units, referenceBindings, isLastRound); 135 } 136 } 137 138 } 139 | Popular Tags |