public class DeclareAnnotationDeclaration extends DeclareDeclaration {
- private Annotation annotation;
+// private Annotation[] annotation;
private boolean isRemover = false;
- public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation annotation) {
+ public DeclareAnnotationDeclaration(CompilationResult result, DeclareAnnotation symbolicDeclare, Annotation[] annotations) {
super(result, symbolicDeclare);
- this.annotation = annotation;
+// this.annotations = annotations;
- addAnnotation(annotation);
+ for (int a=0;a<annotations.length;a++) {
+ addAnnotation(annotations[a]);
+ }
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);
+ StringBuilder sb = new StringBuilder();
+ for (int a=0;a<annotations.length;a++) {
+ if (a>0) {
+ sb.append(" ");
+ }
+ sb.append(annotations[a].toString());
+ }
+ symbolicDeclare.setAnnotationString(sb.toString());
+ symbolicDeclare.setAnnotationLocation(annotations[0].sourceStart, annotations[annotations.length-1].sourceEnd);
}
-
+
public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo flowInfo) {
super.analyseCode(classScope, initializationContext, flowInfo);
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)");
+ else if (isRemover) { // && !(annotation instanceof MarkerAnnotation)) {
+ for (int a=0;a<annotations.length;a++) {
+ if (!(annotations[a] 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) {
- // The annotation is stored against a method. For declare @type we need to
- // confirm the annotation targets the right types. Earlier checking will
- // have not found this problem because an annotation for target METHOD will
- // not be reported on as we *do* store it against a method in this case
- DeclareAnnotation.Kind k = ((DeclareAnnotation) declareDecl).getKind();
- if (k.equals(DeclareAnnotation.AT_TYPE)) {
- if ((bits & TagBits.AnnotationForMethod) != 0) {
- classScope.problemReporter().disallowedTargetForAnnotation(annotation);
+ for (int a=0;a<annotations.length;a++) {
+ long bits = annotations[a].resolvedType.getAnnotationTagBits();
+
+ if ((bits & TagBits.AnnotationTarget) != 0) {
+ // The annotation is stored against a method. For declare @type we need to
+ // confirm the annotation targets the right types. Earlier checking will
+ // have not found this problem because an annotation for target METHOD will
+ // not be reported on as we *do* store it against a method in this case
+ DeclareAnnotation.Kind k = ((DeclareAnnotation) declareDecl).getKind();
+ if (k.equals(DeclareAnnotation.AT_TYPE)) {
+ if ((bits & TagBits.AnnotationForMethod) != 0) {
+ classScope.problemReporter().disallowedTargetForAnnotation(annotations[a]);
+ }
}
- }
- if (k.equals(DeclareAnnotation.AT_FIELD)) {
- if ((bits & TagBits.AnnotationForMethod) != 0) {
- classScope.problemReporter().disallowedTargetForAnnotation(annotation);
+ if (k.equals(DeclareAnnotation.AT_FIELD)) {
+ if ((bits & TagBits.AnnotationForMethod) != 0) {
+ classScope.problemReporter().disallowedTargetForAnnotation(annotations[a]);
+ }
}
}
}
}
- public Annotation getDeclaredAnnotation() {
- return annotation;
+ public Annotation[] getDeclaredAnnotations() {
+ return annotations;
}
protected boolean shouldDelegateCodeGeneration() {
private ResolvedType containingAspect;
private List<String> annotationMethods;
private List<String> annotationStrings;
- private AnnotationAJ annotation; // discovered when required
- private ResolvedType annotationType; // discovered when required
+ private AnnotationAJ[] annotations; // discovered when required
+ private ResolvedType[] annotationTypes; // discovered when required
// not serialized:
private int annotationStart;
}
ret.annotationMethods = this.annotationMethods;
ret.annotationStrings = this.annotationStrings;
- ret.annotation = this.annotation;
+ ret.annotations = this.annotations;
ret.containingAspect = this.containingAspect;
ret.copyLocationFrom(this);
return ret;
* finds that method and retrieves the annotation
*/
private void ensureAnnotationDiscovered() {
- if (annotation != null) {
+ if (annotations != null) {
return;
}
String annotationMethod = annotationMethods.get(0);
/**
* @return the type of the annotation
*/
- public ResolvedType getAnnotationType() {
- if (annotationType == null) {
+ public ResolvedType[] getAnnotationTypes() {
+ if (annotationTypes == null) {
String annotationMethod = annotationMethods.get(0);
+ List<ResolvedType> annoTypesToStore = new ArrayList<ResolvedType>();
for (Iterator<ResolvedMember> iter = containingAspect.getMethods(true, true); iter.hasNext();) {
ResolvedMember member = iter.next();
if (member.getName().equals(annotationMethod)) {
return null;
}
int idx = 0;
- if (annoTypes[0].getSignature().equals("Lorg/aspectj/internal/lang/annotation/ajcDeclareAnnotation;")) {
- idx = 1;
+ for (int i=0;i<annoTypes.length;i++) {
+ if (!annoTypes[0].getSignature().equals("Lorg/aspectj/internal/lang/annotation/ajcDeclareAnnotation;")) {
+ annoTypesToStore.add(annoTypes[i]);
+ }
}
- annotationType = annoTypes[idx];
+// if (annoTypes[0].getSignature().equals("Lorg/aspectj/internal/lang/annotation/ajcDeclareAnnotation;")) {
+// idx = 1;
+// }
+ annotationTypes = annoTypesToStore.toArray(new ResolvedType[annoTypesToStore.size()]);//annoTypes[idx];
break;
}
}
}
- return annotationType;
- }
-
- /**
- * @return true if the annotation specified is allowed on a field
- */
- public boolean isAnnotationAllowedOnField() {
- ensureAnnotationDiscovered();
- return annotation.allowedOnField();
+ return annotationTypes;
}
public String getPatternAsString() {