]> source.dussan.org Git - aspectj.git/commitdiff
ensure that reflection based world can cope when given a java.lang.Class that represe...
authoracolyer <acolyer>
Mon, 24 Oct 2005 20:46:51 +0000 (20:46 +0000)
committeracolyer <acolyer>
Mon, 24 Oct 2005 20:46:51 +0000 (20:46 +0000)
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java
weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java
weaver/testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java

index 69ae60a8edca01b77507e9995858a2d28cd456c3..75605b5ed5828f71d03aaadd01f52423fc9a9cd0 100644 (file)
@@ -64,6 +64,10 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
                return this.world;
        }
        
+       protected ReflectionWorld getReflectionWorld() {
+               return (ReflectionWorld) this.world;
+       }
+       
        
        public ReferenceType buildGenericType() {
                throw new UnsupportedOperationException("Shouldn't be asking for generic type at 1.4 source level or lower");
@@ -193,7 +197,7 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
                        Class[] reflectInterfaces = this.myClass.getInterfaces();
                        this.interfaces = new ResolvedType[reflectInterfaces.length];
                        for (int i = 0; i < reflectInterfaces.length; i++) {
-                               this.interfaces[i] = world.resolve(reflectInterfaces[i].getName());
+                               this.interfaces[i] = getReflectionWorld().resolve(reflectInterfaces[i]);
                        }
                }
                return interfaces;
@@ -278,7 +282,7 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
         */
        public ResolvedType getSuperclass() {
                if (this.myClass.getSuperclass() == null) return null;
-               return world.resolve(this.myClass.getSuperclass().getName());
+               return getReflectionWorld().resolve(this.myClass.getSuperclass());
        }
 
        /* (non-Javadoc)
index 52eefe0b60b4c88ca35bc4316cb14e19e4303727..619e5099ab8524c86130b007462d8c1ad4f000a3 100644 (file)
@@ -148,7 +148,7 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
        private static ResolvedType[] toResolvedTypeArray(Class[] classes, World inWorld) {
                ResolvedType[] ret = new ResolvedType[classes.length];
                for (int i = 0; i < ret.length; i++) {
-                       ret[i] = inWorld.resolve(classes[i].getName());
+                       ret[i] = ((ReflectionWorld)inWorld).resolve(classes[i]);
                }
                return ret;
        }
index 3fd57314f9d90692d7d5c57fbe93af4569d8349f..789dc580600fb9c818c595c0623a033507168ce5 100644 (file)
@@ -23,6 +23,7 @@ import org.aspectj.weaver.ReferenceTypeDelegate;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.ResolvedTypeMunger;
+import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.AjAttribute.AdviceAttribute;
 import org.aspectj.weaver.patterns.Pointcut;
@@ -42,6 +43,16 @@ public class ReflectionWorld extends World {
                setBehaveInJava5Way(LangUtil.is15VMOrGreater());
        }
        
+       public ResolvedType resolve(Class aClass) {
+               // classes that represent arrays return a class name that is the signature of the array type, ho-hum...
+               String className = aClass.getName();
+               if (!className.startsWith("[")) {
+                       return resolve(className);
+               } else {
+                       return resolve(UnresolvedType.forSignature(className));
+               }
+       }
+       
        /* (non-Javadoc)
         * @see org.aspectj.weaver.World#resolveDelegate(org.aspectj.weaver.ReferenceType)
         */
index 8f094272530a113c77ada8a0683ca20ec037d155..4bc879daed7d06c6eb2ccc95892819278815ecbc 100644 (file)
@@ -12,6 +12,7 @@
 package org.aspectj.weaver.reflect;
 
 import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 
 import junit.framework.TestCase;
@@ -25,4 +26,11 @@ public class ReflectionWorldTest extends TestCase {
                assertEquals("Ljava/lang/Object;",rt.getSignature());
        }
        
+       public void testArrayTypes() {
+               World world = new ReflectionWorld();
+               String[] strArray = new String[1];
+               ResolvedType rt = world.resolve(UnresolvedType.forSignature(strArray.getClass().getName()));
+               assertTrue(rt.isArray());
+       }
+       
 }