Lines 40-45
Link Here
|
40 |
// ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD |
40 |
// ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD |
41 |
public static boolean DEBUG = false; |
41 |
public static boolean DEBUG = false; |
42 |
public int parseThreshold = -1; |
42 |
public int parseThreshold = -1; |
|
|
43 |
|
44 |
public AnnotationProcessorManager annotationProcessorManager; |
45 |
|
43 |
// number of initial units parsed at once (-1: none) |
46 |
// number of initial units parsed at once (-1: none) |
44 |
|
47 |
|
45 |
/* |
48 |
/* |
Lines 354-387
Link Here
|
354 |
CompilationUnitDeclaration parsedUnit; |
357 |
CompilationUnitDeclaration parsedUnit; |
355 |
CompilationResult unitResult = |
358 |
CompilationResult unitResult = |
356 |
new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); |
359 |
new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); |
357 |
try { |
|
|
358 |
if (options.verbose) { |
359 |
this.out.println( |
360 |
Messages.bind(Messages.compilation_request, |
361 |
new String[] { |
362 |
String.valueOf(i + 1), |
363 |
String.valueOf(maxUnits), |
364 |
new String(sourceUnits[i].getFileName()) |
365 |
})); |
366 |
} |
367 |
// diet parsing for large collection of units |
368 |
if (totalUnits < parseThreshold) { |
369 |
parsedUnit = parser.parse(sourceUnits[i], unitResult); |
370 |
} else { |
371 |
parsedUnit = parser.dietParse(sourceUnits[i], unitResult); |
372 |
} |
373 |
// initial type binding creation |
374 |
lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
375 |
this.addCompilationUnit(sourceUnits[i], parsedUnit); |
376 |
ImportReference currentPackage = parsedUnit.currentPackage; |
360 |
ImportReference currentPackage = parsedUnit.currentPackage; |
377 |
if (currentPackage != null) { |
361 |
if (currentPackage != null) { |
378 |
unitResult.recordPackageName(currentPackage.tokens); |
362 |
unitResult.recordPackageName(currentPackage.tokens); |
379 |
} |
363 |
} |
380 |
//} catch (AbortCompilationUnit e) { |
364 |
if (options.verbose) { |
381 |
// requestor.acceptResult(unitResult.tagAsAccepted()); |
365 |
this.out.println( |
382 |
} finally { |
366 |
Messages.bind(Messages.compilation_request, |
383 |
sourceUnits[i] = null; // no longer hold onto the unit |
367 |
new String[] { |
|
|
368 |
String.valueOf(i + 1), |
369 |
String.valueOf(maxUnits), |
370 |
new String(sourceUnits[i].getFileName()) |
371 |
})); |
372 |
} |
373 |
// diet parsing for large collection of units |
374 |
if (totalUnits < parseThreshold) { |
375 |
parsedUnit = parser.parse(sourceUnits[i], unitResult); |
376 |
} else { |
377 |
parsedUnit = parser.dietParse(sourceUnits[i], unitResult); |
384 |
} |
378 |
} |
|
|
379 |
// initial type binding creation |
380 |
lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
381 |
this.addCompilationUnit(sourceUnits[i], parsedUnit); |
382 |
//} catch (AbortCompilationUnit e) { |
383 |
// requestor.acceptResult(unitResult.tagAsAccepted()); |
385 |
} |
384 |
} |
386 |
// binding resolution |
385 |
// binding resolution |
387 |
lookupEnvironment.completeTypeBindings(); |
386 |
lookupEnvironment.completeTypeBindings(); |
Lines 394-407
Link Here
|
394 |
*/ |
393 |
*/ |
395 |
public void compile(ICompilationUnit[] sourceUnits) { |
394 |
public void compile(ICompilationUnit[] sourceUnits) { |
396 |
CompilationUnitDeclaration unit = null; |
395 |
CompilationUnitDeclaration unit = null; |
397 |
int i = 0; |
|
|
398 |
try { |
396 |
try { |
399 |
// build and record parsed units |
397 |
// build and record parsed units |
400 |
|
398 |
|
401 |
beginToCompile(sourceUnits); |
399 |
beginToCompile(sourceUnits); |
402 |
|
400 |
|
|
|
401 |
if (annotationProcessorManager != null) { |
402 |
processAnnotations(sourceUnits); |
403 |
} |
403 |
// process all units (some more could be injected in the loop by the lookup environment) |
404 |
// process all units (some more could be injected in the loop by the lookup environment) |
404 |
for (; i < this.totalUnits; i++) { |
405 |
for (int i = 0; i < this.totalUnits; i++) { |
405 |
unit = unitsToProcess[i]; |
406 |
unit = unitsToProcess[i]; |
406 |
try { |
407 |
try { |
407 |
if (options.verbose) |
408 |
if (options.verbose) |
Lines 450-455
Link Here
|
450 |
} |
451 |
} |
451 |
} |
452 |
} |
452 |
|
453 |
|
|
|
454 |
protected void processAnnotations(ICompilationUnit[] sourceUnits) { |
455 |
int newUnitSize = 0; |
456 |
do { |
457 |
for (int i = 0; i < this.totalUnits; i++) { |
458 |
CompilationUnitDeclaration unit = unitsToProcess[i]; |
459 |
this.annotationProcessorManager.processAnnotations(unit); |
460 |
} |
461 |
List newUnits = this.annotationProcessorManager.getNewUnits(); |
462 |
newUnitSize = newUnits.size(); |
463 |
ICompilationUnit[] newSourceUnits = sourceUnits; |
464 |
if (newUnitSize != 0) { |
465 |
// we reset the compiler in order to restart with the new units |
466 |
this.reset(); |
467 |
int sourceUnitsLength = sourceUnits.length; |
468 |
ICompilationUnit[] newSourceUnits = new ICompilationUnit[sourceUnitsLength + newUnitSize]; |
469 |
newUnits.toArray(newSourceUnits); |
470 |
System.arraycopy(sourceUnits, 0, newSourceUnits, newUnitSize, sourceUnitsLength); |
471 |
beginToCompile(newSourceUnits); |
472 |
this.annotationProcessorManager.reset(); |
473 |
} |
474 |
} while (newUnitSize != 0);` |
475 |
// one more loop to create possible resources |
476 |
// this loop cannot create any java source files |
477 |
for (int i = 0; i < this.totalUnits; i++) { |
478 |
CompilationUnitDeclaration unit = unitsToProcess[i]; |
479 |
this.annotationProcessorManager.processAnnotations(unit); |
480 |
} |
481 |
List newUnits = this.annotationProcessorManager.getNewUnits(); |
482 |
if (newUnits.size() != 0) { |
483 |
// report error |
484 |
} |
485 |
} |
486 |
|
453 |
/* |
487 |
/* |
454 |
* Compiler crash recovery in case of unexpected runtime exceptions |
488 |
* Compiler crash recovery in case of unexpected runtime exceptions |
455 |
*/ |
489 |
*/ |