]> source.dussan.org Git - aspectj.git/commitdiff
fix to use cache for isPackage method (as indicated by previous !!! comment)
authorjhugunin <jhugunin>
Fri, 9 May 2003 17:31:49 +0000 (17:31 +0000)
committerjhugunin <jhugunin>
Fri, 9 May 2003 17:31:49 +0000 (17:31 +0000)
this fixes the two failing incremental test cases just added by Wes and now
moved to ajcTests as passing

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/StatefulNameEnvironment.java

index 552a409dd2887ba298fd7ba4931a17eb51677099..af72b9a9aee54d7938de07be8821743068529253 100644 (file)
 
 package org.aspectj.ajdt.internal.core.builder;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import org.aspectj.weaver.bcel.UnwovenClassFile;
 import org.eclipse.jdt.core.compiler.CharOperation;
@@ -25,11 +29,27 @@ import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
 
 public class StatefulNameEnvironment implements INameEnvironment {
        Map classesFromName;
+       Set packageNames;
        INameEnvironment baseEnvironment;
        
        public StatefulNameEnvironment(INameEnvironment baseEnvironment, Map classesFromName) {
                this.classesFromName = classesFromName;
                this.baseEnvironment = baseEnvironment;
+               
+               packageNames = new HashSet();
+               for (Iterator i = classesFromName.keySet().iterator(); i.hasNext(); ) {
+                       String className = (String)i.next();
+                       addAllPackageNames(className);
+               }
+//             System.err.println(packageNames);
+       }
+
+       private void addAllPackageNames(String className) {
+               int dot = className.indexOf('.');
+               while (dot != -1) {
+                       packageNames.add(className.substring(0, dot));
+                       dot = className.indexOf('.', dot+1);
+               }
        }
 
        public void cleanup() {
@@ -38,6 +58,8 @@ public class StatefulNameEnvironment implements INameEnvironment {
 
        private NameEnvironmentAnswer findType(String name) {
                UnwovenClassFile cf = (UnwovenClassFile)classesFromName.get(name);
+               //System.err.println("find: " + name + " found: " + cf);
+               
                if (cf == null) return null;
 
                try {
@@ -64,9 +86,10 @@ public class StatefulNameEnvironment implements INameEnvironment {
        }
 
        public boolean isPackage(char[][] parentPackageName, char[] packageName) {
-               //!!! need to use cache here too
-               return baseEnvironment.isPackage(parentPackageName, packageName);
+               if (baseEnvironment.isPackage(parentPackageName, packageName)) return true;
 
+               String fullPackageName = new String(CharOperation.concatWith(parentPackageName, packageName, '.'));
+               return packageNames.contains(fullPackageName);
        }
 
 }