]> source.dussan.org Git - aspectj.git/commitdiff
support for isNested, and use of that property when splitting names in WildTypePattern
authoracolyer <acolyer>
Fri, 2 Dec 2005 07:02:33 +0000 (07:02 +0000)
committeracolyer <acolyer>
Fri, 2 Dec 2005 07:02:33 +0000 (07:02 +0000)
weaver/src/org/aspectj/weaver/BoundedReferenceType.java
weaver/src/org/aspectj/weaver/ReferenceType.java
weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/ResolvedType.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java

index f2f7dac99a9a73adfd1948f7247c873c0afeb22b..28d2e80d92c2e582bf0d5085848775a93b4565f3 100644 (file)
@@ -181,6 +181,10 @@ public class BoundedReferenceType extends ReferenceType {
                        return resolvedTypeX.isAnonymous();
                }
                
+               public boolean isNested() {
+                       return resolvedTypeX.isNested();
+               }
+               
                public String getRetentionPolicy() {
                        return resolvedTypeX.getRetentionPolicy();
                }
index eb2fa46f2c1fcb709d3616fa19421bce43772804..7cc34533a434cc345ddcc1a9ba08660ce65dc929 100644 (file)
@@ -166,6 +166,10 @@ public class ReferenceType extends ResolvedType {
                return delegate.isAnonymous();
     }
     
+    public boolean isNested() {
+               return delegate.isNested();
+    }
+    
     public String getRetentionPolicy() {
        return delegate.getRetentionPolicy();
     }
index d00a4d288099106f640900d53b43d89d8cad3a9b..101c06e66dd3206fbade3f89b6638d0a76c33aa1 100644 (file)
@@ -38,6 +38,7 @@ public interface ReferenceTypeDelegate {
        public boolean isClass();
        public boolean isGeneric();
        public boolean isAnonymous();
+       public boolean isNested();
        public boolean isExposedToWeaver();
        
        public boolean hasAnnotation(UnresolvedType ofType);
index ba8d60a4880e511376516693046416f52836de51..7ef50c857c79de465349e54f4dde73fb13a64324 100644 (file)
@@ -54,7 +54,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
     }
 
     // ---- things that don't require a world
-
+    
     /**
      * Returns an iterator through ResolvedType objects representing all the direct
      * supertypes of this type.  That is, through the superclass, if any, and
@@ -620,6 +620,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                return false;
     }
     
+    public boolean isNested() {
+               return false;
+    }
+    
     /**
      * Note: Only overridden by Name subtype
      */
index a6d499a9a11505c68e4159ff6dd58cc76a7138eb..59dcea1104f4e154f7a0b74aa52dde664a8a5b75 100644 (file)
@@ -409,6 +409,10 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                return javaClass.isAnonymous();
        }
        
+       public boolean isNested() {
+               return javaClass.isNested();
+       }
+       
        public void addAnnotation(AnnotationX annotation) {
                damaged = true;
                // Add it to the set of annotations
index 8313460bd20017134ac28bb81ced40ef8427a14c..234bcc33460ae574bcaa6973e6f767447a840c99 100644 (file)
@@ -200,12 +200,15 @@ public class WildTypePattern extends TypePattern {
        }
        
        //XXX inefficient implementation
-       public static char[][] splitNames(String s) {
+       // we don't know whether $ characters are from nested types, or were
+       // part of the declared type name (generated code often uses $s in type
+       // names). More work required on our part to get this right...
+       public static char[][] splitNames(String s, boolean convertDollar) {
                List ret = new ArrayList();
                int startIndex = 0;
                while (true) {
                    int breakIndex = s.indexOf('.', startIndex);  // what about /
-                   if (breakIndex == -1) breakIndex = s.indexOf('$', startIndex);  // we treat $ like . here
+                   if (convertDollar && (breakIndex == -1)) breakIndex = s.indexOf('$', startIndex);  // we treat $ like . here
                    if (breakIndex == -1) break;
                    char[] name = s.substring(startIndex, breakIndex).toCharArray();
                    ret.add(name);
@@ -230,7 +233,7 @@ public class WildTypePattern extends TypePattern {
                // Ensure the annotation pattern is resolved
                annotationPattern.resolve(type.getWorld());
                
-               return matchesExactlyByName(targetTypeName,type.isAnonymous()) &&
+               return matchesExactlyByName(targetTypeName,type.isAnonymous(),type.isNested()) &&
                        matchesParameters(type,STATIC) &&
                        matchesBounds(type,STATIC) &&
                       annotationPattern.matches(annotatedType).alwaysTrue();
@@ -288,7 +291,7 @@ public class WildTypePattern extends TypePattern {
         * @param targetTypeName
         * @return
         */
-       private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous) {
+       private boolean matchesExactlyByName(String targetTypeName, boolean isAnonymous, boolean isNested) {
                // we deal with parameter matching separately...
                if (targetTypeName.indexOf('<') != -1) {
                        targetTypeName = targetTypeName.substring(0,targetTypeName.indexOf('<'));
@@ -299,7 +302,7 @@ public class WildTypePattern extends TypePattern {
                }
                //XXX hack
                if (knownMatches == null && importedPrefixes == null) {
-                       return innerMatchesExactly(targetTypeName,isAnonymous);
+                       return innerMatchesExactly(targetTypeName,isAnonymous, isNested);
                }
                
                if (isNamePatternStar()) {
@@ -334,7 +337,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),isAnonymous)) {
+                                       if (innerMatchesExactly(targetTypeName.substring(pos+1),isAnonymous,isNested)) {
                                                return true;
                                        }
                                }
@@ -349,13 +352,13 @@ public class WildTypePattern extends TypePattern {
                        //System.err.println("prefix match? " + prefix + " to " + targetTypeName);
                        if (targetTypeName.startsWith(prefix)) {
                                
-                               if (innerMatchesExactly(targetTypeName.substring(prefix.length()),isAnonymous)) {
+                               if (innerMatchesExactly(targetTypeName.substring(prefix.length()),isAnonymous,isNested)) {
                                        return true;
                                }
                        }
                }
                
-               return innerMatchesExactly(targetTypeName,isAnonymous);
+               return innerMatchesExactly(targetTypeName,isAnonymous,isNested);
        }
 
        private int lastIndexOfDotOrDollar(String string) {
@@ -365,9 +368,9 @@ public class WildTypePattern extends TypePattern {
     }
 
        
-       private boolean innerMatchesExactly(String targetTypeName, boolean isAnonymous) {
+       private boolean innerMatchesExactly(String targetTypeName, boolean isAnonymous, boolean isNested) {
                //??? doing this everytime is not very efficient
-               char[][] names = splitNames(targetTypeName);
+               char[][] names = splitNames(targetTypeName,isNested);
 
         return innerMatchesExactly(names, isAnonymous);
        }
@@ -980,9 +983,16 @@ public class WildTypePattern extends TypePattern {
                
                List ret = new ArrayList();
                for (int i=0, len=possibleMatches.length; i < len; i++) {
-                       char[][] names = splitNames(possibleMatches[i]); //??? not most efficient
+                       char[][] names = splitNames(possibleMatches[i],true); //??? not most efficient
                        if (namePatterns[0].matches(names[names.length-1])) {
                                ret.add(possibleMatches[i]);
+                               continue;
+                       }
+                       if (possibleMatches[i].indexOf("$") != -1) {
+                               names = splitNames(possibleMatches[i],false); //??? not most efficient
+                               if (namePatterns[0].matches(names[names.length-1])) {
+                                       ret.add(possibleMatches[i]);
+                               }
                        }
                }
                return (String[])ret.toArray(new String[ret.size()]);
index ef61c7f2fa0738588fa986d9148898ced2041cb0..cce85c3236be69a152cf8065361910bc6a447a56 100644 (file)
@@ -156,6 +156,11 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
        public boolean isAnonymous() {
                return false;
        }
+       
+       public boolean isNested() {
+               boolean member = this.myClass.isMemberClass();
+               return member;
+       }
 
        /* (non-Javadoc)
         * @see org.aspectj.weaver.ReferenceTypeDelegate#isExposedToWeaver()