From 78569b96815838515cb9c9bc8ab528149a89af00 Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 4 Nov 2005 13:12:15 +0000 Subject: [PATCH] fix for pr73050 :- support for isAnonymous and name pattern matching that now only matches "*" against anonymous types --- .../aspectj/weaver/BoundedReferenceType.java | 4 +++ .../src/org/aspectj/weaver/ReferenceType.java | 4 +++ .../aspectj/weaver/ReferenceTypeDelegate.java | 1 + .../src/org/aspectj/weaver/ResolvedType.java | 4 +++ .../aspectj/weaver/bcel/BcelObjectType.java | 4 +++ .../weaver/patterns/WildTypePattern.java | 26 ++++++++++++------- .../ReflectionBasedReferenceTypeDelegate.java | 4 +++ 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/BoundedReferenceType.java b/weaver/src/org/aspectj/weaver/BoundedReferenceType.java index 08cb9bab3..fe8bda13b 100644 --- a/weaver/src/org/aspectj/weaver/BoundedReferenceType.java +++ b/weaver/src/org/aspectj/weaver/BoundedReferenceType.java @@ -177,6 +177,10 @@ public class BoundedReferenceType extends ReferenceType { return resolvedTypeX.isAnnotationWithRuntimeRetention(); } + public boolean isAnonymous() { + return resolvedTypeX.isAnonymous(); + } + public String getRetentionPolicy() { return resolvedTypeX.getRetentionPolicy(); } diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index f31cf2e96..0bc7a0d94 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -147,6 +147,10 @@ public class ReferenceType extends ResolvedType { return delegate.isAnnotation(); } + public boolean isAnonymous() { + return delegate.isAnonymous(); + } + public String getRetentionPolicy() { return delegate.getRetentionPolicy(); } diff --git a/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java index b2a6ec0bf..2c49ef54d 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java @@ -37,6 +37,7 @@ public interface ReferenceTypeDelegate { public boolean isAnnotationWithRuntimeRetention(); public boolean isClass(); public boolean isGeneric(); + public boolean isAnonymous(); public boolean isExposedToWeaver(); public boolean hasAnnotation(UnresolvedType ofType); diff --git a/weaver/src/org/aspectj/weaver/ResolvedType.java b/weaver/src/org/aspectj/weaver/ResolvedType.java index 464c1675c..51d962d9d 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedType.java +++ b/weaver/src/org/aspectj/weaver/ResolvedType.java @@ -616,6 +616,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl return false; } + public boolean isAnonymous() { + return false; + } + /** * Note: Only overridden by Name subtype */ diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 1f0a04610..cacd98fa0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -402,6 +402,10 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { return javaClass.isAnnotation(); } + public boolean isAnonymous() { + return javaClass.isAnonymous(); + } + public void addAnnotation(AnnotationX annotation) { damaged = true; // Add it to the set of annotations diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index b76a1f6af..d3e4cfff3 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -229,7 +229,7 @@ public class WildTypePattern extends TypePattern { // Ensure the annotation pattern is resolved annotationPattern.resolve(type.getWorld()); - return matchesExactlyByName(targetTypeName) && + return matchesExactlyByName(targetTypeName,type.isAnonymous()) && matchesParameters(type,STATIC) && matchesBounds(type,STATIC) && annotationPattern.matches(annotatedType).alwaysTrue(); @@ -287,7 +287,7 @@ public class WildTypePattern extends TypePattern { * @param targetTypeName * @return */ - private boolean matchesExactlyByName(String targetTypeName) { + private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous) { // we deal with parameter matching separately... if (targetTypeName.indexOf('<') != -1) { targetTypeName = targetTypeName.substring(0,targetTypeName.indexOf('<')); @@ -298,7 +298,7 @@ public class WildTypePattern extends TypePattern { } //XXX hack if (knownMatches == null && importedPrefixes == null) { - return innerMatchesExactly(targetTypeName); + return innerMatchesExactly(targetTypeName,isAnonymous); } if (isNamePatternStar()) { @@ -321,6 +321,10 @@ public class WildTypePattern extends TypePattern { // 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) { + if (isAnonymous) { + // we've already ruled out "*", and no other name pattern should match an anonymous type + return false; + } for (int i=0, len=knownMatches.length; i < len; i++) { if (knownMatches[i].equals(targetTypeName)) return true; } @@ -329,7 +333,7 @@ public class WildTypePattern extends TypePattern { String knownPrefix = knownMatches[i] + "$"; if (targetTypeName.startsWith(knownPrefix)) { int pos = lastIndexOfDotOrDollar(knownMatches[i]); - if (innerMatchesExactly(targetTypeName.substring(pos+1))) { + if (innerMatchesExactly(targetTypeName.substring(pos+1),isAnonymous)) { return true; } } @@ -344,13 +348,13 @@ public class WildTypePattern extends TypePattern { //System.err.println("prefix match? " + prefix + " to " + targetTypeName); if (targetTypeName.startsWith(prefix)) { - if (innerMatchesExactly(targetTypeName.substring(prefix.length()))) { + if (innerMatchesExactly(targetTypeName.substring(prefix.length()),isAnonymous)) { return true; } } } - return innerMatchesExactly(targetTypeName); + return innerMatchesExactly(targetTypeName,isAnonymous); } private int lastIndexOfDotOrDollar(String string) { @@ -360,21 +364,23 @@ public class WildTypePattern extends TypePattern { } - private boolean innerMatchesExactly(String targetTypeName) { + private boolean innerMatchesExactly(String targetTypeName, boolean isAnonymous) { //??? doing this everytime is not very efficient char[][] names = splitNames(targetTypeName); - return innerMatchesExactly(names); + return innerMatchesExactly(names, isAnonymous); } - private boolean innerMatchesExactly(char[][] names) { + private boolean innerMatchesExactly(char[][] names, boolean isAnonymous) { int namesLength = names.length; int patternsLength = namePatterns.length; int namesIndex = 0; int patternsIndex = 0; - + + if ((!namePatterns[patternsLength-1].isAny()) && isAnonymous) return false; + if (ellipsisCount == 0) { if (namesLength != patternsLength) return false; while (patternsIndex < patternsLength) { diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java index 8b17d22ce..011a180f9 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java @@ -146,6 +146,10 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega // cant be generic in 1.4 return false; } + + public boolean isAnonymous() { + return this.myClass.isAnonymousClass(); + } /* (non-Javadoc) * @see org.aspectj.weaver.ReferenceTypeDelegate#isExposedToWeaver() -- 2.39.5