diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AndTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AndTypePattern.java index 83004d468e..e4099a692a 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AndTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AndTypePattern.java @@ -68,6 +68,11 @@ public boolean matchesStatically(ResolvedType type) { return left.matchesStatically(type) && right.matchesStatically(type); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return left.matchesArray(type) && right.matchesArray(type); + } + @Override public void setIsVarArgs(boolean isVarArgs) { this.isVarArgs = isVarArgs; diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyTypePattern.java index 2f71e7312a..4201f3cfb0 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyTypePattern.java @@ -60,6 +60,11 @@ public FuzzyBoolean matchesInstanceof(ResolvedType type) { return FuzzyBoolean.YES; } + @Override + protected boolean matchesArray(UnresolvedType type) { + return true; + } + @Override public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(ANY_KEY); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyWithAnnotationTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyWithAnnotationTypePattern.java index eafc0ebc1c..f0583ffcf3 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyWithAnnotationTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnyWithAnnotationTypePattern.java @@ -82,6 +82,11 @@ public FuzzyBoolean matchesInstanceof(ResolvedType type) { return FuzzyBoolean.MAYBE; } + @Override + protected boolean matchesArray(UnresolvedType type) { + return true; + } + @Override public TypePattern parameterizeWith(Map typeVariableMap, World w) { AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(this.annotationPattern.parameterizeWith( diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/EllipsisTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/EllipsisTypePattern.java index 745edb9f15..34df30df5c 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/EllipsisTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/EllipsisTypePattern.java @@ -17,6 +17,7 @@ import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.CompressingDataOutputStream; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; public class EllipsisTypePattern extends TypePattern { @@ -59,6 +60,11 @@ public FuzzyBoolean matchesInstanceof(ResolvedType type) { return FuzzyBoolean.NO; } + @Override + protected boolean matchesArray(UnresolvedType type) { + return false; + } + @Override public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(ELLIPSIS_KEY); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/ExactTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/ExactTypePattern.java index 9cd6ef6e24..6a747a3eca 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/ExactTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/ExactTypePattern.java @@ -177,6 +177,11 @@ protected boolean matchesExactly(ResolvedType matchType, ResolvedType annotatedT return (typeMatch && annMatch); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return type.getDimensions() == getDimensions(); + } + public UnresolvedType getType() { return type; } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java index 84730b9008..be09f77baf 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java @@ -26,6 +26,7 @@ import org.aspectj.weaver.Member; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.World; @@ -121,6 +122,11 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) return matchesExactly(type); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return true; + } + @Override public FuzzyBoolean matchesInstanceof(ResolvedType type) { throw new UnsupportedOperationException("hasmethod/field do not support instanceof matching"); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NoTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NoTypePattern.java index aac64a1d63..585bf34d1b 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NoTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NoTypePattern.java @@ -49,6 +49,11 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) return false; } + @Override + protected boolean matchesArray(UnresolvedType type) { + return false; + } + /** * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(ResolvedType) */ diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NotTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NotTypePattern.java index dca24c8f33..b5c5aee5a0 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NotTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/NotTypePattern.java @@ -68,6 +68,11 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) return (!negatedPattern.matchesExactly(type, annotatedType) && annotationPattern.matches(annotatedType).alwaysTrue()); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return !negatedPattern.matchesArray(type); + } + @Override public boolean matchesStatically(ResolvedType type) { return !negatedPattern.matchesStatically(type); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/OrTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/OrTypePattern.java index 4d0f9157fc..627c4a7d0a 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/OrTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/OrTypePattern.java @@ -73,6 +73,11 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) return left.matchesExactly(type, annotatedType) || right.matchesExactly(type, annotatedType); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return left.matchesArray(type) || right.matchesArray(type); + } + public boolean matchesStatically(ResolvedType type) { return left.matchesStatically(type) || right.matchesStatically(type); } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java index 5b2e021c11..4285da575d 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java @@ -465,7 +465,7 @@ private boolean parametersCannotMatch(JoinPointSignature methodJoinpoint) { * Matches on name, declaring type, return type, parameter types, throws types */ private FuzzyBoolean matchesExactlyMethod(JoinPointSignature aMethod, World world, boolean subjectMatch) { - if (aMethod.getReturnType().getDimensions() != returnType.getDimensions()) { + if (!returnType.matchesArray(aMethod.getReturnType())) { return FuzzyBoolean.NO; } if (parametersCannotMatch(aMethod)) { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java index df8345e964..1f98d074a0 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java @@ -67,6 +67,11 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) return isRightCategory(type); } + @Override + protected boolean matchesArray(UnresolvedType type) { + return true; + } + @Override public FuzzyBoolean matchesInstanceof(ResolvedType type) { return FuzzyBoolean.fromBoolean(isRightCategory(type)); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePattern.java index 8554e28a17..b0e058d452 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePattern.java @@ -163,9 +163,7 @@ public final FuzzyBoolean matches(ResolvedType type, MatchKind kind) { protected abstract boolean matchesExactly(ResolvedType type, ResolvedType annotatedType); - protected boolean matchesArray(ResolvedType type) { - return type.getDimensions() == getDimensions(); - } + protected abstract boolean matchesArray(UnresolvedType type); protected boolean matchesSubtypes(ResolvedType type) { // System.out.println("matching: " + this + " to " + type); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java index 512b72b26e..e43b6ca941 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java @@ -233,7 +233,7 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) // Ensure the annotation pattern is resolved annotationPattern.resolve(type.getWorld()); - return matchesExactlyByName(targetTypeName, type.isAnonymous(), type.isNested()) && matchesParameters(type, STATIC) + return matchesExactlyByName(targetTypeName.replaceFirst("(\\[\\])+$", ""), type.isAnonymous(), type.isNested()) && matchesParameters(type, STATIC) && matchesArray(type) && matchesBounds(type, STATIC) && annotationPattern.matches(annotatedType, type.temporaryAnnotationTypes).alwaysTrue(); @@ -252,6 +252,12 @@ private boolean matchesParameters(ResolvedType aType, MatchKind staticOrDynamic) return true; } + @Override + protected boolean matchesArray(UnresolvedType type) { + return type.getDimensions() == getDimensions() || + getDimensions() == 0 && namePatterns.length > 0 && namePatterns[namePatterns.length-1].toString().endsWith("*"); + } + // we've matched against the base (or raw) type, but if this type pattern specifies bounds because // it is a ? extends or ? super deal then we have to match them too. private boolean matchesBounds(ResolvedType aType, MatchKind staticOrDynamic) { @@ -318,19 +324,6 @@ private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous, return innerMatchesExactly(targetTypeName, isAnonymous, isNested); } - if (isNamePatternStar()) { - // we match if the dimensions match - int numDimensionsInTargetType = 0; - if (dim > 0) { - int index; - while ((index = targetTypeName.indexOf('[')) != -1) { - numDimensionsInTargetType++; - targetTypeName = targetTypeName.substring(index + 1); - } - return numDimensionsInTargetType == dim; - } - } - // if our pattern is length 1, then known matches are exact matches // if it's longer than that, then known matches are prefixes of a sort if (namePatterns.length == 1) { @@ -369,7 +362,7 @@ private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous, } } - return innerMatchesExactly(targetTypeName.substring(0, targetTypeName.length() - dim * 2), isAnonymous, isNested); + return innerMatchesExactly(targetTypeName, isAnonymous, isNested); } private int lastIndexOfDotOrDollar(String string) {