]> source.dussan.org Git - aspectj.git/commitdiff
fixes for 118192
authoraclement <aclement>
Mon, 28 Nov 2005 15:52:50 +0000 (15:52 +0000)
committeraclement <aclement>
Mon, 28 Nov 2005 15:52:50 +0000 (15:52 +0000)
weaver/src/org/aspectj/weaver/UnresolvedType.java
weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java
weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java

index 1b8b62a934d4599cc09c188535f383eb5800d706..360fd5085900dcff473d75516e8bb7451f41bdb7 100644 (file)
@@ -187,6 +187,7 @@ public class UnresolvedType implements TypeVariableDeclaringElement {
     public boolean isGenericWildcard()        { return typeKind == TypeKind.WILDCARD; }
     public boolean isExtends() { return isExtends;}
     public boolean isSuper()   { return isSuper;  }
+    public TypeKind getTypekind() { return typeKind;}
     
     // for any reference type, we can get some extra information...
     public final boolean isArray() {  return signature.startsWith("["); } 
index 26c34db9e347b7549a123cc44fa5d95e1eeb8b6f..2a86a1c47212ff1b223392cf3089b13b1bfdd50c 100644 (file)
@@ -14,17 +14,17 @@ package org.aspectj.weaver.reflect;
 
 import junit.framework.TestCase;
 
+import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.bcel.BcelWorld;
 
 public class ReflectionBasedReferenceTypeDelegateTest extends TestCase {
 
        protected ReflectionWorld world;
        private ResolvedType objectType;
        private ResolvedType classType;
-       private ResolvedType enumType;
-
        
        public void testIsAspect() {
                assertFalse(objectType.isAspect());
@@ -173,6 +173,90 @@ public class ReflectionBasedReferenceTypeDelegateTest extends TestCase {
                assertEquals(0,pointcuts.length);
        }
        
+       
+       
+       public void testSerializableSuperclass() {
+               ResolvedType serializableType = world.resolve("java.io.Serializable");
+               ResolvedType superType = serializableType.getSuperclass();
+        assertTrue("Superclass of serializable should be Object but was "+superType,superType.equals(UnresolvedType.OBJECT));    
+
+        BcelWorld bcelworld = new BcelWorld();
+        bcelworld.setBehaveInJava5Way(true);
+        ResolvedType bcelSupertype = bcelworld.resolve(UnresolvedType.SERIALIZABLE).getSuperclass();
+        assertTrue("Should be null but is "+bcelSupertype,bcelSupertype.equals(UnresolvedType.OBJECT));
+       }
+       
+       public void testSubinterfaceSuperclass() {              
+               ResolvedType ifaceType = world.resolve("java.security.Key");
+               ResolvedType superType = ifaceType.getSuperclass();
+               assertTrue("Superclass should be Object but was "+superType,superType.equals(UnresolvedType.OBJECT));  
+
+        BcelWorld bcelworld = new BcelWorld();
+        bcelworld.setBehaveInJava5Way(true);
+        ResolvedType bcelSupertype = bcelworld.resolve("java.security.Key").getSuperclass();
+        assertTrue("Should be null but is "+bcelSupertype,bcelSupertype.equals(UnresolvedType.OBJECT));
+       }
+       
+       public void testVoidSuperclass() {
+               ResolvedType voidType = world.resolve(Void.TYPE);
+               ResolvedType superType = voidType.getSuperclass();
+               assertNull(superType);
+                  
+        BcelWorld bcelworld = new BcelWorld();
+        bcelworld.setBehaveInJava5Way(true);
+        ResolvedType bcelSupertype = bcelworld.resolve("void").getSuperclass();
+        assertTrue("Should be null but is "+bcelSupertype,bcelSupertype==null);
+       }
+
+       public void testIntSuperclass() {
+               ResolvedType voidType = world.resolve(Integer.TYPE);
+               ResolvedType superType = voidType.getSuperclass();
+               assertNull(superType);
+
+        BcelWorld bcelworld = new BcelWorld();
+        bcelworld.setBehaveInJava5Way(true);
+        ResolvedType bcelSupertype = bcelworld.resolve("int").getSuperclass();
+        assertTrue("Should be null but is "+bcelSupertype,bcelSupertype==null);
+       }
+       
+    public void testGenericInterfaceSuperclass_BcelWorldResolution() {
+        BcelWorld bcelworld = new BcelWorld();
+        bcelworld.setBehaveInJava5Way(true);
+        
+        UnresolvedType javaUtilMap = UnresolvedType.forName("java.util.Map");
+        
+        ReferenceType rawType = (ReferenceType) bcelworld.resolve(javaUtilMap);
+        assertTrue("Should be the raw type ?!? "+rawType.getTypekind(),rawType.isRawType());
+        
+        ReferenceType genericType = (ReferenceType)rawType.getGenericType();
+        assertTrue("Should be the generic type ?!? "+genericType.getTypekind(),genericType.isGenericType());
+        
+        ResolvedType rt = rawType.getSuperclass();
+        assertTrue("Superclass for Map raw type should be Object but was "+rt,rt.equals(UnresolvedType.OBJECT));         
+        
+        ResolvedType rt2 = genericType.getSuperclass();
+        assertTrue("Superclass for Map generic type should be Object but was "+rt2,rt2.equals(UnresolvedType.OBJECT));         
+    }
+    
+    public void testGenericInterfaceSuperclass_ReflectionWorldResolution() {
+        
+        UnresolvedType javaUtilMap = UnresolvedType.forName("java.util.Map");
+        
+        ReferenceType rawType = (ReferenceType) world.resolve(javaUtilMap);
+        assertTrue("Should be the raw type ?!? "+rawType.getTypekind(),rawType.isRawType());
+        
+        ReferenceType genericType = (ReferenceType)rawType.getGenericType();
+        assertTrue("Should be the generic type ?!? "+genericType.getTypekind(),genericType.isGenericType());
+        
+        ResolvedType rt = rawType.getSuperclass();
+        assertTrue("Superclass for Map raw type should be Object but was "+rt,rt.equals(UnresolvedType.OBJECT));     
+        
+        ResolvedType rt2 = genericType.getSuperclass();
+        assertTrue("Superclass for Map generic type should be Object but was "+rt2,rt2.equals(UnresolvedType.OBJECT));       
+    }
+
+       // todo: array of int   
+
        protected void setUp() throws Exception {
                world = new ReflectionWorld();
                objectType = world.resolve("java.lang.Object");
index 9d6e99cb8b7d36b1d28f80c8576ca2ba216b8edd..57909f6df11fdb798e5141bd101edcf6bbf65656 100644 (file)
@@ -129,9 +129,13 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends
                return superInterfaces;
        }
        
+       // If the superclass is null, return Object - same as bcel does
        public ResolvedType getSuperclass() {
-               if (superclass == null && getBaseClass()!=Object.class) // superclass of Object is null
-                 superclass = fromType(this.getBaseClass().getGenericSuperclass());
+               if (superclass == null && getBaseClass()!=Object.class) {// superclass of Object is null
+                 Type t = this.getBaseClass().getGenericSuperclass();
+                 if (t!=null) superclass = fromType(t);
+                 if (t==null) superclass = getWorld().resolve(UnresolvedType.OBJECT);
+               }
                 return superclass;
        }