1 11 package org.eclipse.jdt.apt.core.internal.env; 12 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.jdt.apt.core.env.EclipseAnnotationProcessorEnvironment; 16 import org.eclipse.jdt.apt.core.env.Phase; 17 import org.eclipse.jdt.apt.core.internal.AptPlugin; 18 import org.eclipse.jdt.apt.core.internal.env.MessagerImpl.Severity; 19 import org.eclipse.jdt.core.ICompilationUnit; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.compiler.ReconcileContext; 22 import org.eclipse.jdt.core.dom.ASTRequestor; 23 import org.eclipse.jdt.core.dom.CompilationUnit; 24 import org.eclipse.jdt.core.dom.IBinding; 25 26 import com.sun.mirror.apt.Filer; 27 28 public class ReconcileEnv extends AbstractCompilationEnv implements EclipseAnnotationProcessorEnvironment{ 29 30 31 private final ICompilationUnit _workingCopy; 32 33 private final ReconcileContext _context; 34 35 40 static ReconcileEnv newEnv(ReconcileContext context) 41 { 42 final ICompilationUnit workingCopy = context.getWorkingCopy(); 43 IJavaProject javaProject = workingCopy.getJavaProject(); 44 final IFile file = (IFile)workingCopy.getResource(); 45 return new ReconcileEnv(context, workingCopy, file, javaProject); 46 } 47 48 private ReconcileEnv( 49 ReconcileContext context, 50 ICompilationUnit workingCopy, 51 IFile file, 52 IJavaProject javaProj) 53 { 54 super(EMPTY_AST_UNIT, file, javaProj, Phase.RECONCILE); 60 _context = context; 61 _workingCopy = workingCopy; 62 if (AptPlugin.DEBUG_COMPILATION_ENV) AptPlugin.trace( 63 "constructed " + this + " for " + _workingCopy.getElementName()); } 65 66 void addMessage( 67 IFile resource, 68 int start, 69 int end, 70 Severity severity, 71 String msg, 72 int line, 73 String [] arguments) 74 { 75 checkValid(); 76 77 if( resource == null ) 78 resource = getFile(); 79 80 assert resource != null : "don't know about the current resource"; 82 if( resource != null && !resource.equals( getFile() ) ) 85 return; 86 87 _problems.add(createProblem(resource, start, end, severity, msg, line, arguments)); 88 } 89 90 public CompilationUnit getASTFrom(final IFile file){ 91 if( _file.equals(file) ) 92 return _astRoot; 93 else 94 return null; 95 } 96 97 public void addTypeDependency(String fullyQualifiedTypeName) { 98 return; 100 } 101 102 public Filer getFiler(){ 103 return new ReconcileFilerImpl(this); 104 } 105 106 void openPipeline() { 107 _requestor = new CallbackRequestor(); 108 createASTs(_javaProject, new ICompilationUnit[]{_workingCopy}, _requestor); 109 } 110 111 114 @Override 115 public void close() { 116 _context.resetAST(); 121 super.close(); 122 } 123 124 class CallbackRequestor extends ASTRequestor { 125 @Override 126 public void acceptAST(ICompilationUnit source, CompilationUnit ast) { 127 _astRoot = ast; 129 } 130 131 @Override 132 public void acceptBinding(String bindingKey, IBinding binding) { 133 _callback.run(ReconcileEnv.this); 136 137 } 138 } 139 140 141 ICompilationUnit getCompilationUnit() { 142 return _workingCopy; 143 } 144 145 } 146 | Popular Tags |