### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.compiler.apt Index: batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java,v retrieving revision 1.4 diff -u -r1.4 AnnotationDiscoveryVisitor.java --- batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java 16 Jan 2007 04:56:49 -0000 1.4 +++ batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java 8 Feb 2007 04:31:59 -0000 @@ -22,10 +22,7 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; -import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; -import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; -import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; @@ -40,39 +37,50 @@ */ public class AnnotationDiscoveryVisitor extends ASTVisitor { - Binding currentBinding; - boolean storeAnnotations; - /** * Collects a many-to-many map of annotation types to * the elements they appear on. */ ManyToMany _annoToElement; + boolean storeAnnotations; + public AnnotationDiscoveryVisitor() { this._annoToElement = new ManyToMany(); } + @Override + public void endVisit(CompilationUnitDeclaration compilationUnitDeclaration, CompilationUnitScope scope) { + scope.compilerOptions().storeAnnotations = this.storeAnnotations; + } + + @Override public boolean visit(Argument argument, BlockScope scope) { - this.currentBinding = argument.binding; Annotation[] annotations = argument.annotations; if (annotations != null) { - int annotationsLength = annotations.length; - for (int i = 0; i < annotationsLength; i++) { - annotations[i].traverse(this, scope); - } + this.resolveAnnotations( + scope, + annotations, + argument.binding); } return false; } + @Override + public boolean visit(CompilationUnitDeclaration compilationUnitDeclaration, CompilationUnitScope scope) { + this.storeAnnotations = scope.compilerOptions().storeAnnotations; + scope.compilerOptions().storeAnnotations = true; + return true; + } + + @Override public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) { - this.currentBinding = constructorDeclaration.binding; Annotation[] annotations = constructorDeclaration.annotations; if (annotations != null) { - int annotationsLength = annotations.length; - for (int i = 0; i < annotationsLength; i++) { - annotations[i].traverse(this, constructorDeclaration.scope); - } + this.resolveAnnotations( + constructorDeclaration.scope, + annotations, + constructorDeclaration.binding); } Argument[] arguments = constructorDeclaration.arguments; if (arguments != null) { @@ -84,35 +92,25 @@ return false; } + @Override public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { - this.currentBinding = fieldDeclaration.binding; Annotation[] annotations = fieldDeclaration.annotations; if (annotations != null) { - int annotationsLength = annotations.length; - for (int i = 0; i < annotationsLength; i++) { - annotations[i].traverse(this, scope); - } + this.resolveAnnotations(scope, annotations, fieldDeclaration.binding); } return false; } - public void endVisit(MarkerAnnotation annotation, BlockScope scope) { - ASTNode.resolveAnnotations(scope, new Annotation[] { annotation }, this.currentBinding); - AnnotationBinding binding = annotation.getCompilerAnnotation(); - TypeElement anno = (TypeElement)ElementFactory.newElement(binding.getAnnotationType()); - Element element = ElementFactory.newElement(this.currentBinding); - _annoToElement.put(anno, element); - } - + @Override public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { - this.currentBinding = methodDeclaration.binding; Annotation[] annotations = methodDeclaration.annotations; if (annotations != null) { - int annotationsLength = annotations.length; - for (int i = 0; i < annotationsLength; i++) { - annotations[i].traverse(this, methodDeclaration.scope); - } + this.resolveAnnotations( + methodDeclaration.scope, + annotations, + methodDeclaration.binding); } + Argument[] arguments = methodDeclaration.arguments; if (arguments != null) { int argumentLength = arguments.length; @@ -123,54 +121,41 @@ return false; } - public void endVisit(NormalAnnotation annotation, BlockScope scope) { - ASTNode.resolveAnnotations(scope, new Annotation[] { annotation }, this.currentBinding); - AnnotationBinding binding = annotation.getCompilerAnnotation(); - TypeElement anno = (TypeElement)ElementFactory.newElement(binding.getAnnotationType()); - Element element = ElementFactory.newElement(this.currentBinding); - _annoToElement.put(anno, element); - } - - public void endVisit(SingleMemberAnnotation annotation, BlockScope scope) { - ASTNode.resolveAnnotations(scope, new Annotation[] { annotation }, this.currentBinding); - AnnotationBinding binding = annotation.getCompilerAnnotation(); - TypeElement anno = (TypeElement)ElementFactory.newElement(binding.getAnnotationType()); - Element element = ElementFactory.newElement(this.currentBinding); - _annoToElement.put(anno, element); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, - * org.eclipse.jdt.internal.compiler.lookup.ClassScope) - */ + @Override public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { - this.currentBinding = memberTypeDeclaration.binding; + Annotation[] annotations = memberTypeDeclaration.annotations; + if (annotations != null) { + this.resolveAnnotations( + memberTypeDeclaration.staticInitializerScope, + annotations, + memberTypeDeclaration.binding); + } return true; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, - * org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope) - */ + @Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { - this.currentBinding = typeDeclaration.binding; + Annotation[] annotations = typeDeclaration.annotations; + if (annotations != null) { + this.resolveAnnotations( + typeDeclaration.staticInitializerScope, + annotations, + typeDeclaration.binding); + } return true; } - @Override - public void endVisit(CompilationUnitDeclaration compilationUnitDeclaration, CompilationUnitScope scope) { - scope.compilerOptions().storeAnnotations = this.storeAnnotations; - } - - @Override - public boolean visit(CompilationUnitDeclaration compilationUnitDeclaration, CompilationUnitScope scope) { - this.storeAnnotations = scope.compilerOptions().storeAnnotations; - scope.compilerOptions().storeAnnotations = true; - return true; + private void resolveAnnotations( + BlockScope scope, + Annotation[] annotations, + Binding currentBinding) { + ASTNode.resolveAnnotations(scope, annotations, currentBinding); + + for (Annotation annotation : annotations) { + AnnotationBinding binding = annotation.getCompilerAnnotation(); + TypeElement anno = (TypeElement)ElementFactory.newElement(binding.getAnnotationType()); + Element element = ElementFactory.newElement(currentBinding); + _annoToElement.put(anno, element); + } } - }