KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > retouche > source > CompilationInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.retouche.source;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import org.netbeans.api.gsf.Error;
26 import org.netbeans.api.gsf.Index;
27 import org.netbeans.api.gsf.ParserResult;
28 import org.netbeans.api.gsf.PositionManager;
29 import org.netbeans.api.retouche.source.CompilationUnitTree;
30 import org.netbeans.api.retouche.source.ParserTaskImpl;
31 import org.netbeans.modules.gsf.Language;
32 import org.netbeans.modules.retouche.source.parsing.SourceFileObject;
33 import org.openide.ErrorManager;
34 import org.openide.cookies.EditorCookie;
35 import org.openide.filesystems.FileObject;
36 import org.openide.loaders.DataObject;
37 import org.netbeans.api.gsf.annotations.CheckForNull;
38 import org.netbeans.api.gsf.annotations.NonNull;
39 import org.netbeans.api.gsf.annotations.Nullable;
40
41
42 /**
43  * This file is originally from Retouche, the Java Support
44  * infrastructure in NetBeans. I have modified the file as little
45  * as possible to make merging Retouche fixes back as simple as
46  * possible.
47  *
48  * Assorted information about the Source.
49  *
50  *
51  * @author Petr Hrebejk, Tomas Zezula
52  */

53 public class CompilationInfo extends org.netbeans.api.gsf.CompilationInfo {
54     private Phase phase = Phase.MODIFIED;
55     private CompilationUnitTree compilationUnit;
56     private ParserTaskImpl javacTask;
57     final SourceFileObject jfo;
58     final Source javaSource;
59     boolean needsRestart;
60     private Language language;
61
62     CompilationInfo() throws IOException JavaDoc {
63         super(null);
64         this.javaSource = null;
65         this.jfo = null;
66         this.javacTask = null;
67     }
68
69     CompilationInfo(final Source javaSource, final FileObject fo, final ParserTaskImpl javacTask)
70         throws IOException JavaDoc {
71         super(fo);
72         assert javaSource != null;
73         this.javaSource = javaSource;
74
75         //this.jfo = fo != null ? javaSource.jfoProvider.createJavaFileObject(fo) : null;
76
if (fo.isValid() && !fo.isVirtual()) {
77             this.jfo = new SourceFileObject(fo, true);
78         } else {
79             this.jfo = null;
80         }
81
82         this.javacTask = javacTask;
83     }
84
85     // API of the class --------------------------------------------------------
86

87     /**
88      * Returns the current phase of the {@link Source}.
89      *
90      *
91      * @return {@link Source.Phase} the state which was reached by the {@link Source}.
92      */

93     public Phase getPhase() {
94         return this.phase;
95     }
96
97     /**
98      * Returns the javac tree representing the source file.
99      * @return {@link CompilationUnitTree} the compilation unit cantaining the top level classes contained in the
100      * java source file
101      */

102     @CheckForNull
103     public CompilationUnitTree getCompilationUnit() {
104         if (this.jfo == null) {
105             throw new IllegalStateException JavaDoc();
106         }
107
108         return this.compilationUnit;
109     }
110
111     /**
112      * Returns the content of the file represented by the {@link Source}.
113      *
114      *
115      * @return String the java source
116      */

117     public String JavaDoc getText() {
118         if (this.jfo == null) {
119             throw new IllegalStateException JavaDoc();
120         }
121
122         try {
123             return this.jfo.getCharContent(false).toString();
124         } catch (IOException JavaDoc ioe) {
125             //Should never happen
126
ErrorManager.getDefault().notify(ioe);
127
128             return null;
129         }
130     }
131
132     public Source getSource() {
133         return javaSource;
134     }
135
136     public ClasspathInfo getClasspathInfo() {
137         return javaSource.getClasspathInfo();
138     }
139     
140     @Override JavaDoc
141     public Index getIndex() {
142         return getClasspathInfo().getClassIndex();
143     }
144
145     void setPhase(final Phase phase) {
146         assert phase != null;
147         this.phase = phase;
148     }
149
150     void setCompilationUnit(final CompilationUnitTree compilationUnit) {
151         assert compilationUnit != null;
152         this.compilationUnit = compilationUnit;
153     }
154
155     synchronized ParserTaskImpl getParserTask() {
156         if (javacTask == null) {
157             javacTask =
158                 javaSource.createParserTask( /*new DiagnosticListenerImpl(errors),*/
159                     this);
160         }
161
162         return javacTask;
163     }
164
165     public Language getLanguage() {
166         return language;
167     }
168
169     public void setLanguage(Language language) {
170         this.language = language;
171     }
172 }
173
Popular Tags