Lines 10-28
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.compiler; |
11 |
package org.eclipse.jdt.internal.compiler; |
12 |
|
12 |
|
13 |
import org.eclipse.jdt.core.compiler.*; |
13 |
import java.io.PrintWriter; |
14 |
import org.eclipse.jdt.internal.compiler.env.*; |
14 |
import java.io.StringWriter; |
15 |
import org.eclipse.jdt.internal.compiler.impl.*; |
15 |
import java.util.Map; |
16 |
import org.eclipse.jdt.internal.compiler.ast.*; |
16 |
|
17 |
import org.eclipse.jdt.internal.compiler.lookup.*; |
17 |
import org.eclipse.jdt.core.compiler.CategorizedProblem; |
18 |
import org.eclipse.jdt.internal.compiler.parser.*; |
18 |
import org.eclipse.jdt.core.compiler.CompilationProgress; |
19 |
import org.eclipse.jdt.internal.compiler.problem.*; |
19 |
import org.eclipse.jdt.core.compiler.IProblem; |
20 |
import org.eclipse.jdt.internal.compiler.util.*; |
20 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
21 |
|
21 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
22 |
import java.io.*; |
22 |
import org.eclipse.jdt.internal.compiler.ast.ImportReference; |
23 |
import java.util.*; |
23 |
import org.eclipse.jdt.internal.compiler.env.AccessRestriction; |
|
|
24 |
import org.eclipse.jdt.internal.compiler.env.IBinaryType; |
25 |
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
26 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
27 |
import org.eclipse.jdt.internal.compiler.env.ISourceType; |
28 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
29 |
import org.eclipse.jdt.internal.compiler.impl.CompilerStats; |
30 |
import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor; |
31 |
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; |
32 |
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; |
33 |
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; |
34 |
import org.eclipse.jdt.internal.compiler.parser.Parser; |
35 |
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; |
36 |
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; |
37 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
38 |
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
39 |
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; |
40 |
import org.eclipse.jdt.internal.compiler.util.Messages; |
24 |
|
41 |
|
25 |
public class Compiler implements ITypeRequestor, ProblemSeverities { |
42 |
public class Compiler implements ITypeRequestor, ProblemSeverities { |
|
|
43 |
|
26 |
public Parser parser; |
44 |
public Parser parser; |
27 |
public ICompilerRequestor requestor; |
45 |
public ICompilerRequestor requestor; |
28 |
public CompilerOptions options; |
46 |
public CompilerOptions options; |
Lines 58-911
Link Here
|
58 |
*/ |
76 |
*/ |
59 |
public static IDebugRequestor DebugRequestor = null; |
77 |
public static IDebugRequestor DebugRequestor = null; |
60 |
|
78 |
|
61 |
/** |
79 |
/** |
62 |
* Answer a new compiler using the given name environment and compiler options. |
80 |
* Answer a new compiler using the given name environment and compiler options. |
63 |
* The environment and options will be in effect for the lifetime of the compiler. |
81 |
* The environment and options will be in effect for the lifetime of the compiler. |
64 |
* When the compiler is run, compilation results are sent to the given requestor. |
82 |
* When the compiler is run, compilation results are sent to the given requestor. |
65 |
* |
83 |
* |
66 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
84 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
67 |
* Environment used by the compiler in order to resolve type and package |
85 |
* Environment used by the compiler in order to resolve type and package |
68 |
* names. The name environment implements the actual connection of the compiler |
86 |
* names. The name environment implements the actual connection of the compiler |
69 |
* to the outside world (e.g. in batch mode the name environment is performing |
87 |
* to the outside world (e.g. in batch mode the name environment is performing |
70 |
* pure file accesses, reuse previous build state or connection to repositories). |
88 |
* pure file accesses, reuse previous build state or connection to repositories). |
71 |
* Note: the name environment is responsible for implementing the actual classpath |
89 |
* Note: the name environment is responsible for implementing the actual classpath |
72 |
* rules. |
90 |
* rules. |
73 |
* |
91 |
* |
74 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
92 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
75 |
* Configurable part for problem handling, allowing the compiler client to |
93 |
* Configurable part for problem handling, allowing the compiler client to |
76 |
* specify the rules for handling problems (stop on first error or accumulate |
94 |
* specify the rules for handling problems (stop on first error or accumulate |
77 |
* them all) and at the same time perform some actions such as opening a dialog |
95 |
* them all) and at the same time perform some actions such as opening a dialog |
78 |
* in UI when compiling interactively. |
96 |
* in UI when compiling interactively. |
79 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
97 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
80 |
* |
98 |
* |
81 |
* @param settings java.util.Map |
99 |
* @param settings java.util.Map |
82 |
* The settings that control the compiler behavior. |
100 |
* The settings that control the compiler behavior. |
83 |
* |
101 |
* |
84 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
102 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
85 |
* Component which will receive and persist all compilation results and is intended |
103 |
* Component which will receive and persist all compilation results and is intended |
86 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
104 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
87 |
* responsible for writing out the actual .class files to the file system. |
105 |
* responsible for writing out the actual .class files to the file system. |
88 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
106 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
89 |
* |
107 |
* |
90 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
108 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
91 |
* Factory used inside the compiler to create problem descriptors. It allows the |
109 |
* Factory used inside the compiler to create problem descriptors. It allows the |
92 |
* compiler client to supply its own representation of compilation problems in |
110 |
* compiler client to supply its own representation of compilation problems in |
93 |
* order to avoid object conversions. Note that the factory is not supposed |
111 |
* order to avoid object conversions. Note that the factory is not supposed |
94 |
* to accumulate the created problems, the compiler will gather them all and hand |
112 |
* to accumulate the created problems, the compiler will gather them all and hand |
95 |
* them back as part of the compilation unit result. |
113 |
* them back as part of the compilation unit result. |
96 |
* |
114 |
* |
97 |
* @deprecated this constructor is kept to preserve 3.1 and 3.2M4 compatibility |
115 |
* @deprecated this constructor is kept to preserve 3.1 and 3.2M4 compatibility |
98 |
*/ |
116 |
*/ |
99 |
public Compiler( |
117 |
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, Map settings, ICompilerRequestor requestor, IProblemFactory problemFactory) { |
100 |
INameEnvironment environment, |
118 |
this(environment, policy, new CompilerOptions(settings), requestor, problemFactory, null /* printwriter */, null /* progress */); |
101 |
IErrorHandlingPolicy policy, |
119 |
} |
102 |
Map settings, |
|
|
103 |
final ICompilerRequestor requestor, |
104 |
IProblemFactory problemFactory) { |
105 |
this(environment, policy, new CompilerOptions(settings), requestor, problemFactory, null /* printwriter */, null /* progress */); |
106 |
} |
107 |
|
108 |
/** |
109 |
* Answer a new compiler using the given name environment and compiler options. |
110 |
* The environment and options will be in effect for the lifetime of the compiler. |
111 |
* When the compiler is run, compilation results are sent to the given requestor. |
112 |
* |
113 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
114 |
* Environment used by the compiler in order to resolve type and package |
115 |
* names. The name environment implements the actual connection of the compiler |
116 |
* to the outside world (e.g. in batch mode the name environment is performing |
117 |
* pure file accesses, reuse previous build state or connection to repositories). |
118 |
* Note: the name environment is responsible for implementing the actual classpath |
119 |
* rules. |
120 |
* |
121 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
122 |
* Configurable part for problem handling, allowing the compiler client to |
123 |
* specify the rules for handling problems (stop on first error or accumulate |
124 |
* them all) and at the same time perform some actions such as opening a dialog |
125 |
* in UI when compiling interactively. |
126 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
127 |
* |
128 |
* @param settings java.util.Map |
129 |
* The settings that control the compiler behavior. |
130 |
* |
131 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
132 |
* Component which will receive and persist all compilation results and is intended |
133 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
134 |
* responsible for writing out the actual .class files to the file system. |
135 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
136 |
* |
137 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
138 |
* Factory used inside the compiler to create problem descriptors. It allows the |
139 |
* compiler client to supply its own representation of compilation problems in |
140 |
* order to avoid object conversions. Note that the factory is not supposed |
141 |
* to accumulate the created problems, the compiler will gather them all and hand |
142 |
* them back as part of the compilation unit result. |
143 |
* |
144 |
* @param parseLiteralExpressionsAsConstants <code>boolean</code> |
145 |
* This parameter is used to optimize the literals or leave them as they are in the source. |
146 |
* If you put true, "Hello" + " world" will be converted to "Hello world". |
147 |
* |
148 |
* @deprecated this constructor is kept to preserve 3.1 and 3.2M4 compatibility |
149 |
*/ |
150 |
public Compiler( |
151 |
INameEnvironment environment, |
152 |
IErrorHandlingPolicy policy, |
153 |
Map settings, |
154 |
final ICompilerRequestor requestor, |
155 |
IProblemFactory problemFactory, |
156 |
boolean parseLiteralExpressionsAsConstants) { |
157 |
this(environment, policy, new CompilerOptions(settings, parseLiteralExpressionsAsConstants), requestor, problemFactory, null /* printwriter */, null /* progress */); |
158 |
} |
159 |
|
160 |
/** |
161 |
* Answer a new compiler using the given name environment and compiler options. |
162 |
* The environment and options will be in effect for the lifetime of the compiler. |
163 |
* When the compiler is run, compilation results are sent to the given requestor. |
164 |
* |
165 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
166 |
* Environment used by the compiler in order to resolve type and package |
167 |
* names. The name environment implements the actual connection of the compiler |
168 |
* to the outside world (e.g. in batch mode the name environment is performing |
169 |
* pure file accesses, reuse previous build state or connection to repositories). |
170 |
* Note: the name environment is responsible for implementing the actual classpath |
171 |
* rules. |
172 |
* |
173 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
174 |
* Configurable part for problem handling, allowing the compiler client to |
175 |
* specify the rules for handling problems (stop on first error or accumulate |
176 |
* them all) and at the same time perform some actions such as opening a dialog |
177 |
* in UI when compiling interactively. |
178 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
179 |
* |
180 |
* @param options org.eclipse.jdt.internal.compiler.impl.CompilerOptions |
181 |
* The options that control the compiler behavior. |
182 |
* |
183 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
184 |
* Component which will receive and persist all compilation results and is intended |
185 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
186 |
* responsible for writing out the actual .class files to the file system. |
187 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
188 |
* |
189 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
190 |
* Factory used inside the compiler to create problem descriptors. It allows the |
191 |
* compiler client to supply its own representation of compilation problems in |
192 |
* order to avoid object conversions. Note that the factory is not supposed |
193 |
* to accumulate the created problems, the compiler will gather them all and hand |
194 |
* them back as part of the compilation unit result. |
195 |
*/ |
196 |
public Compiler( |
197 |
INameEnvironment environment, |
198 |
IErrorHandlingPolicy policy, |
199 |
CompilerOptions options, |
200 |
final ICompilerRequestor requestor, |
201 |
IProblemFactory problemFactory) { |
202 |
this(environment, policy, options, requestor, problemFactory, null /* printwriter */, null /* progress */); |
203 |
} |
204 |
|
205 |
/** |
206 |
* Answer a new compiler using the given name environment and compiler options. |
207 |
* The environment and options will be in effect for the lifetime of the compiler. |
208 |
* When the compiler is run, compilation results are sent to the given requestor. |
209 |
* |
210 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
211 |
* Environment used by the compiler in order to resolve type and package |
212 |
* names. The name environment implements the actual connection of the compiler |
213 |
* to the outside world (e.g. in batch mode the name environment is performing |
214 |
* pure file accesses, reuse previous build state or connection to repositories). |
215 |
* Note: the name environment is responsible for implementing the actual classpath |
216 |
* rules. |
217 |
* |
218 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
219 |
* Configurable part for problem handling, allowing the compiler client to |
220 |
* specify the rules for handling problems (stop on first error or accumulate |
221 |
* them all) and at the same time perform some actions such as opening a dialog |
222 |
* in UI when compiling interactively. |
223 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
224 |
* |
225 |
* @param options org.eclipse.jdt.internal.compiler.impl.CompilerOptions |
226 |
* The options that control the compiler behavior. |
227 |
* |
228 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
229 |
* Component which will receive and persist all compilation results and is intended |
230 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
231 |
* responsible for writing out the actual .class files to the file system. |
232 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
233 |
* |
234 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
235 |
* Factory used inside the compiler to create problem descriptors. It allows the |
236 |
* compiler client to supply its own representation of compilation problems in |
237 |
* order to avoid object conversions. Note that the factory is not supposed |
238 |
* to accumulate the created problems, the compiler will gather them all and hand |
239 |
* them back as part of the compilation unit result. |
240 |
* @deprecated |
241 |
*/ |
242 |
public Compiler( |
243 |
INameEnvironment environment, |
244 |
IErrorHandlingPolicy policy, |
245 |
CompilerOptions options, |
246 |
final ICompilerRequestor requestor, |
247 |
IProblemFactory problemFactory, |
248 |
PrintWriter out) { |
249 |
this(environment, policy, options, requestor, problemFactory, out, null /* progress */); |
250 |
} |
251 |
|
252 |
public Compiler( |
253 |
INameEnvironment environment, |
254 |
IErrorHandlingPolicy policy, |
255 |
CompilerOptions options, |
256 |
final ICompilerRequestor requestor, |
257 |
IProblemFactory problemFactory, |
258 |
PrintWriter out, |
259 |
CompilationProgress progress) { |
260 |
|
261 |
this.options = options; |
262 |
this.progress = progress; |
263 |
|
264 |
// wrap requestor in DebugRequestor if one is specified |
265 |
if(DebugRequestor == null) { |
266 |
this.requestor = requestor; |
267 |
} else { |
268 |
this.requestor = new ICompilerRequestor(){ |
269 |
public void acceptResult(CompilationResult result){ |
270 |
if (DebugRequestor.isActive()){ |
271 |
DebugRequestor.acceptDebugResult(result); |
272 |
} |
273 |
requestor.acceptResult(result); |
274 |
} |
275 |
}; |
276 |
} |
277 |
this.problemReporter = new ProblemReporter(policy, this.options, problemFactory); |
278 |
this.lookupEnvironment = new LookupEnvironment(this, this.options, this.problemReporter, environment); |
279 |
this.out = out == null ? new PrintWriter(System.out, true) : out; |
280 |
this.stats = new CompilerStats(); |
281 |
initializeParser(); |
282 |
} |
283 |
|
120 |
|
284 |
/** |
121 |
/** |
285 |
* Add an additional binary type |
122 |
* Answer a new compiler using the given name environment and compiler options. |
286 |
*/ |
123 |
* The environment and options will be in effect for the lifetime of the compiler. |
287 |
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
124 |
* When the compiler is run, compilation results are sent to the given requestor. |
288 |
if (this.options.verbose) { |
125 |
* |
289 |
this.out.println( |
126 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
290 |
Messages.bind(Messages.compilation_loadBinary, new String(binaryType.getName()))); |
127 |
* Environment used by the compiler in order to resolve type and package |
|
|
128 |
* names. The name environment implements the actual connection of the compiler |
129 |
* to the outside world (e.g. in batch mode the name environment is performing |
130 |
* pure file accesses, reuse previous build state or connection to repositories). |
131 |
* Note: the name environment is responsible for implementing the actual classpath |
132 |
* rules. |
133 |
* |
134 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
135 |
* Configurable part for problem handling, allowing the compiler client to |
136 |
* specify the rules for handling problems (stop on first error or accumulate |
137 |
* them all) and at the same time perform some actions such as opening a dialog |
138 |
* in UI when compiling interactively. |
139 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
140 |
* |
141 |
* @param settings java.util.Map |
142 |
* The settings that control the compiler behavior. |
143 |
* |
144 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
145 |
* Component which will receive and persist all compilation results and is intended |
146 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
147 |
* responsible for writing out the actual .class files to the file system. |
148 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
149 |
* |
150 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
151 |
* Factory used inside the compiler to create problem descriptors. It allows the |
152 |
* compiler client to supply its own representation of compilation problems in |
153 |
* order to avoid object conversions. Note that the factory is not supposed |
154 |
* to accumulate the created problems, the compiler will gather them all and hand |
155 |
* them back as part of the compilation unit result. |
156 |
* |
157 |
* @param parseLiteralExpressionsAsConstants <code>boolean</code> |
158 |
* This parameter is used to optimize the literals or leave them as they are in the source. |
159 |
* If you put true, "Hello" + " world" will be converted to "Hello world". |
160 |
* |
161 |
* @deprecated this constructor is kept to preserve 3.1 and 3.2M4 compatibility |
162 |
*/ |
163 |
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, Map settings, ICompilerRequestor requestor, IProblemFactory problemFactory, boolean parseLiteralExpressionsAsConstants) { |
164 |
this(environment, policy, new CompilerOptions(settings, parseLiteralExpressionsAsConstants), requestor, problemFactory, null /* printwriter */, null /* progress */); |
165 |
} |
166 |
|
167 |
/** |
168 |
* Answer a new compiler using the given name environment and compiler options. |
169 |
* The environment and options will be in effect for the lifetime of the compiler. |
170 |
* When the compiler is run, compilation results are sent to the given requestor. |
171 |
* |
172 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
173 |
* Environment used by the compiler in order to resolve type and package |
174 |
* names. The name environment implements the actual connection of the compiler |
175 |
* to the outside world (e.g. in batch mode the name environment is performing |
176 |
* pure file accesses, reuse previous build state or connection to repositories). |
177 |
* Note: the name environment is responsible for implementing the actual classpath |
178 |
* rules. |
179 |
* |
180 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
181 |
* Configurable part for problem handling, allowing the compiler client to |
182 |
* specify the rules for handling problems (stop on first error or accumulate |
183 |
* them all) and at the same time perform some actions such as opening a dialog |
184 |
* in UI when compiling interactively. |
185 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
186 |
* |
187 |
* @param options org.eclipse.jdt.internal.compiler.impl.CompilerOptions |
188 |
* The options that control the compiler behavior. |
189 |
* |
190 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
191 |
* Component which will receive and persist all compilation results and is intended |
192 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
193 |
* responsible for writing out the actual .class files to the file system. |
194 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
195 |
* |
196 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
197 |
* Factory used inside the compiler to create problem descriptors. It allows the |
198 |
* compiler client to supply its own representation of compilation problems in |
199 |
* order to avoid object conversions. Note that the factory is not supposed |
200 |
* to accumulate the created problems, the compiler will gather them all and hand |
201 |
* them back as part of the compilation unit result. |
202 |
*/ |
203 |
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, CompilerOptions options, ICompilerRequestor requestor, IProblemFactory problemFactory) { |
204 |
this(environment, policy, options, requestor, problemFactory, null /* printwriter */, null /* progress */); |
205 |
} |
206 |
|
207 |
/** |
208 |
* Answer a new compiler using the given name environment and compiler options. |
209 |
* The environment and options will be in effect for the lifetime of the compiler. |
210 |
* When the compiler is run, compilation results are sent to the given requestor. |
211 |
* |
212 |
* @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment |
213 |
* Environment used by the compiler in order to resolve type and package |
214 |
* names. The name environment implements the actual connection of the compiler |
215 |
* to the outside world (e.g. in batch mode the name environment is performing |
216 |
* pure file accesses, reuse previous build state or connection to repositories). |
217 |
* Note: the name environment is responsible for implementing the actual classpath |
218 |
* rules. |
219 |
* |
220 |
* @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy |
221 |
* Configurable part for problem handling, allowing the compiler client to |
222 |
* specify the rules for handling problems (stop on first error or accumulate |
223 |
* them all) and at the same time perform some actions such as opening a dialog |
224 |
* in UI when compiling interactively. |
225 |
* @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies |
226 |
* |
227 |
* @param options org.eclipse.jdt.internal.compiler.impl.CompilerOptions |
228 |
* The options that control the compiler behavior. |
229 |
* |
230 |
* @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor |
231 |
* Component which will receive and persist all compilation results and is intended |
232 |
* to consume them as they are produced. Typically, in a batch compiler, it is |
233 |
* responsible for writing out the actual .class files to the file system. |
234 |
* @see org.eclipse.jdt.internal.compiler.CompilationResult |
235 |
* |
236 |
* @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory |
237 |
* Factory used inside the compiler to create problem descriptors. It allows the |
238 |
* compiler client to supply its own representation of compilation problems in |
239 |
* order to avoid object conversions. Note that the factory is not supposed |
240 |
* to accumulate the created problems, the compiler will gather them all and hand |
241 |
* them back as part of the compilation unit result. |
242 |
* @deprecated |
243 |
*/ |
244 |
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, CompilerOptions options, ICompilerRequestor requestor, IProblemFactory problemFactory, PrintWriter out) { |
245 |
this(environment, policy, options, requestor, problemFactory, out, null /* progress */); |
246 |
} |
247 |
|
248 |
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, CompilerOptions options, final ICompilerRequestor requestor, IProblemFactory problemFactory, PrintWriter out, CompilationProgress progress) { |
249 |
this.options = options; |
250 |
this.progress = progress; |
251 |
|
252 |
// wrap requestor in DebugRequestor if one is specified |
253 |
if(DebugRequestor == null) { |
254 |
this.requestor = requestor; |
255 |
} else { |
256 |
this.requestor = new ICompilerRequestor(){ |
257 |
public void acceptResult(CompilationResult result){ |
258 |
if (DebugRequestor.isActive()){ |
259 |
DebugRequestor.acceptDebugResult(result); |
260 |
} |
261 |
requestor.acceptResult(result); |
262 |
} |
263 |
}; |
264 |
} |
265 |
this.problemReporter = new ProblemReporter(policy, this.options, problemFactory); |
266 |
this.lookupEnvironment = new LookupEnvironment(this, this.options, this.problemReporter, environment); |
267 |
this.out = out == null ? new PrintWriter(System.out, true) : out; |
268 |
this.stats = new CompilerStats(); |
269 |
initializeParser(); |
270 |
} |
271 |
|
272 |
/** |
273 |
* Add an additional binary type |
274 |
*/ |
275 |
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
276 |
if (this.options.verbose) { |
277 |
this.out.println( |
278 |
Messages.bind(Messages.compilation_loadBinary, new String(binaryType.getName()))); |
291 |
// new Exception("TRACE BINARY").printStackTrace(System.out); |
279 |
// new Exception("TRACE BINARY").printStackTrace(System.out); |
292 |
// System.out.println(); |
280 |
// System.out.println(); |
293 |
} |
|
|
294 |
this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction); |
295 |
} |
281 |
} |
|
|
282 |
this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction); |
283 |
} |
296 |
|
284 |
|
297 |
/** |
285 |
/** |
298 |
* Add an additional compilation unit into the loop |
286 |
* Add an additional compilation unit into the loop |
299 |
* -> build compilation unit declarations, their bindings and record their results. |
287 |
* -> build compilation unit declarations, their bindings and record their results. |
300 |
*/ |
288 |
*/ |
301 |
public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { |
289 |
public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { |
302 |
// Switch the current policy and compilation result for this unit to the requested one. |
290 |
// Switch the current policy and compilation result for this unit to the requested one. |
303 |
CompilationResult unitResult = |
291 |
CompilationResult unitResult = |
304 |
new CompilationResult(sourceUnit, this.totalUnits, this.totalUnits, this.options.maxProblemsPerUnit); |
292 |
new CompilationResult(sourceUnit, this.totalUnits, this.totalUnits, this.options.maxProblemsPerUnit); |
305 |
unitResult.checkSecondaryTypes = true; |
293 |
unitResult.checkSecondaryTypes = true; |
306 |
try { |
294 |
try { |
307 |
if (this.options.verbose) { |
295 |
if (this.options.verbose) { |
308 |
String count = String.valueOf(this.totalUnits + 1); |
296 |
String count = String.valueOf(this.totalUnits + 1); |
309 |
this.out.println( |
297 |
this.out.println( |
310 |
Messages.bind(Messages.compilation_request, |
298 |
Messages.bind(Messages.compilation_request, |
311 |
new String[] { |
299 |
new String[] { |
312 |
count, |
300 |
count, |
313 |
count, |
301 |
count, |
314 |
new String(sourceUnit.getFileName()) |
302 |
new String(sourceUnit.getFileName()) |
315 |
})); |
303 |
})); |
316 |
} |
304 |
} |
317 |
// diet parsing for large collection of unit |
305 |
// diet parsing for large collection of unit |
318 |
CompilationUnitDeclaration parsedUnit; |
306 |
CompilationUnitDeclaration parsedUnit; |
319 |
if (this.totalUnits < this.parseThreshold) { |
307 |
if (this.totalUnits < this.parseThreshold) { |
320 |
parsedUnit = this.parser.parse(sourceUnit, unitResult); |
308 |
parsedUnit = this.parser.parse(sourceUnit, unitResult); |
321 |
} else { |
309 |
} else { |
322 |
parsedUnit = this.parser.dietParse(sourceUnit, unitResult); |
310 |
parsedUnit = this.parser.dietParse(sourceUnit, unitResult); |
323 |
} |
311 |
} |
324 |
parsedUnit.bits |= ASTNode.IsImplicitUnit; |
312 |
parsedUnit.bits |= ASTNode.IsImplicitUnit; |
325 |
// initial type binding creation |
313 |
// initial type binding creation |
326 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); |
314 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); |
327 |
addCompilationUnit(sourceUnit, parsedUnit); |
315 |
addCompilationUnit(sourceUnit, parsedUnit); |
328 |
|
316 |
|
329 |
// binding resolution |
317 |
// binding resolution |
330 |
this.lookupEnvironment.completeTypeBindings(parsedUnit); |
318 |
this.lookupEnvironment.completeTypeBindings(parsedUnit); |
331 |
} catch (AbortCompilationUnit e) { |
319 |
} catch (AbortCompilationUnit e) { |
332 |
// at this point, currentCompilationUnitResult may not be sourceUnit, but some other |
320 |
// at this point, currentCompilationUnitResult may not be sourceUnit, but some other |
333 |
// one requested further along to resolve sourceUnit. |
321 |
// one requested further along to resolve sourceUnit. |
334 |
if (unitResult.compilationUnit == sourceUnit) { // only report once |
322 |
if (unitResult.compilationUnit == sourceUnit) { // only report once |
335 |
this.requestor.acceptResult(unitResult.tagAsAccepted()); |
323 |
this.requestor.acceptResult(unitResult.tagAsAccepted()); |
336 |
} else { |
324 |
} else { |
337 |
throw e; // want to abort enclosing request to compile |
325 |
throw e; // want to abort enclosing request to compile |
338 |
} |
|
|
339 |
} |
326 |
} |
340 |
} |
327 |
} |
|
|
328 |
} |
341 |
|
329 |
|
342 |
/** |
330 |
/** |
343 |
* Add additional source types |
331 |
* Add additional source types |
344 |
*/ |
332 |
*/ |
345 |
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
333 |
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
346 |
this.problemReporter.abortDueToInternalError( |
334 |
this.problemReporter.abortDueToInternalError( |
347 |
Messages.bind(Messages.abort_againstSourceModel, new String[] { String.valueOf(sourceTypes[0].getName()), String.valueOf(sourceTypes[0].getFileName()) })); |
335 |
Messages.bind(Messages.abort_againstSourceModel, new String[] { String.valueOf(sourceTypes[0].getName()), String.valueOf(sourceTypes[0].getFileName()) })); |
348 |
} |
336 |
} |
349 |
|
|
|
350 |
protected synchronized void addCompilationUnit( |
351 |
ICompilationUnit sourceUnit, |
352 |
CompilationUnitDeclaration parsedUnit) { |
353 |
|
354 |
// append the unit to the list of ones to process later on |
355 |
int size = this.unitsToProcess.length; |
356 |
if (this.totalUnits == size) |
357 |
// when growing reposition units starting at position 0 |
358 |
System.arraycopy( |
359 |
this.unitsToProcess, |
360 |
0, |
361 |
(this.unitsToProcess = new CompilationUnitDeclaration[size * 2]), |
362 |
0, |
363 |
this.totalUnits); |
364 |
this.unitsToProcess[this.totalUnits++] = parsedUnit; |
365 |
} |
366 |
|
367 |
/** |
368 |
* Add the initial set of compilation units into the loop |
369 |
* -> build compilation unit declarations, their bindings and record their results. |
370 |
*/ |
371 |
protected void beginToCompile(ICompilationUnit[] sourceUnits) { |
372 |
int maxUnits = sourceUnits.length; |
373 |
this.totalUnits = 0; |
374 |
this.unitsToProcess = new CompilationUnitDeclaration[maxUnits]; |
375 |
|
337 |
|
376 |
internalBeginToCompile(sourceUnits, maxUnits); |
338 |
protected synchronized void addCompilationUnit(ICompilationUnit sourceUnit, CompilationUnitDeclaration parsedUnit) { |
377 |
} |
339 |
// append the unit to the list of ones to process later on |
|
|
340 |
int size = this.unitsToProcess.length; |
341 |
if (this.totalUnits == size) |
342 |
// when growing reposition units starting at position 0 |
343 |
System.arraycopy( |
344 |
this.unitsToProcess, |
345 |
0, |
346 |
(this.unitsToProcess = new CompilationUnitDeclaration[size * 2]), |
347 |
0, |
348 |
this.totalUnits); |
349 |
this.unitsToProcess[this.totalUnits++] = parsedUnit; |
350 |
} |
378 |
|
351 |
|
379 |
/** |
352 |
/** |
380 |
* Checks whether the compilation has been canceled and reports the given progress to the compiler progress. |
353 |
* Add the initial set of compilation units into the loop |
381 |
*/ |
354 |
* -> build compilation unit declarations, their bindings and record their results. |
382 |
protected void reportProgress(String taskDecription) { |
355 |
*/ |
383 |
if (this.progress != null) { |
356 |
protected void beginToCompile(ICompilationUnit[] sourceUnits) { |
384 |
if (this.progress.isCanceled()) { |
357 |
int maxUnits = sourceUnits.length; |
385 |
// Only AbortCompilation can stop the compiler cleanly. |
358 |
this.totalUnits = 0; |
386 |
// We check cancellation again following the call to compile. |
359 |
this.unitsToProcess = new CompilationUnitDeclaration[maxUnits]; |
387 |
throw new AbortCompilation(true, null); |
360 |
|
388 |
} |
361 |
internalBeginToCompile(sourceUnits, maxUnits); |
389 |
this.progress.setTaskName(taskDecription); |
362 |
} |
|
|
363 |
|
364 |
/** |
365 |
* Checks whether the compilation has been canceled and reports the given progress to the compiler progress. |
366 |
*/ |
367 |
protected void reportProgress(String taskDecription) { |
368 |
if (this.progress != null) { |
369 |
if (this.progress.isCanceled()) { |
370 |
// Only AbortCompilation can stop the compiler cleanly. |
371 |
// We check cancellation again following the call to compile. |
372 |
throw new AbortCompilation(true, null); |
390 |
} |
373 |
} |
|
|
374 |
this.progress.setTaskName(taskDecription); |
391 |
} |
375 |
} |
|
|
376 |
} |
392 |
|
377 |
|
393 |
/** |
378 |
/** |
394 |
* Checks whether the compilation has been canceled and reports the given work increment to the compiler progress. |
379 |
* Checks whether the compilation has been canceled and reports the given work increment to the compiler progress. |
395 |
*/ |
380 |
*/ |
396 |
protected void reportWorked(int workIncrement, int currentUnitIndex) { |
381 |
protected void reportWorked(int workIncrement, int currentUnitIndex) { |
397 |
if (this.progress != null) { |
382 |
if (this.progress != null) { |
398 |
if (this.progress.isCanceled()) { |
383 |
if (this.progress.isCanceled()) { |
399 |
// Only AbortCompilation can stop the compiler cleanly. |
384 |
// Only AbortCompilation can stop the compiler cleanly. |
400 |
// We check cancellation again following the call to compile. |
385 |
// We check cancellation again following the call to compile. |
401 |
throw new AbortCompilation(true, null); |
386 |
throw new AbortCompilation(true, null); |
402 |
} |
|
|
403 |
this.progress.worked(workIncrement, (this.totalUnits* this.remainingIterations) - currentUnitIndex - 1); |
404 |
} |
387 |
} |
|
|
388 |
this.progress.worked(workIncrement, (this.totalUnits* this.remainingIterations) - currentUnitIndex - 1); |
405 |
} |
389 |
} |
|
|
390 |
} |
406 |
|
391 |
|
407 |
/** |
392 |
/** |
408 |
* General API |
393 |
* General API |
409 |
* -> compile each of supplied files |
394 |
* -> compile each of supplied files |
410 |
* -> recompile any required types for which we have an incomplete principle structure |
395 |
* -> recompile any required types for which we have an incomplete principle structure |
411 |
*/ |
396 |
*/ |
412 |
public void compile(ICompilationUnit[] sourceUnits) { |
397 |
public void compile(ICompilationUnit[] sourceUnits) { |
413 |
this.stats.startTime = System.currentTimeMillis(); |
398 |
this.stats.startTime = System.currentTimeMillis(); |
414 |
CompilationUnitDeclaration unit = null; |
399 |
CompilationUnitDeclaration unit = null; |
415 |
ProcessTaskManager processingTask = null; |
400 |
ProcessTaskManager processingTask = null; |
416 |
try { |
401 |
try { |
417 |
// build and record parsed units |
402 |
// build and record parsed units |
418 |
reportProgress(Messages.compilation_beginningToCompile); |
403 |
reportProgress(Messages.compilation_beginningToCompile); |
419 |
|
404 |
beginToCompile(sourceUnits); |
420 |
beginToCompile(sourceUnits); |
405 |
if (this.annotationProcessorManager != null) { |
421 |
|
406 |
processAnnotations(); |
422 |
if (this.annotationProcessorManager != null) { |
407 |
if (!this.options.generateClassFiles) { |
423 |
processAnnotations(); |
408 |
// -proc:only was set on the command line |
424 |
if (!this.options.generateClassFiles) { |
409 |
return; |
425 |
// -proc:only was set on the command line |
|
|
426 |
return; |
427 |
} |
428 |
} |
410 |
} |
429 |
|
411 |
} |
430 |
if (this.useSingleThread) { |
412 |
if (this.useSingleThread) { |
431 |
// process all units (some more could be injected in the loop by the lookup environment) |
413 |
// process all units (some more could be injected in the loop by the lookup environment) |
432 |
for (int i = 0; i < this.totalUnits; i++) { |
414 |
for (int i = 0; i < this.totalUnits; i++) { |
433 |
unit = this.unitsToProcess[i]; |
415 |
unit = this.unitsToProcess[i]; |
434 |
reportProgress(Messages.bind(Messages.compilation_processing, new String(unit.getFileName()))); |
416 |
reportProgress(Messages.bind(Messages.compilation_processing, new String(unit.getFileName()))); |
435 |
try { |
417 |
try { |
436 |
if (this.options.verbose) |
|
|
437 |
this.out.println( |
438 |
Messages.bind(Messages.compilation_process, |
439 |
new String[] { |
440 |
String.valueOf(i + 1), |
441 |
String.valueOf(this.totalUnits), |
442 |
new String(this.unitsToProcess[i].getFileName()) |
443 |
})); |
444 |
process(unit, i); |
445 |
} finally { |
446 |
// cleanup compilation unit result |
447 |
unit.cleanUp(); |
448 |
} |
449 |
this.unitsToProcess[i] = null; // release reference to processed unit declaration |
450 |
|
451 |
reportWorked(1, i); |
452 |
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length; |
453 |
long acceptStart = System.currentTimeMillis(); |
454 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
455 |
this.stats.generateTime += System.currentTimeMillis() - acceptStart; // record accept time as part of generation |
456 |
if (this.options.verbose) |
418 |
if (this.options.verbose) |
457 |
this.out.println( |
419 |
this.out.println( |
458 |
Messages.bind(Messages.compilation_done, |
420 |
Messages.bind(Messages.compilation_process, |
459 |
new String[] { |
421 |
new String[] { |
460 |
String.valueOf(i + 1), |
422 |
String.valueOf(i + 1), |
461 |
String.valueOf(this.totalUnits), |
423 |
String.valueOf(this.totalUnits), |
462 |
new String(unit.getFileName()) |
424 |
new String(this.unitsToProcess[i].getFileName()) |
463 |
})); |
|
|
464 |
} |
465 |
} else { |
466 |
processingTask = new ProcessTaskManager(this); |
467 |
int acceptedCount = 0; |
468 |
// process all units (some more could be injected in the loop by the lookup environment) |
469 |
// the processTask can continue to process units until its fixed sized cache is full then it must wait |
470 |
// for this this thread to accept the units as they appear (it only waits if no units are available) |
471 |
while (true) { |
472 |
try { |
473 |
unit = processingTask.removeNextUnit(); // waits if no units are in the processed queue |
474 |
} catch (Error e) { |
475 |
unit = processingTask.unitToProcess; |
476 |
throw e; |
477 |
} catch (RuntimeException e) { |
478 |
unit = processingTask.unitToProcess; |
479 |
throw e; |
480 |
} |
481 |
if (unit == null) break; |
482 |
reportWorked(1, acceptedCount++); |
483 |
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length; |
484 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
485 |
if (this.options.verbose) |
486 |
this.out.println( |
487 |
Messages.bind(Messages.compilation_done, |
488 |
new String[] { |
489 |
String.valueOf(acceptedCount), |
490 |
String.valueOf(this.totalUnits), |
491 |
new String(unit.getFileName()) |
492 |
})); |
425 |
})); |
493 |
} |
426 |
process(unit, i); |
|
|
427 |
} finally { |
428 |
// cleanup compilation unit result |
429 |
unit.cleanUp(); |
430 |
} |
431 |
this.unitsToProcess[i] = null; // release reference to processed unit declaration |
432 |
|
433 |
reportWorked(1, i); |
434 |
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length; |
435 |
long acceptStart = System.currentTimeMillis(); |
436 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
437 |
this.stats.generateTime += System.currentTimeMillis() - acceptStart; // record accept time as part of generation |
438 |
if (this.options.verbose) |
439 |
this.out.println( |
440 |
Messages.bind(Messages.compilation_done, |
441 |
new String[] { |
442 |
String.valueOf(i + 1), |
443 |
String.valueOf(this.totalUnits), |
444 |
new String(unit.getFileName()) |
445 |
})); |
494 |
} |
446 |
} |
495 |
} catch (AbortCompilation e) { |
447 |
} else { |
496 |
this.handleInternalException(e, unit); |
448 |
processingTask = new ProcessTaskManager(this); |
497 |
} catch (Error e) { |
449 |
int acceptedCount = 0; |
498 |
this.handleInternalException(e, unit, null); |
450 |
// process all units (some more could be injected in the loop by the lookup environment) |
499 |
throw e; // rethrow |
451 |
// the processTask can continue to process units until its fixed sized cache is full then it must wait |
500 |
} catch (RuntimeException e) { |
452 |
// for this this thread to accept the units as they appear (it only waits if no units are available) |
501 |
this.handleInternalException(e, unit, null); |
453 |
while (true) { |
502 |
throw e; // rethrow |
454 |
try { |
503 |
} finally { |
455 |
unit = processingTask.removeNextUnit(); // waits if no units are in the processed queue |
504 |
if (processingTask != null) { |
456 |
} catch (Error e) { |
505 |
processingTask.shutdown(); |
457 |
unit = processingTask.unitToProcess; |
506 |
processingTask = null; |
458 |
throw e; |
|
|
459 |
} catch (RuntimeException e) { |
460 |
unit = processingTask.unitToProcess; |
461 |
throw e; |
462 |
} |
463 |
if (unit == null) break; |
464 |
reportWorked(1, acceptedCount++); |
465 |
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length; |
466 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
467 |
if (this.options.verbose) |
468 |
this.out.println( |
469 |
Messages.bind(Messages.compilation_done, |
470 |
new String[] { |
471 |
String.valueOf(acceptedCount), |
472 |
String.valueOf(this.totalUnits), |
473 |
new String(unit.getFileName()) |
474 |
})); |
507 |
} |
475 |
} |
508 |
reset(); |
|
|
509 |
this.stats.endTime = System.currentTimeMillis(); |
510 |
} |
476 |
} |
511 |
if (this.options.verbose) { |
477 |
} catch (AbortCompilation e) { |
512 |
if (this.totalUnits > 1) { |
478 |
this.handleInternalException(e, unit); |
513 |
this.out.println( |
479 |
} catch (Error e) { |
514 |
Messages.bind(Messages.compilation_units, String.valueOf(this.totalUnits))); |
480 |
this.handleInternalException(e, unit, null); |
515 |
} else { |
481 |
throw e; // rethrow |
516 |
this.out.println( |
482 |
} catch (RuntimeException e) { |
517 |
Messages.bind(Messages.compilation_unit, String.valueOf(this.totalUnits))); |
483 |
this.handleInternalException(e, unit, null); |
518 |
} |
484 |
throw e; // rethrow |
|
|
485 |
} finally { |
486 |
if (processingTask != null) { |
487 |
processingTask.shutdown(); |
488 |
processingTask = null; |
519 |
} |
489 |
} |
|
|
490 |
reset(); |
491 |
this.stats.endTime = System.currentTimeMillis(); |
520 |
} |
492 |
} |
521 |
|
493 |
if (this.options.verbose) { |
522 |
public synchronized CompilationUnitDeclaration getUnitToProcess(int next) { |
494 |
if (this.totalUnits > 1) { |
523 |
if (next < this.totalUnits) { |
495 |
this.out.println( |
524 |
CompilationUnitDeclaration unit = this.unitsToProcess[next]; |
496 |
Messages.bind(Messages.compilation_units, String.valueOf(this.totalUnits))); |
525 |
this.unitsToProcess[next] = null; // release reference to processed unit declaration |
497 |
} else { |
526 |
return unit; |
498 |
this.out.println( |
|
|
499 |
Messages.bind(Messages.compilation_unit, String.valueOf(this.totalUnits))); |
527 |
} |
500 |
} |
528 |
return null; |
|
|
529 |
} |
501 |
} |
|
|
502 |
} |
530 |
|
503 |
|
531 |
public void setBinaryTypes(ReferenceBinding[] binaryTypes) { |
504 |
public synchronized CompilationUnitDeclaration getUnitToProcess(int next) { |
532 |
this.referenceBindings = binaryTypes; |
505 |
if (next < this.totalUnits) { |
533 |
} |
506 |
CompilationUnitDeclaration unit = this.unitsToProcess[next]; |
534 |
/* |
507 |
this.unitsToProcess[next] = null; // release reference to processed unit declaration |
535 |
* Compiler crash recovery in case of unexpected runtime exceptions |
508 |
return unit; |
536 |
*/ |
|
|
537 |
protected void handleInternalException( |
538 |
Throwable internalException, |
539 |
CompilationUnitDeclaration unit, |
540 |
CompilationResult result) { |
541 |
|
542 |
if (result == null && unit != null) { |
543 |
result = unit.compilationResult; // current unit being processed ? |
544 |
} |
545 |
// Lookup environment may be in middle of connecting types |
546 |
if (result == null && this.lookupEnvironment.unitBeingCompleted != null) { |
547 |
result = this.lookupEnvironment.unitBeingCompleted.compilationResult; |
548 |
} |
549 |
if (result == null) { |
550 |
synchronized (this) { |
551 |
if (this.unitsToProcess != null && this.totalUnits > 0) |
552 |
result = this.unitsToProcess[this.totalUnits - 1].compilationResult; |
553 |
} |
554 |
} |
555 |
// last unit in beginToCompile ? |
556 |
|
557 |
boolean needToPrint = true; |
558 |
if (result != null) { |
559 |
/* create and record a compilation problem */ |
560 |
StringWriter stringWriter = new StringWriter(); |
561 |
PrintWriter writer = new PrintWriter(stringWriter); |
562 |
internalException.printStackTrace(writer); |
563 |
StringBuffer buffer = stringWriter.getBuffer(); |
564 |
|
565 |
String[] pbArguments = new String[] { |
566 |
Messages.compilation_internalError |
567 |
+ "\n" //$NON-NLS-1$ |
568 |
+ buffer.toString()}; |
569 |
|
570 |
result |
571 |
.record( |
572 |
this.problemReporter |
573 |
.createProblem( |
574 |
result.getFileName(), |
575 |
IProblem.Unclassified, |
576 |
pbArguments, |
577 |
pbArguments, |
578 |
Error, // severity |
579 |
0, // source start |
580 |
0, // source end |
581 |
0, // line number |
582 |
0),// column number |
583 |
unit); |
584 |
|
585 |
/* hand back the compilation result */ |
586 |
if (!result.hasBeenAccepted) { |
587 |
this.requestor.acceptResult(result.tagAsAccepted()); |
588 |
needToPrint = false; |
589 |
} |
590 |
} |
591 |
if (needToPrint) { |
592 |
/* dump a stack trace to the console */ |
593 |
internalException.printStackTrace(); |
594 |
} |
595 |
} |
509 |
} |
|
|
510 |
return null; |
511 |
} |
596 |
|
512 |
|
597 |
/* |
513 |
public void setBinaryTypes(ReferenceBinding[] binaryTypes) { |
598 |
* Compiler recovery in case of internal AbortCompilation event |
514 |
this.referenceBindings = binaryTypes; |
599 |
*/ |
515 |
} |
600 |
protected void handleInternalException( |
|
|
601 |
AbortCompilation abortException, |
602 |
CompilationUnitDeclaration unit) { |
603 |
|
604 |
/* special treatment for SilentAbort: silently cancelling the compilation process */ |
605 |
if (abortException.isSilent) { |
606 |
if (abortException.silentException == null) { |
607 |
return; |
608 |
} |
609 |
throw abortException.silentException; |
610 |
} |
611 |
|
516 |
|
612 |
/* uncomment following line to see where the abort came from */ |
517 |
/* |
613 |
// abortException.printStackTrace(); |
518 |
* Compiler crash recovery in case of unexpected runtime exceptions |
|
|
519 |
*/ |
520 |
protected void handleInternalException(Throwable internalException, CompilationUnitDeclaration unit, CompilationResult result) { |
521 |
if (result == null && unit != null) { |
522 |
result = unit.compilationResult; // current unit being processed ? |
523 |
} |
524 |
// Lookup environment may be in middle of connecting types |
525 |
if (result == null && this.lookupEnvironment.unitBeingCompleted != null) { |
526 |
result = this.lookupEnvironment.unitBeingCompleted.compilationResult; |
527 |
} |
528 |
if (result == null) { |
529 |
synchronized (this) { |
530 |
if (this.unitsToProcess != null && this.totalUnits > 0) |
531 |
result = this.unitsToProcess[this.totalUnits - 1].compilationResult; |
532 |
} |
533 |
} |
534 |
// last unit in beginToCompile ? |
535 |
|
536 |
boolean needToPrint = true; |
537 |
if (result != null) { |
538 |
/* create and record a compilation problem */ |
539 |
StringWriter stringWriter = new StringWriter(); |
540 |
PrintWriter writer = new PrintWriter(stringWriter); |
541 |
internalException.printStackTrace(writer); |
542 |
String exceptionTrace = stringWriter.toString(); |
543 |
// only keep a portion of it |
544 |
if (exceptionTrace.length() > 10000) { |
545 |
exceptionTrace = exceptionTrace.substring(0, 10000); |
546 |
} |
547 |
|
548 |
String[] pbArguments = new String[] { |
549 |
Messages.compilation_internalError |
550 |
+ "\n" //$NON-NLS-1$ |
551 |
+ exceptionTrace}; |
552 |
|
553 |
result |
554 |
.record( |
555 |
this.problemReporter |
556 |
.createProblem( |
557 |
result.getFileName(), |
558 |
IProblem.Unclassified, |
559 |
pbArguments, |
560 |
pbArguments, |
561 |
Error, // severity |
562 |
0, // source start |
563 |
0, // source end |
564 |
0, // line number |
565 |
0),// column number |
566 |
unit); |
567 |
|
568 |
/* hand back the compilation result */ |
569 |
if (!result.hasBeenAccepted) { |
570 |
this.requestor.acceptResult(result.tagAsAccepted()); |
571 |
needToPrint = false; |
572 |
} |
573 |
} |
574 |
if (needToPrint) { |
575 |
/* dump a stack trace to the console */ |
576 |
internalException.printStackTrace(); |
577 |
} |
578 |
} |
614 |
|
579 |
|
615 |
// Exception may tell which compilation result it is related, and which problem caused it |
580 |
/* |
616 |
CompilationResult result = abortException.compilationResult; |
581 |
* Compiler recovery in case of internal AbortCompilation event |
617 |
if (result == null && unit != null) { |
582 |
*/ |
618 |
result = unit.compilationResult; // current unit being processed ? |
583 |
protected void handleInternalException(AbortCompilation abortException, CompilationUnitDeclaration unit) { |
619 |
} |
584 |
/* special treatment for SilentAbort: silently cancelling the compilation process */ |
620 |
// Lookup environment may be in middle of connecting types |
585 |
if (abortException.isSilent) { |
621 |
if (result == null && this.lookupEnvironment.unitBeingCompleted != null) { |
586 |
if (abortException.silentException == null) { |
622 |
result = this.lookupEnvironment.unitBeingCompleted.compilationResult; |
587 |
return; |
623 |
} |
588 |
} |
624 |
if (result == null) { |
589 |
throw abortException.silentException; |
625 |
synchronized (this) { |
590 |
} |
626 |
if (this.unitsToProcess != null && this.totalUnits > 0) |
591 |
|
627 |
result = this.unitsToProcess[this.totalUnits - 1].compilationResult; |
592 |
/* uncomment following line to see where the abort came from */ |
628 |
} |
593 |
// abortException.printStackTrace(); |
629 |
} |
594 |
|
630 |
// last unit in beginToCompile ? |
595 |
// Exception may tell which compilation result it is related, and which problem caused it |
631 |
if (result != null && !result.hasBeenAccepted) { |
596 |
CompilationResult result = abortException.compilationResult; |
632 |
/* distant problem which could not be reported back there? */ |
597 |
if (result == null && unit != null) { |
633 |
if (abortException.problem != null) { |
598 |
result = unit.compilationResult; // current unit being processed ? |
634 |
recordDistantProblem: { |
599 |
} |
635 |
CategorizedProblem distantProblem = abortException.problem; |
600 |
// Lookup environment may be in middle of connecting types |
636 |
CategorizedProblem[] knownProblems = result.problems; |
601 |
if (result == null && this.lookupEnvironment.unitBeingCompleted != null) { |
637 |
for (int i = 0; i < result.problemCount; i++) { |
602 |
result = this.lookupEnvironment.unitBeingCompleted.compilationResult; |
638 |
if (knownProblems[i] == distantProblem) { // already recorded |
603 |
} |
639 |
break recordDistantProblem; |
604 |
if (result == null) { |
640 |
} |
605 |
synchronized (this) { |
|
|
606 |
if (this.unitsToProcess != null && this.totalUnits > 0) |
607 |
result = this.unitsToProcess[this.totalUnits - 1].compilationResult; |
608 |
} |
609 |
} |
610 |
// last unit in beginToCompile ? |
611 |
if (result != null && !result.hasBeenAccepted) { |
612 |
/* distant problem which could not be reported back there? */ |
613 |
if (abortException.problem != null) { |
614 |
recordDistantProblem: { |
615 |
CategorizedProblem distantProblem = abortException.problem; |
616 |
CategorizedProblem[] knownProblems = result.problems; |
617 |
for (int i = 0; i < result.problemCount; i++) { |
618 |
if (knownProblems[i] == distantProblem) { // already recorded |
619 |
break recordDistantProblem; |
641 |
} |
620 |
} |
642 |
if (distantProblem instanceof DefaultProblem) { // fixup filename TODO (philippe) should improve API to make this official |
|
|
643 |
((DefaultProblem) distantProblem).setOriginatingFileName(result.getFileName()); |
644 |
} |
645 |
result.record(distantProblem, unit); |
646 |
} |
621 |
} |
647 |
} else { |
622 |
if (distantProblem instanceof DefaultProblem) { // fixup filename TODO (philippe) should improve API to make this official |
648 |
/* distant internal exception which could not be reported back there */ |
623 |
((DefaultProblem) distantProblem).setOriginatingFileName(result.getFileName()); |
649 |
if (abortException.exception != null) { |
|
|
650 |
this.handleInternalException(abortException.exception, null, result); |
651 |
return; |
652 |
} |
624 |
} |
653 |
} |
625 |
result.record(distantProblem, unit); |
654 |
/* hand back the compilation result */ |
|
|
655 |
if (!result.hasBeenAccepted) { |
656 |
this.requestor.acceptResult(result.tagAsAccepted()); |
657 |
} |
626 |
} |
658 |
} else { |
627 |
} else { |
659 |
abortException.printStackTrace(); |
628 |
/* distant internal exception which could not be reported back there */ |
|
|
629 |
if (abortException.exception != null) { |
630 |
this.handleInternalException(abortException.exception, null, result); |
631 |
return; |
632 |
} |
660 |
} |
633 |
} |
|
|
634 |
/* hand back the compilation result */ |
635 |
if (!result.hasBeenAccepted) { |
636 |
this.requestor.acceptResult(result.tagAsAccepted()); |
637 |
} |
638 |
} else { |
639 |
abortException.printStackTrace(); |
661 |
} |
640 |
} |
|
|
641 |
} |
662 |
|
642 |
|
663 |
public void initializeParser() { |
643 |
public void initializeParser() { |
|
|
644 |
this.parser = new Parser(this.problemReporter, this.options.parseLiteralExpressionsAsConstants); |
645 |
} |
664 |
|
646 |
|
665 |
this.parser = new Parser(this.problemReporter, this.options.parseLiteralExpressionsAsConstants); |
647 |
/** |
666 |
} |
648 |
* Add the initial set of compilation units into the loop |
|
|
649 |
* -> build compilation unit declarations, their bindings and record their results. |
650 |
*/ |
651 |
protected void internalBeginToCompile(ICompilationUnit[] sourceUnits, int maxUnits) { |
652 |
if (!this.useSingleThread && maxUnits >= ReadManager.THRESHOLD) |
653 |
this.parser.readManager = new ReadManager(sourceUnits, maxUnits); |
667 |
|
654 |
|
668 |
/** |
655 |
// Switch the current policy and compilation result for this unit to the requested one. |
669 |
* Add the initial set of compilation units into the loop |
656 |
for (int i = 0; i < maxUnits; i++) { |
670 |
* -> build compilation unit declarations, their bindings and record their results. |
657 |
try { |
671 |
*/ |
658 |
if (this.options.verbose) { |
672 |
protected void internalBeginToCompile(ICompilationUnit[] sourceUnits, int maxUnits) { |
659 |
this.out.println( |
673 |
if (!this.useSingleThread && maxUnits >= ReadManager.THRESHOLD) |
660 |
Messages.bind(Messages.compilation_request, |
674 |
this.parser.readManager = new ReadManager(sourceUnits, maxUnits); |
661 |
new String[] { |
675 |
|
662 |
String.valueOf(i + 1), |
676 |
// Switch the current policy and compilation result for this unit to the requested one. |
663 |
String.valueOf(maxUnits), |
677 |
for (int i = 0; i < maxUnits; i++) { |
664 |
new String(sourceUnits[i].getFileName()) |
678 |
try { |
665 |
})); |
679 |
if (this.options.verbose) { |
|
|
680 |
this.out.println( |
681 |
Messages.bind(Messages.compilation_request, |
682 |
new String[] { |
683 |
String.valueOf(i + 1), |
684 |
String.valueOf(maxUnits), |
685 |
new String(sourceUnits[i].getFileName()) |
686 |
})); |
687 |
} |
688 |
// diet parsing for large collection of units |
689 |
CompilationUnitDeclaration parsedUnit; |
690 |
CompilationResult unitResult = |
691 |
new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); |
692 |
long parseStart = System.currentTimeMillis(); |
693 |
if (this.totalUnits < this.parseThreshold) { |
694 |
parsedUnit = this.parser.parse(sourceUnits[i], unitResult); |
695 |
} else { |
696 |
parsedUnit = this.parser.dietParse(sourceUnits[i], unitResult); |
697 |
} |
698 |
long resolveStart = System.currentTimeMillis(); |
699 |
this.stats.parseTime += resolveStart - parseStart; |
700 |
// initial type binding creation |
701 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
702 |
this.stats.resolveTime += System.currentTimeMillis() - resolveStart; |
703 |
addCompilationUnit(sourceUnits[i], parsedUnit); |
704 |
ImportReference currentPackage = parsedUnit.currentPackage; |
705 |
if (currentPackage != null) { |
706 |
unitResult.recordPackageName(currentPackage.tokens); |
707 |
} |
708 |
//} catch (AbortCompilationUnit e) { |
709 |
// requestor.acceptResult(unitResult.tagAsAccepted()); |
710 |
} finally { |
711 |
sourceUnits[i] = null; // no longer hold onto the unit |
712 |
} |
666 |
} |
|
|
667 |
// diet parsing for large collection of units |
668 |
CompilationUnitDeclaration parsedUnit; |
669 |
CompilationResult unitResult = |
670 |
new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); |
671 |
long parseStart = System.currentTimeMillis(); |
672 |
if (this.totalUnits < this.parseThreshold) { |
673 |
parsedUnit = this.parser.parse(sourceUnits[i], unitResult); |
674 |
} else { |
675 |
parsedUnit = this.parser.dietParse(sourceUnits[i], unitResult); |
676 |
} |
677 |
long resolveStart = System.currentTimeMillis(); |
678 |
this.stats.parseTime += resolveStart - parseStart; |
679 |
// initial type binding creation |
680 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
681 |
this.stats.resolveTime += System.currentTimeMillis() - resolveStart; |
682 |
addCompilationUnit(sourceUnits[i], parsedUnit); |
683 |
ImportReference currentPackage = parsedUnit.currentPackage; |
684 |
if (currentPackage != null) { |
685 |
unitResult.recordPackageName(currentPackage.tokens); |
686 |
} |
687 |
//} catch (AbortCompilationUnit e) { |
688 |
// requestor.acceptResult(unitResult.tagAsAccepted()); |
689 |
} finally { |
690 |
sourceUnits[i] = null; // no longer hold onto the unit |
713 |
} |
691 |
} |
714 |
if (this.parser.readManager != null) { |
|
|
715 |
this.parser.readManager.shutdown(); |
716 |
this.parser.readManager = null; |
717 |
} |
718 |
// binding resolution |
719 |
this.lookupEnvironment.completeTypeBindings(); |
720 |
} |
692 |
} |
|
|
693 |
if (this.parser.readManager != null) { |
694 |
this.parser.readManager.shutdown(); |
695 |
this.parser.readManager = null; |
696 |
} |
697 |
// binding resolution |
698 |
this.lookupEnvironment.completeTypeBindings(); |
699 |
} |
721 |
|
700 |
|
722 |
/** |
701 |
/** |
723 |
* Process a compilation unit already parsed and build. |
702 |
* Process a compilation unit already parsed and build. |
724 |
*/ |
703 |
*/ |
725 |
public void process(CompilationUnitDeclaration unit, int i) { |
704 |
public void process(CompilationUnitDeclaration unit, int i) { |
726 |
this.lookupEnvironment.unitBeingCompleted = unit; |
705 |
this.lookupEnvironment.unitBeingCompleted = unit; |
727 |
long parseStart = System.currentTimeMillis(); |
706 |
long parseStart = System.currentTimeMillis(); |
728 |
|
707 |
|
729 |
this.parser.getMethodBodies(unit); |
708 |
this.parser.getMethodBodies(unit); |
730 |
|
709 |
|
731 |
long resolveStart = System.currentTimeMillis(); |
710 |
long resolveStart = System.currentTimeMillis(); |
732 |
this.stats.parseTime += resolveStart - parseStart; |
711 |
this.stats.parseTime += resolveStart - parseStart; |
733 |
|
712 |
|
734 |
// fault in fields & methods |
713 |
// fault in fields & methods |
735 |
if (unit.scope != null) |
714 |
if (unit.scope != null) |
736 |
unit.scope.faultInTypes(); |
715 |
unit.scope.faultInTypes(); |
737 |
|
716 |
|
738 |
// verify inherited methods |
717 |
// verify inherited methods |
739 |
if (unit.scope != null) |
718 |
if (unit.scope != null) |
740 |
unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); |
719 |
unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); |
741 |
|
|
|
742 |
// type checking |
743 |
unit.resolve(); |
744 |
|
745 |
long analyzeStart = System.currentTimeMillis(); |
746 |
this.stats.resolveTime += analyzeStart - resolveStart; |
747 |
|
748 |
// flow analysis |
749 |
unit.analyseCode(); |
750 |
|
751 |
long generateStart = System.currentTimeMillis(); |
752 |
this.stats.analyzeTime += generateStart - analyzeStart; |
753 |
|
754 |
// code generation |
755 |
unit.generateCode(); |
756 |
|
757 |
// reference info |
758 |
if (this.options.produceReferenceInfo && unit.scope != null) |
759 |
unit.scope.storeDependencyInfo(); |
760 |
|
761 |
// finalize problems (suppressWarnings) |
762 |
unit.finalizeProblems(); |
763 |
|
764 |
this.stats.generateTime += System.currentTimeMillis() - generateStart; |
765 |
|
766 |
// refresh the total number of units known at this stage |
767 |
unit.compilationResult.totalUnitsKnown = this.totalUnits; |
768 |
|
769 |
this.lookupEnvironment.unitBeingCompleted = null; |
770 |
} |
771 |
|
772 |
protected void processAnnotations() { |
773 |
int newUnitSize = 0; |
774 |
int newClassFilesSize = 0; |
775 |
int bottom = 0; |
776 |
int top = this.totalUnits; |
777 |
ReferenceBinding[] binaryTypeBindingsTemp = this.referenceBindings; |
778 |
if (top == 0 && binaryTypeBindingsTemp == null) return; |
779 |
this.referenceBindings = null; |
780 |
do { |
781 |
// extract units to process |
782 |
int length = top - bottom; |
783 |
CompilationUnitDeclaration[] currentUnits = new CompilationUnitDeclaration[length]; |
784 |
int index = 0; |
785 |
for (int i = bottom; i < top; i++) { |
786 |
CompilationUnitDeclaration currentUnit = this.unitsToProcess[i]; |
787 |
if ((currentUnit.bits & ASTNode.IsImplicitUnit) == 0) { |
788 |
currentUnits[index++] = currentUnit; |
789 |
} |
790 |
} |
791 |
if (index != length) { |
792 |
System.arraycopy(currentUnits, 0, (currentUnits = new CompilationUnitDeclaration[index]), 0, index); |
793 |
} |
794 |
this.annotationProcessorManager.processAnnotations(currentUnits, binaryTypeBindingsTemp, false); |
795 |
ICompilationUnit[] newUnits = this.annotationProcessorManager.getNewUnits(); |
796 |
newUnitSize = newUnits.length; |
797 |
ReferenceBinding[] newClassFiles = this.annotationProcessorManager.getNewClassFiles(); |
798 |
binaryTypeBindingsTemp = newClassFiles; |
799 |
newClassFilesSize = newClassFiles.length; |
800 |
if (newUnitSize != 0) { |
801 |
// we reset the compiler in order to restart with the new units |
802 |
internalBeginToCompile(newUnits, newUnitSize); |
803 |
bottom = top; |
804 |
top = this.totalUnits; // last unit added |
805 |
} else { |
806 |
bottom = top; |
807 |
} |
808 |
this.annotationProcessorManager.reset(); |
809 |
} while (newUnitSize != 0 || newClassFilesSize != 0); |
810 |
// one more loop to create possible resources |
811 |
// this loop cannot create any java source files |
812 |
this.annotationProcessorManager.processAnnotations(null, null, true); |
813 |
// TODO we might want to check if this loop created new units |
814 |
} |
815 |
|
816 |
public void reset() { |
817 |
this.lookupEnvironment.reset(); |
818 |
this.parser.scanner.source = null; |
819 |
this.unitsToProcess = null; |
820 |
if (DebugRequestor != null) DebugRequestor.reset(); |
821 |
this.problemReporter.reset(); |
822 |
} |
823 |
|
720 |
|
824 |
/** |
721 |
// type checking |
825 |
* Internal API used to resolve a given compilation unit. Can run a subset of the compilation process |
722 |
unit.resolve(); |
826 |
*/ |
|
|
827 |
public CompilationUnitDeclaration resolve( |
828 |
CompilationUnitDeclaration unit, |
829 |
ICompilationUnit sourceUnit, |
830 |
boolean verifyMethods, |
831 |
boolean analyzeCode, |
832 |
boolean generateCode) { |
833 |
|
723 |
|
834 |
try { |
724 |
long analyzeStart = System.currentTimeMillis(); |
835 |
if (unit == null) { |
725 |
this.stats.resolveTime += analyzeStart - resolveStart; |
836 |
// build and record parsed units |
|
|
837 |
this.parseThreshold = 0; // will request a full parse |
838 |
beginToCompile(new ICompilationUnit[] { sourceUnit }); |
839 |
// process all units (some more could be injected in the loop by the lookup environment) |
840 |
unit = this.unitsToProcess[0]; |
841 |
} else { |
842 |
// initial type binding creation |
843 |
this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/); |
844 |
|
726 |
|
845 |
// binding resolution |
727 |
// flow analysis |
846 |
this.lookupEnvironment.completeTypeBindings(); |
728 |
unit.analyseCode(); |
847 |
} |
|
|
848 |
this.lookupEnvironment.unitBeingCompleted = unit; |
849 |
this.parser.getMethodBodies(unit); |
850 |
if (unit.scope != null) { |
851 |
// fault in fields & methods |
852 |
unit.scope.faultInTypes(); |
853 |
if (unit.scope != null && verifyMethods) { |
854 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=23117 |
855 |
// verify inherited methods |
856 |
unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); |
857 |
} |
858 |
// type checking |
859 |
unit.resolve(); |
860 |
|
729 |
|
861 |
// flow analysis |
730 |
long generateStart = System.currentTimeMillis(); |
862 |
if (analyzeCode) unit.analyseCode(); |
731 |
this.stats.analyzeTime += generateStart - analyzeStart; |
863 |
|
732 |
|
864 |
// code generation |
733 |
// code generation |
865 |
if (generateCode) unit.generateCode(); |
734 |
unit.generateCode(); |
866 |
|
735 |
|
867 |
// finalize problems (suppressWarnings) |
736 |
// reference info |
868 |
unit.finalizeProblems(); |
737 |
if (this.options.produceReferenceInfo && unit.scope != null) |
869 |
} |
738 |
unit.scope.storeDependencyInfo(); |
870 |
if (this.unitsToProcess != null) this.unitsToProcess[0] = null; // release reference to processed unit declaration |
|
|
871 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
872 |
return unit; |
873 |
} catch (AbortCompilation e) { |
874 |
this.handleInternalException(e, unit); |
875 |
return unit == null ? this.unitsToProcess[0] : unit; |
876 |
} catch (Error e) { |
877 |
this.handleInternalException(e, unit, null); |
878 |
throw e; // rethrow |
879 |
} catch (RuntimeException e) { |
880 |
this.handleInternalException(e, unit, null); |
881 |
throw e; // rethrow |
882 |
} finally { |
883 |
// leave this.lookupEnvironment.unitBeingCompleted set to the unit, until another unit is resolved |
884 |
// other calls to dom can cause classpath errors to be detected, resulting in AbortCompilation exceptions |
885 |
|
739 |
|
886 |
// No reset is performed there anymore since, |
740 |
// finalize problems (suppressWarnings) |
887 |
// within the CodeAssist (or related tools), |
741 |
unit.finalizeProblems(); |
888 |
// the compiler may be called *after* a call |
742 |
|
889 |
// to this resolve(...) method. And such a call |
743 |
this.stats.generateTime += System.currentTimeMillis() - generateStart; |
890 |
// needs to have a compiler with a non-empty |
744 |
|
891 |
// environment. |
745 |
// refresh the total number of units known at this stage |
892 |
// this.reset(); |
746 |
unit.compilationResult.totalUnitsKnown = this.totalUnits; |
|
|
747 |
|
748 |
this.lookupEnvironment.unitBeingCompleted = null; |
749 |
} |
750 |
|
751 |
protected void processAnnotations() { |
752 |
int newUnitSize = 0; |
753 |
int newClassFilesSize = 0; |
754 |
int bottom = 0; |
755 |
int top = this.totalUnits; |
756 |
ReferenceBinding[] binaryTypeBindingsTemp = this.referenceBindings; |
757 |
if (top == 0 && binaryTypeBindingsTemp == null) return; |
758 |
this.referenceBindings = null; |
759 |
do { |
760 |
// extract units to process |
761 |
int length = top - bottom; |
762 |
CompilationUnitDeclaration[] currentUnits = new CompilationUnitDeclaration[length]; |
763 |
int index = 0; |
764 |
for (int i = bottom; i < top; i++) { |
765 |
CompilationUnitDeclaration currentUnit = this.unitsToProcess[i]; |
766 |
if ((currentUnit.bits & ASTNode.IsImplicitUnit) == 0) { |
767 |
currentUnits[index++] = currentUnit; |
768 |
} |
769 |
} |
770 |
if (index != length) { |
771 |
System.arraycopy(currentUnits, 0, (currentUnits = new CompilationUnitDeclaration[index]), 0, index); |
772 |
} |
773 |
this.annotationProcessorManager.processAnnotations(currentUnits, binaryTypeBindingsTemp, false); |
774 |
ICompilationUnit[] newUnits = this.annotationProcessorManager.getNewUnits(); |
775 |
newUnitSize = newUnits.length; |
776 |
ReferenceBinding[] newClassFiles = this.annotationProcessorManager.getNewClassFiles(); |
777 |
binaryTypeBindingsTemp = newClassFiles; |
778 |
newClassFilesSize = newClassFiles.length; |
779 |
if (newUnitSize != 0) { |
780 |
// we reset the compiler in order to restart with the new units |
781 |
internalBeginToCompile(newUnits, newUnitSize); |
782 |
bottom = top; |
783 |
top = this.totalUnits; // last unit added |
784 |
} else { |
785 |
bottom = top; |
893 |
} |
786 |
} |
|
|
787 |
this.annotationProcessorManager.reset(); |
788 |
} while (newUnitSize != 0 || newClassFilesSize != 0); |
789 |
// one more loop to create possible resources |
790 |
// this loop cannot create any java source files |
791 |
this.annotationProcessorManager.processAnnotations(null, null, true); |
792 |
// TODO we might want to check if this loop created new units |
793 |
} |
794 |
|
795 |
public void reset() { |
796 |
this.lookupEnvironment.reset(); |
797 |
this.parser.scanner.source = null; |
798 |
this.unitsToProcess = null; |
799 |
if (DebugRequestor != null) DebugRequestor.reset(); |
800 |
this.problemReporter.reset(); |
801 |
} |
802 |
|
803 |
/** |
804 |
* Internal API used to resolve a given compilation unit. Can run a subset of the compilation process |
805 |
*/ |
806 |
public CompilationUnitDeclaration resolve(CompilationUnitDeclaration unit, ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { |
807 |
try { |
808 |
if (unit == null) { |
809 |
// build and record parsed units |
810 |
this.parseThreshold = 0; // will request a full parse |
811 |
beginToCompile(new ICompilationUnit[] { sourceUnit }); |
812 |
// process all units (some more could be injected in the loop by the lookup environment) |
813 |
unit = this.unitsToProcess[0]; |
814 |
} else { |
815 |
// initial type binding creation |
816 |
this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/); |
817 |
|
818 |
// binding resolution |
819 |
this.lookupEnvironment.completeTypeBindings(); |
820 |
} |
821 |
this.lookupEnvironment.unitBeingCompleted = unit; |
822 |
this.parser.getMethodBodies(unit); |
823 |
if (unit.scope != null) { |
824 |
// fault in fields & methods |
825 |
unit.scope.faultInTypes(); |
826 |
if (unit.scope != null && verifyMethods) { |
827 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=23117 |
828 |
// verify inherited methods |
829 |
unit.scope.verifyMethods(this.lookupEnvironment.methodVerifier()); |
830 |
} |
831 |
// type checking |
832 |
unit.resolve(); |
833 |
|
834 |
// flow analysis |
835 |
if (analyzeCode) unit.analyseCode(); |
836 |
|
837 |
// code generation |
838 |
if (generateCode) unit.generateCode(); |
839 |
|
840 |
// finalize problems (suppressWarnings) |
841 |
unit.finalizeProblems(); |
842 |
} |
843 |
if (this.unitsToProcess != null) this.unitsToProcess[0] = null; // release reference to processed unit declaration |
844 |
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted()); |
845 |
return unit; |
846 |
} catch (AbortCompilation e) { |
847 |
this.handleInternalException(e, unit); |
848 |
return unit == null ? this.unitsToProcess[0] : unit; |
849 |
} catch (Error e) { |
850 |
this.handleInternalException(e, unit, null); |
851 |
throw e; // rethrow |
852 |
} catch (RuntimeException e) { |
853 |
this.handleInternalException(e, unit, null); |
854 |
throw e; // rethrow |
855 |
} finally { |
856 |
// leave this.lookupEnvironment.unitBeingCompleted set to the unit, until another unit is resolved |
857 |
// other calls to dom can cause classpath errors to be detected, resulting in AbortCompilation exceptions |
858 |
|
859 |
// No reset is performed there anymore since, |
860 |
// within the CodeAssist (or related tools), |
861 |
// the compiler may be called *after* a call |
862 |
// to this resolve(...) method. And such a call |
863 |
// needs to have a compiler with a non-empty |
864 |
// environment. |
865 |
// this.reset(); |
894 |
} |
866 |
} |
895 |
/** |
867 |
} |
896 |
* Internal API used to resolve a given compilation unit. Can run a subset of the compilation process |
868 |
/** |
897 |
*/ |
869 |
* Internal API used to resolve a given compilation unit. Can run a subset of the compilation process |
898 |
public CompilationUnitDeclaration resolve( |
870 |
*/ |
899 |
ICompilationUnit sourceUnit, |
871 |
public CompilationUnitDeclaration resolve(ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { |
900 |
boolean verifyMethods, |
872 |
return resolve(null, sourceUnit, verifyMethods, analyzeCode, |
901 |
boolean analyzeCode, |
873 |
generateCode); |
902 |
boolean generateCode) { |
874 |
} |
903 |
|
|
|
904 |
return resolve( |
905 |
null, |
906 |
sourceUnit, |
907 |
verifyMethods, |
908 |
analyzeCode, |
909 |
generateCode); |
910 |
} |
911 |
} |
875 |
} |