From edfe7deb9e56272d31c8dadfa15c1907cad5e4da Mon Sep 17 00:00:00 2001 From: aclement Date: Sat, 27 Nov 2010 06:23:21 +0000 Subject: [PATCH] annotation removal - extra checks --- .../ast/DeclareAnnotationDeclaration.java | 19 ++++++++++++++++++- .../compiler/parser/DeclarationFactory.java | 6 ++++-- .../compiler/problem/AjProblemReporter.java | 11 +++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java index f1cc2f166..7f1880590 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareAnnotationDeclaration.java @@ -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; + } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/DeclarationFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/DeclarationFactory.java index be12049fd..5cc6bd37c 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/DeclarationFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/DeclarationFactory.java @@ -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; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java index 31f50a573..1cbaf124f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java @@ -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); + } } -- 2.39.5