From: aclement Date: Mon, 25 Feb 2008 22:10:36 +0000 (+0000) Subject: annoValMatch: implementation X-Git-Tag: V1_6_0M2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0a10381d5cfe599acea374aa96019849b42900b;p=aspectj.git annoValMatch: implementation --- diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java index 060d2956a..0dafaedd7 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java @@ -11,15 +11,20 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Set; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.AnnotatedElement; +import org.aspectj.weaver.AnnotationX; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.TypeVariableReference; import org.aspectj.weaver.UnresolvedType; @@ -37,11 +42,20 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { protected String formalName; protected boolean resolved = false; private boolean bindingPattern = false; + private Map annotationValues; /** + * @param annotationValues * */ - public ExactAnnotationTypePattern(UnresolvedType annotationType) { + public ExactAnnotationTypePattern(UnresolvedType annotationType, Map annotationValues) { + this.annotationType = annotationType; + this.annotationValues = annotationValues; + this.resolved = (annotationType instanceof ResolvedType); + } + + // Used when deserializing, values will be added + private ExactAnnotationTypePattern(UnresolvedType annotationType) { this.annotationType = annotationType; this.resolved = (annotationType instanceof ResolvedType); } @@ -61,9 +75,13 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { public UnresolvedType getAnnotationType() { return annotationType; } + + public Map getAnnotationValues() { + return annotationValues; + } public FuzzyBoolean fastMatches(AnnotatedElement annotated) { - if (annotated.hasAnnotation(annotationType)) { + if (annotated.hasAnnotation(annotationType) && annotationValues == null) { return FuzzyBoolean.YES; } else { // could be inherited, but we don't know that until we are @@ -94,11 +112,73 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { return FuzzyBoolean.NO; } } + + + // Are we also matching annotation values? + if (annotationValues!=null) { + AnnotationX theAnnotation = annotated.getAnnotationOfType(annotationType); + + // Check each one + Set keys = annotationValues.keySet(); + for (Iterator keyIter = keys.iterator(); keyIter.hasNext();) { + String k = (String) keyIter.next(); + String v = (String)annotationValues.get(k); + if (theAnnotation.hasNamedValue(k)) { + // Simple case, value is 'name=value' and the annotation specified the same thing + if (!theAnnotation.hasNameValuePair(k,v)) { + return FuzzyBoolean.NO; + } + } else { + // Complex case, look at the default value + ResolvedMember[] ms = ((ResolvedType)annotationType).getDeclaredMethods(); + boolean foundMatch = false; + for (int i=0; i VERSION) { throw new BCException("ExactAnnotationTypePattern was written by a newer version of AspectJ"); @@ -259,6 +358,18 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { if (s.getMajorVersion()>=WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ160) { if (s.readBoolean()) ret.setForParameterAnnotationMatch(); } + if (s.getMajorVersion()>=WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ160M2) { + int annotationValueCount = s.readInt(); + if (annotationValueCount>0) { + Map aValues = new HashMap(); + for (int i=0;i VERSION) { throw new BCException("ExactAnnotationTypePattern was written by a newer version of AspectJ"); @@ -154,6 +323,18 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { if (s.getMajorVersion()>=WeaverVersionInfo.WEAVER_VERSION_MINOR_AJ160) { if (s.readBoolean()) ret.setForParameterAnnotationMatch(); } + if (s.getMajorVersion()>=WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ160M2) { + int annotationValueCount = s.readInt(); + if (annotationValueCount>0) { + Map aValues = new HashMap(); + for (int i=0;i