1 12 13 package org.eclipse.jdt.internal.apt.pluggable.core.filer; 14 15 import java.io.IOException ; 16 import java.io.StringWriter ; 17 import java.util.Collection ; 18 19 import org.eclipse.core.resources.IFile; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.jdt.apt.core.env.Phase; 22 import org.eclipse.jdt.apt.core.internal.generatedfile.FileGenerationResult; 23 import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedFileManager; 24 import org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin; 25 import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl; 26 27 31 public class IdeJavaSourceFileWriter extends StringWriter { 32 33 private final IdeProcessingEnvImpl _env; 34 private final CharSequence _name; 35 private final Collection <IFile> _parentFiles; 36 private boolean _closed = false; 37 38 public IdeJavaSourceFileWriter(IdeProcessingEnvImpl env, CharSequence name, Collection <IFile> parentFiles) { 39 _env = env; 40 _parentFiles = parentFiles; 41 _name = name; 42 _env.getAptProject().getGeneratedSourceFolderManager().getFolder(); 43 } 44 45 48 @Override 49 public void close() throws IOException { 50 synchronized(this) { 51 if (_closed) { 52 return; 53 } 54 _closed = true; 55 } 56 try { 57 GeneratedFileManager gfm = _env.getAptProject().getGeneratedFileManager(); 58 Phase phase = _env.getPhase(); 59 60 FileGenerationResult result = null; 61 if ( phase == Phase.RECONCILE ) 62 { 63 } 65 else if ( phase == Phase.BUILD) { 66 result = gfm.generateFileDuringBuild( 68 _parentFiles, _name.toString(), this.toString(), 69 _env.currentProcessorSupportsRTTG(), null ); 70 } 71 if (result != null) { 72 _env.addNewUnit(result); 73 } 74 } 75 catch (CoreException ce) { 76 Apt6Plugin.log(ce, "Unable to generate type when JavaSourceFilePrintWriter was closed"); } 78 } 79 } 80 | Popular Tags |