KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.netbeans.api.retouche.source;
21
22 import java.util.Map JavaDoc;
23 import org.netbeans.api.gsf.OffsetRange;
24 import org.netbeans.api.gsf.Parser;
25 import org.netbeans.api.gsf.ParserResult;
26 import org.netbeans.api.gsf.ColoringAttributes;
27 import org.netbeans.api.retouche.source.CompilationUnitTree;
28 import org.netbeans.api.retouche.source.ParserTaskImpl;
29 import java.io.IOException JavaDoc;
30 import java.util.List JavaDoc;
31 import javax.swing.text.Document JavaDoc;
32 import org.netbeans.api.gsf.Error;
33 import org.netbeans.api.gsf.Index;
34 import org.netbeans.api.gsf.PositionManager;
35 import org.netbeans.api.retouche.source.Phase;
36 import org.netbeans.modules.gsf.Language;
37 import org.openide.filesystems.FileObject;
38 import static org.netbeans.api.retouche.source.Phase.*;
39
40 /**
41  * This file is originally from Retouche, the Java Support
42  * infrastructure in NetBeans. I have modified the file as little
43  * as possible to make merging Retouche fixes back as simple as
44  * possible.
45  *
46  * Class for explicit invocation of compilation phases on a source file.
47  * The implementation delegates to the {@link CompilationInfo} to get the data,
48  * the access to {@link CompilationInfo} is not synchronized, so the class isn't
49  * reentrant.
50  *
51  * XXX: make toPhase automatic in getTrees(), Trees.getElement, etc....
52  * @author Petr Hrebejk, Tomas Zezula
53  */

54 public class CompilationController extends CompilationInfo {
55     
56     //Not private for unit tests
57
/*private*/final CompilationInfo delegate;
58     
59     CompilationController(final CompilationInfo delegate) throws IOException JavaDoc {
60         super();
61         assert delegate != null;
62         this.delegate = delegate;
63     }
64         
65     // API of the class --------------------------------------------------------
66

67     /**
68      * Moves the state to required phase. If given state was already reached
69      * the state is not changed. The method will throw exception if a state is
70      * illegal required. Acceptable parameters for thid method are <BR>
71      * <LI>{@link org.netbeans.api.retouche.source.Source.Phase.PARSED}
72      * <LI>{@link org.netbeans.api.retouche.source.Source.Phase.ELEMENTS_RESOLVED}
73      * <LI>{@link org.netbeans.api.retouche.source.Source.Phase.RESOLVED}
74      * <LI>{@link org.netbeans.api.retouche.source.Source.Phase.UP_TO_DATE}
75      *
76      * @param phase The required phase
77      * @return the reached state
78      * @throws IllegalArgumentException in case that given state can not be
79      * reached using this method
80      * @throws IOException when the file cannot be red
81      */

82     public Phase toPhase(Phase phase ) throws IOException JavaDoc {
83         if (phase == MODIFIED) {
84             throw new IllegalArgumentException JavaDoc( "Wrong phase" + phase );
85         }
86         if (delegate.jfo == null) {
87             Phase currentPhase = delegate.getPhase();
88             if (currentPhase.compareTo(phase)<0) {
89                 delegate.setPhase(phase);
90             }
91             return delegate.getPhase();
92         }
93         else {
94             Phase currentPhase = Source.moveToPhase(phase, this.delegate,false);
95             return currentPhase.compareTo (phase) < 0 ? currentPhase : phase;
96         }
97     }
98
99     /**
100      * Returns the current phase of the {@link Source}.
101      *
102      *
103      * @return {@link Source.Phase} the state which was reached by the {@link Source}.
104      */

105     @Override JavaDoc
106     public Phase getPhase() {
107         return this.delegate.getPhase();
108     }
109         
110     /**
111      * Returns the javac tree representing the source file.
112      *
113      * @return {@link CompilationUnitTree} the compilation unit cantaining the top level classes contained in the
114      * java source file
115      */

116     @Override JavaDoc
117     public CompilationUnitTree getCompilationUnit() {
118         return this.delegate.getCompilationUnit();
119     }
120
121     @Override JavaDoc
122     public ParserResult getParserResult() {
123         return this.delegate.getParserResult();
124     }
125     /**
126      * Returns the content of the file represented by the {@link Source}.
127      *
128      *
129      * @return String the java source
130      */

131     @Override JavaDoc
132     public String JavaDoc getText() {
133         return this.delegate.getText();
134     }
135
136     /**@inheritDoc*/
137 // @Override
138
// public TokenHierarchy getTokenHiearchy() {
139
// return this.delegate.getTokenHiearchy();
140
// }
141

142     /**
143      * Returns the errors in the file represented by the {@link Source}.
144      *
145      *
146      * @return an list of {@link Diagnostic}
147      */

148     @Override JavaDoc
149     public List JavaDoc<Error JavaDoc/*Diagnostic*/> getDiagnostics() {
150         return this.delegate.getDiagnostics();
151     }
152
153 // @Override
154
// public Trees getTrees() {
155
// return this.delegate.getTrees();
156
// }
157
//
158
// @Override
159
// public Types getTypes() {
160
// return this.delegate.getTypes();
161
// }
162
//
163
// @Override
164
// public Elements getElements() {
165
// return this.delegate.getElements();
166
// }
167

168     @Override JavaDoc
169     public Source getSource() {
170         return this.delegate.getSource();
171     }
172
173     @Override JavaDoc
174     public ClasspathInfo getClasspathInfo() {
175         return this.delegate.getClasspathInfo();
176     }
177
178     @Override JavaDoc
179     public FileObject getFileObject() {
180         return this.delegate.getFileObject();
181     }
182
183     @Override JavaDoc
184     public PositionManager getPositionManager() {
185         return this.delegate.getPositionManager();
186     }
187
188     @Override JavaDoc
189     public Parser getParser() {
190         return this.delegate.getParser();
191     }
192
193     @Override JavaDoc
194     public Document JavaDoc getDocument() throws IOException JavaDoc {
195         return this.delegate.getDocument();
196     }
197         
198     // Package private methods -------------------------------------------------
199

200     @Override JavaDoc
201     void setPhase(final Phase phase) {
202         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
203
}
204
205     @Override JavaDoc
206     void setCompilationUnit(final CompilationUnitTree compilationUnit) {
207         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
208
}
209
210     @Override JavaDoc
211     public void setParserResult(final ParserResult parserResult) {
212         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
213
}
214
215     @Override JavaDoc
216     public void setPositionManager(final PositionManager positions) {
217         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
218
}
219
220     @Override JavaDoc
221     public void setParser(final Parser parser) {
222         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
223
}
224
225     @Override JavaDoc
226     public void setLanguage(final Language language) {
227         throw new UnsupportedOperationException JavaDoc ("CompilationController supports only read interface"); //NOI18N
228
}
229
230     @Override JavaDoc
231     public Language getLanguage() {
232         return this.delegate.getLanguage();
233     }
234
235     @Override JavaDoc
236     ParserTaskImpl getParserTask() {
237         return this.delegate.getParserTask();
238     }
239     
240     @Override JavaDoc
241     public Index getIndex() {
242         return this.delegate.getIndex();
243     }
244 }
245
Popular Tags