View | Details | Raw Unified | Return to bug 160773 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/Compiler.java (-25 / +59 lines)
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
	 */
(-)compiler/org/eclipse/jdt/internal/compiler/AnnotationProcessorManager.java (+37 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
7
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
8
9
public class AnnotationProcessorManager {
10
	List addedUnits;
11
	
12
	public static AnnotationProcessorManager configure(String[] commandLineArguments) {
13
		return new AnnotationProcessorManager();
14
	}
15
	
16
	private AnnotationProcessorManager() {
17
		this.addedUnits = new ArrayList();
18
	}
19
20
	public void processAnnotations(CompilationUnitDeclaration unit) {
21
		// do nothing
22
	}
23
	
24
	public void addNewUnit(ICompilationUnit unit) {
25
		this.addedUnits.add(unit);
26
	}
27
28
	public List getNewUnits() {
29
		return this.addedUnits;
30
	}
31
	
32
	public void reset() {
33
		this.addedUnits.clear();
34
	}
35
	
36
	
37
}
(-)compiler/org/eclipse/jdt/internal/compiler/AnnotationDiscoveryVisitor.java (+114 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
7
import org.eclipse.jdt.internal.compiler.ast.Annotation;
8
import org.eclipse.jdt.internal.compiler.ast.Argument;
9
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
10
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
11
import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
12
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
13
import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation;
14
import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
15
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
17
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
18
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
19
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
20
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
21
22
public class AnnotationDiscoveryVisitor extends ASTVisitor {
23
24
Binding currentBinding;
25
List collector;
26
public AnnotationDiscoveryVisitor() {
27
	this.collector = new ArrayList();
28
}
29
public boolean visit(Argument argument, BlockScope scope) {
30
	this.currentBinding = argument.binding;
31
	Annotation[] annotations = argument.annotations;
32
	if (annotations != null) {
33
		int annotationsLength = annotations.length;
34
		for (int i = 0; i < annotationsLength; i++) {
35
			annotations[i].traverse(this, scope);
36
		}
37
	}
38
	return false;
39
}
40
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
41
	this.currentBinding = constructorDeclaration.binding;
42
	Annotation[] annotations = constructorDeclaration.annotations;
43
	if (annotations != null) {
44
		int annotationsLength = annotations.length;
45
		for (int i = 0; i < annotationsLength; i++) {
46
			annotations[i].traverse(this, constructorDeclaration.scope);
47
		}
48
	}
49
	Argument[] arguments = constructorDeclaration.arguments;
50
	if (arguments != null) {
51
		int argumentLength = arguments.length;
52
		for (int i = 0; i < argumentLength; i++) {
53
			arguments[i].traverse(this, constructorDeclaration.scope);
54
		}
55
	}	
56
	return false;
57
}
58
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
59
	this.currentBinding = fieldDeclaration.binding;
60
	Annotation[] annotations = fieldDeclaration.annotations;
61
	if (annotations != null) {
62
		int annotationsLength = annotations.length;
63
		for (int i = 0; i < annotationsLength; i++) {
64
			annotations[i].traverse(this, scope);
65
		}
66
	}
67
	return false;
68
}
69
public void endVisit(MarkerAnnotation annotation, BlockScope scope) {
70
	ASTNode.resolveAnnotations(scope, new Annotation[] { annotation}, this.currentBinding);
71
	collector.add(annotation.getCompilerAnnotation());
72
}
73
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
74
	this.currentBinding = methodDeclaration.binding;
75
	Annotation[] annotations = methodDeclaration.annotations;
76
	if (annotations != null) {
77
		int annotationsLength = annotations.length;
78
		for (int i = 0; i < annotationsLength; i++) {
79
			annotations[i].traverse(this, methodDeclaration.scope);
80
		}
81
	}
82
	Argument[] arguments = methodDeclaration.arguments;
83
	if (arguments != null) {
84
		int argumentLength = arguments.length;
85
		for (int i = 0; i < argumentLength; i++) {
86
			arguments[i].traverse(this, methodDeclaration.scope);
87
		}
88
	}	
89
	return false;
90
}
91
public void endVisit(NormalAnnotation annotation, BlockScope scope) {
92
	ASTNode.resolveAnnotations(scope, new Annotation[] { annotation}, this.currentBinding);
93
	this.collector.add(annotation.getCompilerAnnotation());
94
}
95
public void endVisit(SingleMemberAnnotation annotation, BlockScope scope) {
96
	ASTNode.resolveAnnotations(scope, new Annotation[] { annotation}, this.currentBinding);
97
	this.collector.add(annotation.getCompilerAnnotation());
98
}
99
/* (non-Javadoc)
100
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, org.eclipse.jdt.internal.compiler.lookup.ClassScope)
101
 */
102
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
103
	this.currentBinding = memberTypeDeclaration.binding;
104
	return true;
105
}
106
/* (non-Javadoc)
107
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope)
108
 */
109
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) {
110
	this.currentBinding = typeDeclaration.binding;
111
	return true;
112
}
113
114
}

Return to bug 160773