]> source.dussan.org Git - aspectj.git/commitdiff
wildcarded type patterns now remember there scope information
authorjhugunin <jhugunin>
Wed, 18 Dec 2002 01:37:07 +0000 (01:37 +0000)
committerjhugunin <jhugunin>
Wed, 18 Dec 2002 01:37:07 +0000 (01:37 +0000)
so they can do matching of local names

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java
util/src/org/aspectj/util/FileUtil.java
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java

index 88c9072d99cc02c4273dc2679a8f81bcbab8189b..49fef3dc69f81266c92f969ff19af40af93c1933 100644 (file)
@@ -199,6 +199,7 @@ public class EclipseScope implements IScope {
 
        public String[] getImportedPrefixes() {
                computeImports();
+               //System.err.println("prefixes: " + Arrays.asList(importedPrefixes));
                return importedPrefixes;
        }
 
index a0d445cfe08f909005e4e3bfca8846d69beafc9e..b9a91b0019dc9deea6d15572d324a93677304da5 100644 (file)
@@ -825,7 +825,7 @@ public class FileUtil {
 
 
        /**
-        * Reads an int array with our encoding
+        * Writes an int array with our encoding
         */
        public static void writeIntArray(DataOutputStream s, int[] a) throws IOException {
                int len = a.length;
@@ -835,6 +835,30 @@ public class FileUtil {
 
 
 
+       /**
+        * Reads an int array with our encoding
+        */
+       public static String[] readStringArray(DataInputStream s) throws IOException {
+               int len = s.readInt();
+               String[] ret = new String[len];
+               for (int i=0; i < len; i++) ret[i] = s.readUTF();
+               return ret;
+       }
+
+
+       /**
+        * Writes an int array with our encoding
+        */
+       public static void writeStringArray(DataOutputStream s, String[] a) throws IOException {
+               if (a == null) {
+                       s.writeInt(0);
+                       return;
+               }
+               int len = a.length;
+               s.writeInt(len);
+               for (int i=0; i < len; i++) s.writeUTF(a[i]);
+       }
+
 
        /**
         * Returns the contents of this file as a String
index 90f8c31b7ecfbda7f0de6729ad1a7baad6e6efd2..c12c0e8dc5b37bec99b73824ce2c6def81852ccf 100644 (file)
@@ -21,6 +21,8 @@ import org.aspectj.bridge.*;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.util.*;
 
+import com.sun.corba.se.internal.util.Utility;
+
 //XXX need to use dim in matching
 public class WildTypePattern extends TypePattern {
        NamePattern[] namePatterns;
@@ -74,8 +76,10 @@ public class WildTypePattern extends TypePattern {
        protected boolean matchesExactly(ResolvedTypeX type) {
                String targetTypeName = type.getName();
                
+               //System.err.println("match: " + targetTypeName + ", " + knownMatches); //Arrays.asList(importedPrefixes));
+               
                //XXX hack
-               if (knownMatches == null) {
+               if (knownMatches == null && importedPrefixes == null) {
                        return innerMatchesExactly(targetTypeName);
                }
                
@@ -102,7 +106,9 @@ public class WildTypePattern extends TypePattern {
                // assumes that prefixes have a dot at the end
                for (int i=0, len=importedPrefixes.length; i < len; i++) {
                        String prefix = importedPrefixes[i];
+                       //System.err.println("prefix match? " + prefix + " to " + targetTypeName);
                        if (targetTypeName.startsWith(prefix)) {
+                               
                                if (innerMatchesExactly(targetTypeName.substring(prefix.length()))) {
                                        return true;
                                }
@@ -123,8 +129,6 @@ public class WildTypePattern extends TypePattern {
                //??? doing this everytime is not very efficient
                char[][] names = splitNames(targetTypeName);
 
-               
-               
         return innerMatchesExactly(names);
        }
 
@@ -427,6 +431,10 @@ public class WildTypePattern extends TypePattern {
                }
                s.writeBoolean(includeSubtypes);
                s.writeInt(dim);
+               //??? storing this information with every type pattern is wasteful of .class
+               //    file size. Storing it on enclosing types would be more efficient
+               FileUtil.writeStringArray(s, knownMatches);
+               FileUtil.writeStringArray(s, importedPrefixes);
                writeLocation(s);
        }
        
@@ -438,7 +446,9 @@ public class WildTypePattern extends TypePattern {
                }
                boolean includeSubtypes = s.readBoolean();
                int dim = s.readInt();
-               TypePattern ret = new WildTypePattern(namePatterns, includeSubtypes, dim);
+               WildTypePattern ret = new WildTypePattern(namePatterns, includeSubtypes, dim);
+               ret.knownMatches = FileUtil.readStringArray(s);
+               ret.importedPrefixes = FileUtil.readStringArray(s);
                ret.readLocation(context, s);
                return ret;
        }