-import org.xyz.*;
+import org.xyz.*; import anns.*;
//import org.abc.*;
import java.util.List;
-import org.xyz.*;
+import org.xyz.*; import anns.*;
import org.abc.*;
import java.lang.annotation.Inherited;
+++ /dev/null
-public @interface Cachable {}
\ No newline at end of file
+++ /dev/null
-public @interface Immutable {}
\ No newline at end of file
+++ /dev/null
-import java.lang.annotation.Inherited;
-
-@Inherited
-public @interface NonPersistent {}
\ No newline at end of file
+++ /dev/null
-public @interface Persisted {}
\ No newline at end of file
+++ /dev/null
-public @interface SensitiveData {}
\ No newline at end of file
+++ /dev/null
-public @interface Transaction {}
\ No newline at end of file
--- /dev/null
+package anns;
+public @interface Cachable {}
\ No newline at end of file
--- /dev/null
+package anns;
+public @interface Immutable {}
\ No newline at end of file
--- /dev/null
+package anns;
+import java.lang.annotation.Inherited;
+
+@Inherited
+public @interface NonPersistent {}
\ No newline at end of file
--- /dev/null
+package anns;
+public @interface Persisted {}
\ No newline at end of file
--- /dev/null
+package anns;
+public @interface SensitiveData {}
\ No newline at end of file
--- /dev/null
+package anns;
+public @interface Transaction {}
\ No newline at end of file
-
+package org.abc; import anns.*;
class E {}
@Immutable
+package org.xyz;
public @interface OrgXYZAnnotation {}
\ No newline at end of file
+package org.xyz; import anns.*;
import java.util.List;
import java.util.ArrayList;
-
+package org.xyz; import anns.*;
@Immutable
class C {}
</ajc-test>
<ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotation type pattern matching">
- <compile files="AnnotationsInTypePatterns.aj,org/xyz/OrgXYZAnnotation.java,org/xyz/Types.java,org/abc/Types.java,Immutable.java,NonPersistent.java" options="-1.5">
+ <compile files="AnnotationsInTypePatterns.aj,org/xyz/OrgXYZAnnotation.java,org/xyz/Types.java,org/abc/Types.java,anns/Immutable.java,anns/NonPersistent.java" options="-1.5">
<message kind="warning" line="23" text="(@Immutable *)"/>
<message kind="warning" line="32" text="(@Immutable *)"/>
<message kind="warning" line="3" text="(@Immutable *)"/>
<message kind="warning" line="5" text="(!@Immutable *)"/>
<message kind="warning" line="6" text="(!@Immutable *)"/>
<message kind="warning" line="2" text="(!@Immutable *)"/>
- <message kind="warning" line="1" text="(!@Immutable *)"/>
- <message kind="warning" line="4" text="(!@Immutable *)"/>
+ <message kind="warning" line="2" text="(!@Immutable *)"/>
+ <message kind="warning" line="5" text="(!@Immutable *)"/>
<message kind="warning" line="3" text="@Immutable (org.xyz.* || org.abc.*)"/>
<message kind="warning" line="5" text="@Immutable (org.xyz.* || org.abc.*)"/>
<message kind="warning" line="8" text="@Immutable (org.xyz.* || org.abc.*)"/>
<message kind="warning" line="8" text="@(Immutable || NonPersistent) org.xyz..*"/>
<message kind="warning" line="8" text="@Immutable @NonPersistent org.xyz..*"/>
<message kind="warning" line="6" text="@(@Inherited *) org.xyz..*"/>
+ <message kind="warning" line="8" text="@(@Inherited *) org.xyz..*"/>
</compile>
</ajc-test>
<ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotations in sig patterns">
- <compile files="AnnotationsInSignaturePatterns.aj,Cachable.java,SensitiveData.java,Persisted.java,Classified.java,Immutable.java,Secure.java,Catastrophic.java,Oneway.java,Transaction.java,org/xyz/SignatureTypes.java" options="-1.5">
+ <compile files="AnnotationsInSignaturePatterns.aj,anns/Cachable.java,anns/SensitiveData.java,anns/Persisted.java,Classified.java,anns/Immutable.java,Secure.java,Catastrophic.java,Oneway.java,anns/Transaction.java,org/xyz/SignatureTypes.java" options="-1.5">
<message kind="warning" line="32" text="@SensitiveData * *"/>
- <message kind="warning" line="6" text="@SensitiveData * *"/>
- <message kind="warning" line="12" text="@SensitiveData * *"/>
- <message kind="warning" line="6" text="@SensitiveData List org.xyz..*.*"/>
- <message kind="warning" line="10" text="(@SensitiveData *) org.xyz..*.*"/>
- <message kind="warning" line="12" text="(@SensitiveData *) org.xyz..*.*"/>
+ <message kind="warning" line="7" text="@SensitiveData * *"/>
+ <message kind="warning" line="13" text="@SensitiveData * *"/>
+ <message kind="warning" line="7" text="@SensitiveData List org.xyz..*.*"/>
+ <message kind="warning" line="11" text="(@SensitiveData *) org.xyz..*.*"/>
+ <message kind="warning" line="13" text="(@SensitiveData *) org.xyz..*.*"/>
<message kind="warning" line="50" text="@Foo (@Goo *) (@Hoo *).*"/>
<message kind="warning" line="38" text="@Persisted @Classified * *"/>
<message kind="warning" line="44" text="@Oneway * *(..)"/>
- <message kind="warning" line="17" text="@Transaction * (@Persisted org.xyz..*).*(..)"/>
+ <message kind="warning" line="18" text="@Transaction * (@Persisted org.xyz..*).*(..)"/>
<message kind="warning" line="52" text="* *.*(@Immutable *,..)"/>
<message kind="warning" line="53" text="* *.*(@Immutable *,..)"/>
<message kind="warning" line="54" text="* *.*(@Immutable *,..)"/>
<message kind="warning" line="62" text="within(@Secure *)"/>
<message kind="warning" line="63" text="within(@Secure *)"/>
<message kind="warning" line="66" text="staticinitialization(@Persisted *)"/>
- <message kind="warning" line="16" text="staticinitialization(@Persisted *)"/>
+ <message kind="warning" line="17" text="staticinitialization(@Persisted *)"/>
<message kind="warning" line="56" text="call(@Oneway * *(..))"/>
- <message kind="warning" line="27" text="execution(public (@Immutable *) org.xyz..*.*(..))"/>
- <message kind="warning" line="25" text="set(@Cachable * *)"/>
+ <message kind="warning" line="28" text="execution(public (@Immutable *) org.xyz..*.*(..))"/>
+ <message kind="warning" line="26" text="set(@Cachable * *)"/>
<message kind="warning" line="80" text="handler(!@Catastrophic *)"/>
</compile>
return left.matchesExactly(type) && right.matchesExactly(type);
}
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ return left.matchesExactly(type,annotatedType) && right.matchesExactly(type,annotatedType);
+ }
+
+
public boolean matchesStatically(Class type) {
return left.matchesStatically(type) && right.matchesStatically(type);
}
right.setIsVarArgs(isVarArgs);
}
+ public void setAnnotationTypePattern(AnnotationTypePattern annPatt) {
+ if (annPatt == AnnotationTypePattern.ANY) return;
+ if (left.annotationPattern == AnnotationTypePattern.ANY) {
+ left.setAnnotationTypePattern(annPatt);
+ } else {
+ left.setAnnotationTypePattern(
+ new AndAnnotationTypePattern(left.annotationPattern,annPatt));
+ }
+ if (right.annotationPattern == AnnotationTypePattern.ANY) {
+ right.setAnnotationTypePattern(annPatt);
+ } else {
+ right.setAnnotationTypePattern(
+ new AndAnnotationTypePattern(right.annotationPattern,annPatt));
+ }
+ }
+
public void write(DataOutputStream s) throws IOException {
s.writeByte(TypePattern.AND);
left.write(s);
protected boolean matchesExactly(ResolvedTypeX matchType) {
boolean typeMatch = this.type.equals(matchType);
+ annotationPattern.resolve(matchType.getWorld());
boolean annMatch = this.annotationPattern.matches(matchType).alwaysTrue();
return (typeMatch && annMatch);
}
+ protected boolean matchesExactly(ResolvedTypeX matchType, ResolvedTypeX annotatedType) {
+ boolean typeMatch = this.type.equals(matchType);
+ annotationPattern.resolve(matchType.getWorld());
+ boolean annMatch = this.annotationPattern.matches(annotatedType).alwaysTrue();
+ return (typeMatch && annMatch);
+ }
+
public TypeX getType() { return type; }
public FuzzyBoolean matchesInstanceof(ResolvedTypeX matchType) {
import java.io.IOException;
import org.aspectj.util.FuzzyBoolean;
+import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.VersionedDataInputStream;
}
protected boolean matchesExactly(ResolvedTypeX type) {
- return !pattern.matchesExactly(type);
+ return (!pattern.matchesExactly(type) && annotationPattern.matches(type).alwaysTrue());
+ }
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ return (!pattern.matchesExactly(type,annotatedType) && annotationPattern.matches(annotatedType).alwaysTrue());
}
public boolean matchesStatically(Class type) {
return !pattern.matchesStatically(type);
}
+ public void setAnnotationTypePattern(AnnotationTypePattern annPatt) {
+ super.setAnnotationTypePattern(annPatt);
+ }
+
+ public void setIsVarArgs(boolean isVarArgs) {
+ pattern.setIsVarArgs(isVarArgs);
+ }
+
+
public void write(DataOutputStream s) throws IOException {
s.writeByte(TypePattern.NOT);
pattern.write(s);
+ annotationPattern.write(s);
writeLocation(s);
}
public static TypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
TypePattern ret = new NotTypePattern(TypePattern.read(s, context));
+ if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
+ ret.annotationPattern = AnnotationTypePattern.read(s,context);
+ }
ret.readLocation(context, s);
return ret;
}
//??? if these had side-effects, this sort-circuit could be a mistake
return left.matchesExactly(type) || right.matchesExactly(type);
}
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ //??? if these had side-effects, this sort-circuit could be a mistake
+ return left.matchesExactly(type,annotatedType) || right.matchesExactly(type,annotatedType);
+ }
public boolean matchesStatically(ResolvedTypeX type) {
return left.matchesStatically(type) || right.matchesStatically(type);
right.setIsVarArgs(isVarArgs);
}
+ public void setAnnotationTypePattern(AnnotationTypePattern annPatt) {
+ if (annPatt == AnnotationTypePattern.ANY) return;
+ if (left.annotationPattern == AnnotationTypePattern.ANY) {
+ left.setAnnotationTypePattern(annPatt);
+ } else {
+ left.setAnnotationTypePattern(
+ new AndAnnotationTypePattern(left.annotationPattern,annPatt));
+ }
+ if (right.annotationPattern == AnnotationTypePattern.ANY) {
+ right.setAnnotationTypePattern(annPatt);
+ } else {
+ right.setAnnotationTypePattern(
+ new AndAnnotationTypePattern(right.annotationPattern,annPatt));
+ }
+ }
+
public void write(DataOutputStream s) throws IOException {
s.writeByte(TypePattern.OR);
left.write(s);
}
protected abstract boolean matchesExactly(ResolvedTypeX type);
+
+ protected abstract boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType);
protected boolean matchesSubtypes(ResolvedTypeX type) {
//System.out.println("matching: " + this + " to " + type);
// FuzzyBoolean ret = FuzzyBoolean.NO; // ??? -eh
for (Iterator i = type.getDirectSupertypes(); i.hasNext(); ) {
ResolvedTypeX superType = (ResolvedTypeX)i.next();
- if (matchesSubtypes(superType)) return true;
+ if (matchesSubtypes(superType,type)) return true;
+ }
+ return false;
+ }
+
+ protected boolean matchesSubtypes(ResolvedTypeX superType, ResolvedTypeX annotatedType) {
+ //System.out.println("matching: " + this + " to " + type);
+ if (matchesExactly(superType,annotatedType)) {
+ //System.out.println(" true");
+ return true;
+ }
+
+ // FuzzyBoolean ret = FuzzyBoolean.NO; // ??? -eh
+ for (Iterator i = superType.getDirectSupertypes(); i.hasNext(); ) {
+ ResolvedTypeX superSuperType = (ResolvedTypeX)i.next();
+ if (matchesSubtypes(superSuperType,annotatedType)) return true;
}
return false;
}
protected boolean matchesExactly(ResolvedTypeX type) {
return false;
}
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ return false;
+ }
/**
* @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
return true;
}
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ return true;
+ }
+
/**
* @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
*/
annotationPattern.resolve(type.getWorld());
return annotationPattern.matches(type).alwaysTrue();
}
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ annotationPattern.resolve(type.getWorld());
+ return annotationPattern.matches(annotatedType).alwaysTrue();
+ }
public FuzzyBoolean matchesInstanceof(ResolvedTypeX type) {
return FuzzyBoolean.YES;
protected boolean matchesExactly(ResolvedTypeX type) {
return false;
}
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
+ return false;
+ }
/**
* @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings,
boolean allowBinding)
{
+ if (resolved) return this;
this.typePattern = typePattern.resolveBindings(scope,bindings,false,false);
resolved = true;
if (typePattern instanceof ExactTypePattern) {
* @see org.aspectj.weaver.TypePattern#matchesExactly(IType)
*/
protected boolean matchesExactly(ResolvedTypeX type) {
+ return matchesExactly(type,type);
+ }
+
+ protected boolean matchesExactly(ResolvedTypeX type, ResolvedTypeX annotatedType) {
String targetTypeName = type.getName();
//System.err.println("match: " + targetTypeName + ", " + knownMatches); //Arrays.asList(importedPrefixes));
annotationPattern.resolve(type.getWorld());
return matchesExactlyByName(targetTypeName) &&
- annotationPattern.matches(type).alwaysTrue();
+ annotationPattern.matches(annotatedType).alwaysTrue();
}
-
+
+
/**
* Used in conjunction with checks on 'isStar()' to tell you if this pattern represents '*' or '*[]' which are
* different !
} else {
if (dim != 0) type = TypeX.makeArray(type, dim);
TypePattern ret = new ExactTypePattern(type, includeSubtypes,isVarArgs);
+ ret.setAnnotationTypePattern(annotationPattern);
ret.copyLocationFrom(this);
return ret;
}
PatternParser p = new PatternParser("(@(Foo || Boo) (Foo || Boo))");
TypePattern t = p.parseTypePattern();
assertTrue("OrTypePattern",t instanceof OrTypePattern);
- WildAnnotationTypePattern wtp = (WildAnnotationTypePattern) t.annotationPattern;
- assertEquals("@((Foo || Boo))",wtp.toString());
- assertEquals("(@((Foo || Boo)) (Foo || Boo))",t.toString());
+ assertEquals("((@((Foo || Boo)) Foo) || (@((Foo || Boo)) Boo))",t.toString());
}
public void testNotSyntax() {
PatternParser p = new PatternParser("!@Foo (Foo || Boo))");
TypePattern t = p.parseTypePattern();
assertTrue("OrTypePattern",t instanceof OrTypePattern);
- NotAnnotationTypePattern natp = (NotAnnotationTypePattern) t.annotationPattern;
- assertEquals("!@(Foo)",natp.toString());
- assertEquals("(!@(Foo) (Foo || Boo))",t.toString());
+ assertEquals("((!@(Foo) Foo) || (!@(Foo) Boo))",t.toString());
}
public void testParseMethodOrConstructorSigNoAP() {