1 12 13 package org.eclipse.jdt.internal.compiler.apt.dispatch; 14 15 import java.io.IOException ; 16 import java.net.URI ; 17 import java.util.HashSet ; 18 19 import javax.annotation.processing.Filer; 20 import javax.annotation.processing.FilerException; 21 import javax.lang.model.element.Element; 22 import javax.tools.FileObject; 23 import javax.tools.JavaFileManager; 24 import javax.tools.JavaFileObject; 25 import javax.tools.StandardLocation; 26 import javax.tools.JavaFileManager.Location; 27 28 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 29 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 30 31 36 public class BatchFilerImpl implements Filer { 37 38 protected final BaseAnnotationProcessorManager _dispatchManager; 39 protected final BaseProcessingEnvImpl _env; 40 protected final JavaFileManager _fileManager; 41 protected final HashSet <URI > _createdFiles; 42 43 public BatchFilerImpl(BaseAnnotationProcessorManager dispatchManager, BatchProcessingEnvImpl env) 44 { 45 _dispatchManager = dispatchManager; 46 _fileManager = env._fileManager; 47 _env = env; 48 _createdFiles = new HashSet <URI >(); 49 } 50 51 public void addNewUnit(ICompilationUnit unit) { 52 _env.addNewUnit(unit); 53 } 54 55 public void addNewClassFile(ReferenceBinding binding) { 56 _env.addNewClassFile(binding); 57 } 58 59 62 @Override 63 public JavaFileObject createClassFile(CharSequence name, 64 Element... originatingElements) throws IOException 65 { 66 JavaFileObject jfo = _fileManager.getJavaFileForOutput( 68 StandardLocation.CLASS_OUTPUT, name.toString(), JavaFileObject.Kind.CLASS, null); 69 URI uri = jfo.toUri(); 70 if (_createdFiles.contains(uri)) { 71 throw new FilerException("Class file already created : " + name); } 73 74 _createdFiles.add(uri); 75 return new HookedJavaFileObject(jfo, jfo.getName(), this); 76 } 77 78 81 @Override 82 public FileObject createResource(Location location, CharSequence pkg, 83 CharSequence relativeName, Element... originatingElements) 84 throws IOException { 85 FileObject fo = _fileManager.getFileForOutput( 87 location, pkg.toString(), relativeName.toString(), null); 88 URI uri = fo.toUri(); 89 if (_createdFiles.contains(uri)) { 90 throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); } 92 93 _createdFiles.add(uri); 94 return fo; 95 } 96 97 100 @Override 101 public JavaFileObject createSourceFile(CharSequence name, 102 Element... originatingElements) throws IOException { 103 JavaFileObject jfo = _fileManager.getJavaFileForOutput( 105 StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); 106 URI uri = jfo.toUri(); 107 if (_createdFiles.contains(uri)) { 108 throw new FilerException("Source file already created : " + name); } 110 111 _createdFiles.add(uri); 112 return new HookedJavaFileObject(jfo, jfo.getName(), this); 114 } 115 116 119 @Override 120 public FileObject getResource(Location location, CharSequence pkg, 121 CharSequence relativeName) throws IOException { 122 FileObject fo = _fileManager.getFileForInput( 124 location, pkg.toString(), relativeName.toString()); 125 URI uri = fo.toUri(); 126 if (_createdFiles.contains(uri)) { 127 throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); } 129 130 _createdFiles.add(uri); 131 return fo; 132 } 133 134 } 135 | Popular Tags |