KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > apt > pluggable > core > filer > IdeJavaSourceFileWriter


1 /*******************************************************************************
2  * Copyright (c) 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.apt.pluggable.core.filer;
14
15 import java.io.IOException JavaDoc;
16 import java.io.StringWriter JavaDoc;
17 import java.util.Collection JavaDoc;
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 /**
28  *
29  * @since 3.3
30  */

31 public class IdeJavaSourceFileWriter extends StringWriter JavaDoc {
32     
33     private final IdeProcessingEnvImpl _env;
34     private final CharSequence JavaDoc _name;
35     private final Collection JavaDoc<IFile> _parentFiles;
36     private boolean _closed = false;
37
38     public IdeJavaSourceFileWriter(IdeProcessingEnvImpl env, CharSequence JavaDoc name, Collection JavaDoc<IFile> parentFiles) {
39         _env = env;
40         _parentFiles = parentFiles;
41         _name = name;
42         _env.getAptProject().getGeneratedSourceFolderManager().getFolder();
43     }
44
45     /**
46      *
47      */

48     @Override JavaDoc
49     public void close() throws IOException JavaDoc {
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                 //TODO - implement reconcile
64
}
65             else if ( phase == Phase.BUILD) {
66                 // TODO: Remember empty-parent situation.
67
result = gfm.generateFileDuringBuild(
68                         _parentFiles, _name.toString(), this.toString(),
69                         _env.currentProcessorSupportsRTTG(), null /* progress monitor */ );
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"); //$NON-NLS-1$
77
}
78     }
79 }
80
Popular Tags