KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > gsf > 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.gsf;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import javax.swing.text.Document JavaDoc;
26 import org.netbeans.api.gsf.Error;
27 import org.netbeans.api.gsf.Index;
28 import org.netbeans.api.gsf.OffsetRange;
29 import org.netbeans.api.gsf.Parser;
30 import org.netbeans.api.gsf.ParserResult;
31 import org.netbeans.api.gsf.PositionManager;
32 import org.openide.ErrorManager;
33 import org.openide.cookies.EditorCookie;
34 import org.openide.filesystems.FileObject;
35 import org.openide.loaders.DataObject;
36 import org.netbeans.api.gsf.annotations.CheckForNull;
37 import org.netbeans.api.gsf.annotations.NonNull;
38 import org.netbeans.api.gsf.annotations.Nullable;
39
40
41 /**
42  * Assorted information about the Source.
43  *
44  * @todo Pass around a context object here that is managed by the client.
45  * This would let all the multiple clients of a particular compilation result
46  * share some work, such as computing the position stack for a caret offset,
47  * and so on. (Each client checks if it's initialized, and if not, perform
48  * work and store it in the context.)
49  *
50  * @author Petr Hrebejk, Tomas Zezula, Tor Norbye
51  */

52 public abstract class CompilationInfo {
53     //private Source.Phase phase = Source.Phase.MODIFIED;
54
//private CompilationUnitTree compilationUnit;
55
private ParserResult parserResult;
56     private List JavaDoc<Error JavaDoc /*Diagnostic*/> errors;
57     private PositionManager positions;
58     private Parser parser;
59     private FileObject fo;
60
61     public CompilationInfo(final FileObject fo) throws IOException JavaDoc {
62         this.fo = fo;
63         this.errors = new ArrayList JavaDoc<Error JavaDoc /*Diagnostic*/>();
64     }
65
66     /**
67      * Returns the parsing result representing the parsed source file.
68      */

69     @CheckForNull
70     public ParserResult getParserResult() {
71         return this.parserResult;
72     }
73
74     /**
75      * Returns the content of the file.
76      *
77      *
78      * @return String the java source
79      */

80     public abstract String JavaDoc getText();
81
82     
83     /**
84      * Returns the index associated with this file
85      */

86     public abstract Index getIndex();
87     
88     /**
89      * Returns the errors in the file represented by the {@link Source}.
90      *
91      *
92      * @return an list of {@link Error}
93      */

94     public List JavaDoc<Error JavaDoc /*Diagnostic*/> getDiagnostics() {
95         ArrayList JavaDoc<Error JavaDoc /*Diagnostic*/> localErrors =
96             new ArrayList JavaDoc<Error JavaDoc /*Diagnostic*/>(errors.size());
97
98         for (Error JavaDoc /*Diagnostic*/ m : errors) {
99             // if (this.jfo == m.getSource())
100
if (this.fo == m.getFile()) {
101                 localErrors.add(m);
102             }
103         }
104
105         return localErrors;
106     }
107
108     public FileObject getFileObject() {
109         return fo;
110     }
111
112     @CheckForNull
113     public PositionManager getPositionManager() {
114         return positions;
115     }
116
117     public Document JavaDoc getDocument() throws IOException JavaDoc {
118         if (this.fo == null) {
119             return null;
120         }
121
122         DataObject od = DataObject.find(fo);
123         EditorCookie ec = (EditorCookie)od.getCookie(EditorCookie.class);
124
125         if (ec != null) {
126             return ec.getDocument();
127         } else {
128             return null;
129         }
130     }
131
132     public void setParserResult(@NonNull
133     final ParserResult parserResult) {
134         this.parserResult = parserResult;
135     }
136
137     public void addError(@NonNull
138     Error JavaDoc message) {
139         errors.add(message);
140     }
141
142     public void setPositionManager(PositionManager positions) {
143         this.positions = positions;
144     }
145
146     public Parser getParser() {
147         return parser;
148     }
149
150     public void setParser(Parser parser) {
151         this.parser = parser;
152     }
153 }
154
Popular Tags