]> source.dussan.org Git - aspectj.git/commitdiff
annotation removal - extra checks
authoraclement <aclement>
Sat, 27 Nov 2010 06:23:21 +0000 (06:23 +0000)
committeraclement <aclement>
Sat, 27 Nov 2010 06:23:21 +0000 (06:23 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/DeclarationFactory.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java

index f1cc2f1664264cbc89c9edc8e3c53342696205f2..7f1880590c40c8550cc52583cd287e2a48db91a6 100644 (file)
@@ -15,6 +15,7 @@ package org.aspectj.ajdt.internal.compiler.ast;
 
 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.flow.FlowInfo;
 import org.aspectj.org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext;
@@ -25,6 +26,7 @@ import org.aspectj.weaver.patterns.DeclareAnnotation;
 public class DeclareAnnotationDeclaration extends DeclareDeclaration {
 
        private Annotation annotation;
+       private boolean isRemover = false;
 
        public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation) {
                super(result, symbolicDeclare);
@@ -34,6 +36,7 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration {
                if (symbolicDeclare == null) {
                        return; // there is an error that will already be getting reported (e.g. incorrect pattern on decaf/decac)
                }
+               this.isRemover = symbolicDeclare.isRemover();
                symbolicDeclare.setAnnotationString(annotation.toString());
                symbolicDeclare.setAnnotationLocation(annotation.sourceStart, annotation.sourceEnd);
        }
@@ -41,6 +44,16 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration {
        public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo flowInfo) {
                super.analyseCode(classScope, initializationContext, flowInfo);
 
+               if (isRemover) {
+                       if (((DeclareAnnotation) declareDecl).getKind() != DeclareAnnotation.AT_FIELD) {
+                               classScope.problemReporter().signalError(this.sourceStart(), this.sourceEnd,
+                                               "Annotation removal only supported for declare @field (compiler limitation)");
+                       }
+                       else if (isRemover && !(annotation instanceof MarkerAnnotation)) {
+                               classScope.problemReporter().signalError(this.sourceStart(), this.sourceEnd,
+                                               "Annotation removal does not allow values to be specified for the annotation (compiler limitation)");
+                       }
+               }
                long bits = annotation.resolvedType.getAnnotationTagBits();
 
                if ((bits & TagBits.AnnotationTarget) != 0) {
@@ -78,7 +91,8 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration {
        private void addAnnotation(Annotation ann) {
                if (this.annotations == null) {
                        this.annotations = new Annotation[1];
-               } else {
+               }
+               else {
                        Annotation[] old = this.annotations;
                        this.annotations = new Annotation[old.length + 1];
                        System.arraycopy(old, 0, this.annotations, 1, old.length);
@@ -93,4 +107,7 @@ public class DeclareAnnotationDeclaration extends DeclareDeclaration {
                }
        }
 
+       public boolean isRemover() {
+               return isRemover;
+       }
 }
index be12049fddc4981f8e1f9826fdf753d74f90b21b..5cc6bd37c80426a716376cfbcd260db9f51477d6 100644 (file)
@@ -146,8 +146,10 @@ public class DeclarationFactory implements IDeclarationFactory {
        public MethodDeclaration createDeclareAnnotationDeclaration(CompilationResult result, ASTNode pseudoTokens,
                        Annotation annotation, Parser parser, char kind) {
                DeclareAnnotation declare = (DeclareAnnotation) ((PseudoTokens) pseudoTokens).parseAnnotationDeclare(parser);
-               if (kind == '-') {
-                       declare.setRemover(true);
+               if (declare != null) {
+                       if (kind == '-') {
+                               declare.setRemover(true);
+                       }
                }
                DeclareAnnotationDeclaration decl = new DeclareAnnotationDeclaration(result, declare, annotation);
                return decl;
index 31f50a573f4316c59695df2b0d71845c452e0833..1cbaf124f2c4d20008db0870b6c320fe563cd7fa 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.DeclareAnnotationDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.Proceed;
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
@@ -684,5 +685,15 @@ public class AjProblemReporter extends ProblemReporter {
                        super.parseErrorInsertAfterToken(start, end, currentKind, errorTokenSource, errorTokenName, expectedToken);
                }
        }
+       
+       public void missingValueForAnnotationMember(Annotation annotation, char[] memberName) {
+               if (referenceContext instanceof DeclareAnnotationDeclaration)  {
+                       // If a remover then the values are not necessary
+                       if (((DeclareAnnotationDeclaration)referenceContext).isRemover()) {
+                               return;
+                       }
+               }
+               super.missingValueForAnnotationMember(annotation, memberName);
+       }
 
 }