1 12 13 package org.eclipse.jdt.internal.apt.pluggable.core.dispatch; 14 15 import java.util.Collections ; 16 import java.util.HashMap ; 17 import java.util.Locale ; 18 import java.util.Map ; 19 20 import javax.lang.model.element.Element; 21 22 import org.eclipse.core.resources.IFile; 23 import org.eclipse.core.resources.IProject; 24 import org.eclipse.core.runtime.Path; 25 import org.eclipse.jdt.apt.core.env.Phase; 26 import org.eclipse.jdt.apt.core.internal.AptCompilationParticipant; 27 import org.eclipse.jdt.apt.core.internal.AptPlugin; 28 import org.eclipse.jdt.apt.core.internal.AptProject; 29 import org.eclipse.jdt.apt.core.internal.generatedfile.FileGenerationResult; 30 import org.eclipse.jdt.apt.core.util.AptConfig; 31 import org.eclipse.jdt.core.IJavaProject; 32 import org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl; 33 import org.eclipse.jdt.internal.compiler.Compiler; 34 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; 35 import org.eclipse.jdt.internal.compiler.apt.model.IElementInfo; 36 37 43 public abstract class IdeProcessingEnvImpl extends BaseProcessingEnvImpl { 44 45 private final IdeAnnotationProcessorManager _dispatchManager; 46 private final IJavaProject _javaProject; 47 protected final AptProject _aptProject; 48 49 public IdeProcessingEnvImpl(IdeAnnotationProcessorManager dispatchManager, 50 IJavaProject jproject, Compiler compiler) 51 { 52 _dispatchManager = dispatchManager; 53 _javaProject = jproject; 54 _compiler = compiler; 55 _aptProject = AptPlugin.getAptProject(jproject); 56 _filer = new IdeFilerImpl(_dispatchManager, this); 57 _messager = new IdeMessagerImpl(_dispatchManager, this); 58 } 59 60 63 @Override 64 public Locale getLocale() { 65 return Locale.getDefault(); 66 } 67 68 @Override 69 public Map <String , String > getOptions() { 70 if (null == _processorOptions) { 71 Map <String , String > allOptions = AptConfig.getProcessorOptions(_javaProject); 75 Map <String , String > procOptions = new HashMap <String , String >(); 76 for (Map.Entry <String , String > entry : allOptions.entrySet()) { 77 if (!entry.getKey().startsWith("-")) { procOptions.put(entry.getKey(), entry.getValue()); 79 } 80 } 81 procOptions.put("phase", getPhase().toString()); _processorOptions = Collections.unmodifiableMap(procOptions); 83 } 84 return _processorOptions; 85 } 86 87 public AptProject getAptProject() { 88 return _aptProject; 89 } 90 91 public IJavaProject getJavaProject() { 92 return _javaProject; 93 } 94 95 public IProject getProject() { 96 return _javaProject.getProject(); 97 } 98 99 102 public abstract Phase getPhase(); 103 104 115 public IFile getEnclosingIFile(Element elem) { 116 IElementInfo impl = (IElementInfo)elem; 118 String name = impl.getFileName(); 119 if (name == null) { 120 return null; 121 } 122 IFile file = _javaProject.getProject().getParent().getFile(new Path(name)); 124 return file; 125 } 126 127 131 public void addNewUnit(FileGenerationResult result) { 132 AptCompilationParticipant.getInstance().addJava6GeneratedFile(result.getFile()); 133 addNewUnit(_dispatchManager.findCompilationUnit(result.getFile())); 134 } 135 136 145 public void addNewResource(IFile file) { 146 AptCompilationParticipant.getInstance().addJava6GeneratedFile(file); 147 } 148 149 public boolean currentProcessorSupportsRTTG() 150 { 151 return false; 153 } 154 155 } 156 | Popular Tags |