]> source.dussan.org Git - aspectj.git/commitdiff
Fix for 91053 (Generics): Generics problem with Set
authoraclement <aclement>
Fri, 6 May 2005 15:18:54 +0000 (15:18 +0000)
committeraclement <aclement>
Fri, 6 May 2005 15:18:54 +0000 (15:18 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
tests/java5/generics/bugs/PR91053.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/TypeX.java
weaver/src/org/aspectj/weaver/World.java

index 395094b256719fb986eecea2717b5dd4c83c387e..b294efccbd0e7e2999ac455c4775ce490bbd88dc 100644 (file)
@@ -192,8 +192,12 @@ public class EclipseFactory {
                          return TypeX.forName(getName(tvb.superclass));
                        }
                }
-               // FIXME asc/amc cope properly with RawTypeBindings
-               if (binding instanceof ParameterizedTypeBinding && !(binding instanceof RawTypeBinding)) {
+               
+               if (binding instanceof ParameterizedTypeBinding) {
+                       if (binding instanceof RawTypeBinding) {
+                               // special case where no parameters are specified!
+                               return TypeX.forRawTypeNames(getName(binding));
+                       }
                        ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) binding;
                        String[] arguments = new String[ptb.arguments.length];
                        for (int i = 0; i < arguments.length; i++) {
@@ -348,16 +352,22 @@ public class EclipseFactory {
                                typeX = typeX.getComponentType();
                        }
                        return lookupEnvironment.createArrayType(makeTypeBinding(typeX), dim);
-               } else if (typeX.isParameterized()){
-                       TypeX[] typeParameters = typeX.getTypeParameters();
-                       ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName());
-                       ReferenceBinding[] argumentBindings = new ReferenceBinding[typeParameters.length];
-                       for (int i = 0; i < argumentBindings.length; i++) {
-                               argumentBindings[i] = lookupBinding(typeParameters[i].getName());
+               } else if (typeX.isParameterized()) {
+                       if (typeX.isRawType()) {
+                               ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName());
+                               RawTypeBinding rtb = lookupEnvironment.createRawType(baseTypeBinding,baseTypeBinding.enclosingType());
+                               return rtb;
+                       } else {
+                           TypeX[] typeParameters = typeX.getTypeParameters();
+                               ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName());
+                               ReferenceBinding[] argumentBindings = new ReferenceBinding[typeParameters.length];
+                               for (int i = 0; i < argumentBindings.length; i++) {
+                                       argumentBindings[i] = lookupBinding(typeParameters[i].getName());
+                               }
+                               ParameterizedTypeBinding ptb = 
+                                       lookupEnvironment.createParameterizedType(baseTypeBinding,argumentBindings,baseTypeBinding.enclosingType());
+                               return ptb;
                        }
-                       ParameterizedTypeBinding ptb = 
-                               lookupEnvironment.createParameterizedType(baseTypeBinding,argumentBindings,baseTypeBinding.enclosingType());
-                       return ptb;
                } else {
                        return lookupBinding(typeX.getName());
                }
diff --git a/tests/java5/generics/bugs/PR91053.aj b/tests/java5/generics/bugs/PR91053.aj
new file mode 100644 (file)
index 0000000..75aa004
--- /dev/null
@@ -0,0 +1,18 @@
+import java.util.*;
+
+aspect X {
+
+    private Set PR91053.aSet = new HashSet();
+
+    public void PR91053.add(String s) {
+        aSet.add(s);
+    }
+
+}
+
+public class PR91053 { 
+
+  public static void main(String[]argv) {
+    new PR91053().add("hello");
+  }
+}
index 96557dfe502a2e7783d92a37eeb687f00dbdf027..fe265050a8daf01e17094bb7848f375e71a74753 100644 (file)
@@ -27,4 +27,8 @@ public class GenericsTests extends XMLBasedAjcTestCase {
        public void testPR91267_2() {
                runTest("NPE using generic methods in aspects 2");
        }
+       
+       public void testPR91053() {
+               runTest("Generics problem with Set");
+       }
 }
index 8dca8410f4737622e9b1b6da7e47fb758ff2623c..e9ef342c371fe1e13f518bf56232a8c4a890461c 100644 (file)
         <compile files="TestBug2.aj" options="-1.5"/>
         <run class="TestBug2"/>
     </ajc-test>
+    
+    <ajc-test dir="java5/generics/bugs" title="Generics problem with Set" vm="1.5">
+      <compile files="PR91053.aj" options="-1.5"/>
+      <run class="PR91053"/>
+   </ajc-test>
  
 </suite>
\ No newline at end of file
index f3f078c371736f419fe6194bc39f74c42d1cde48..3f5c1f39e0c54227c0a520fc9980d467b464dd40 100644 (file)
@@ -28,6 +28,8 @@ public class TypeX implements AnnotatedElement {
         * If this is a parameterized type, these are its parameters
         */
        protected TypeX[] typeParameters;
+       
+       protected boolean isParameterized = false;
 
        /**
         * @param      signature   the bytecode string representation of this Type
@@ -114,6 +116,7 @@ public class TypeX implements AnnotatedElement {
         */
     public static TypeX forParameterizedTypeNames(String name, String[] paramTypeNames) {
                TypeX ret = TypeX.forName(name);
+               ret.setParameterized(true);
                ret.typeParameters = new TypeX[paramTypeNames.length];
                for (int i = 0; i < paramTypeNames.length; i++) {
                        ret.typeParameters[i] = TypeX.forName(paramTypeNames[i]);
@@ -130,6 +133,14 @@ public class TypeX implements AnnotatedElement {
                return ret;
     }
        
+       public static TypeX forRawTypeNames(String name) {
+               TypeX ret = TypeX.forName(name);
+               ret.setParameterized(true);
+               // FIXME asc  no need to mess up the signature is there?
+               // ret.signature = ret.signature+"#RAW";
+               return ret;
+       }
+       
        /**
         * Creates a new type array with a fresh type appended to the end.
         * 
@@ -237,7 +248,8 @@ public class TypeX implements AnnotatedElement {
        public String getBaseName() {
                String name = getName();
                if (isParameterized()) {
-                       return name.substring(0,name.indexOf("<"));
+                       if (isRawType()) return name;
+                       else             return name.substring(0,name.indexOf("<"));
                } else {
                        return name;
                }
@@ -292,9 +304,17 @@ public class TypeX implements AnnotatedElement {
         * Determines if this represents a parameterized type.
         */
        public final boolean isParameterized() {
-               return signature.indexOf("<") != -1; 
-               //(typeParameters != null) && (typeParameters.length > 0);
+               return isParameterized;
+//             return signature.indexOf("<") != -1; 
+//             //(typeParameters != null) && (typeParameters.length > 0);
        }
+       
+       public final boolean isRawType() { 
+           return isParameterized && typeParameters==null;
+       }
+       
+       private final void setParameterized(boolean b) { isParameterized=b;}
+       
     
     /**
      * Returns a TypeX object representing the effective outermost enclosing type
index 04ec34815fc3f18b3a10dc3b9c3f4650e8fad79a..cdcac9fc5cf033a6bf9cadb3f6c18e3d18c0d604 100644 (file)
@@ -137,7 +137,7 @@ public abstract class World implements Dump.INode {
                 dumpState_cantFindTypeExceptions.add(new RuntimeException("Can't find type "+ty.getName()));
             }
         }
-               if (ty.isParameterized()) {
+               if (ty.isParameterized() && !ty.isRawType()) {
                        for (int i = 0; i < ty.typeParameters.length; i++) {
                                ty.typeParameters[i] = resolve(ty.typeParameters[i],allowMissing);
                        }