1 11 12 package org.eclipse.jdt.apt.core.internal.env; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.io.PrintWriter ; 17 import java.io.StringWriter ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IPath; 21 import org.eclipse.jdt.apt.core.internal.AptPlugin; 22 import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedSourceFolderManager; 23 import org.eclipse.jdt.apt.core.internal.util.FileSystemUtil; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import com.sun.mirror.apt.Filer; 27 28 29 public abstract class FilerImpl implements Filer { 30 31 abstract protected AbstractCompilationEnv getEnv(); 32 33 44 public PrintWriter createSourceFile(String typeName) throws IOException 45 { 46 if (typeName == null) 47 throw new IllegalArgumentException ("Type name cannot be null"); if ("".equals(typeName)) throw new IllegalArgumentException ("Type name cannot be empty"); 51 getEnv().checkValid(); 52 53 PrintWriter pw; 54 try { 55 pw = new JavaSourceFilePrintWriter( typeName, new StringWriter (), getEnv() ); 56 } catch (CoreException e) { 57 IOException ioe = new IOException (); 58 ioe.initCause(e); 59 throw ioe; 60 } 61 return pw; 62 } 63 64 65 68 protected IPath getOutputFileForLocation( Filer.Location loc, String pkg, File relPath ) 69 throws IOException 70 { 71 GeneratedSourceFolderManager gsfm = getEnv().getAptProject().getGeneratedSourceFolderManager(); 72 IPath path = null; 73 if ( loc == Filer.Location.CLASS_TREE ) 74 { 75 try 76 { 77 path = gsfm.getBinaryOutputLocation(); 78 } 79 catch ( JavaModelException e ) 80 { 81 AptPlugin.log(e, "Failure getting the output file"); throw new IOException (); 83 } 84 } 85 else if ( loc == Filer.Location.SOURCE_TREE ) { 86 path = gsfm.getFolder().getProjectRelativePath(); 87 } 88 89 if( pkg != null ) 90 path = path.append(pkg.replace('.', File.separatorChar) ); 91 92 path = path.append(relPath.getPath() ); 93 94 IPath absolutePath = getEnv().getProject().getLocation().append(path); 96 File parentFile = absolutePath.toFile().getParentFile(); 97 FileSystemUtil.mkdirs( parentFile ); 98 99 return path; 100 } 101 102 103 } 104 | Popular Tags |