]> source.dussan.org Git - aspectj.git/commitdiff
delegates modified to return the same thing as BCEL. Ctors have the name <init>...
authoraclement <aclement>
Fri, 9 Dec 2005 08:40:12 +0000 (08:40 +0000)
committeraclement <aclement>
Fri, 9 Dec 2005 08:40:12 +0000 (08:40 +0000)
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java
weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java
weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java

index 5063fb0a0c2b29ce29782b31f6d54bd8b55d17c9..3214156cd4bdb4e89633b832d65e7e3f01a08471 100644 (file)
@@ -153,8 +153,9 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
                   new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.CONSTRUCTOR,
                                toResolvedType(aConstructor.getDeclaringClass(),(ReflectionWorld)inWorld),
                                aConstructor.getModifiers(),
-                               toResolvedType(aConstructor.getDeclaringClass(),(ReflectionWorld)inWorld),
-                               "init",
+                               // to return what BCEL returns, the return type for ctor is void
+                               ResolvedType.VOID,//toResolvedType(aConstructor.getDeclaringClass(),(ReflectionWorld)inWorld),
+                               "<init>",
                                toResolvedTypeArray(aConstructor.getParameterTypes(),inWorld),
                                toResolvedTypeArray(aConstructor.getExceptionTypes(),inWorld),
                                aConstructor
index cc0407c5c52519cfd809d89929a99c27ec885f0c..fe5aaec0a7f89ce707b51bac336eb2eac1227335 100644 (file)
@@ -12,6 +12,9 @@
 package org.aspectj.weaver.reflect;
 
 
+import java.util.HashSet;
+import java.util.Set;
+
 import junit.framework.TestCase;
 
 import org.aspectj.weaver.ReferenceType;
@@ -130,7 +133,7 @@ public class ReflectionBasedReferenceTypeDelegateTest extends TestCase {
                assertEquals(1,methods[idx].getExceptions().length);
                assertEquals(world.resolve("java.lang.Exception"),methods[idx].getExceptions()[0]);
                int baridx = findMethod("bar", methods);
-               int initidx = findMethod("init", methods);
+               int initidx = findMethod("<init>", methods);
                assertTrue(baridx > -1);
                assertTrue(initidx > -1);
                assertTrue(baridx != initidx && baridx != idx && idx <= 2 && initidx <= 2 && baridx <= 2);
@@ -238,6 +241,51 @@ public class ReflectionBasedReferenceTypeDelegateTest extends TestCase {
         assertTrue("Superclass for Map generic type should be Object but was "+rt2,rt2.equals(UnresolvedType.OBJECT));         
     }
     
+    // FIXME asc maybe.  The reflection list of methods returned doesn't include <clinit> (the static initializer) ... is that really a problem.
+    public void testCompareSubclassDelegates() {
+       
+       boolean barfIfClinitMissing = false;
+        world.setBehaveInJava5Way(true);
+        
+        BcelWorld bcelWorld = new BcelWorld();
+        bcelWorld.setBehaveInJava5Way(true);
+        UnresolvedType javaUtilHashMap = UnresolvedType.forName("java.util.HashMap");
+        ReferenceType rawType =(ReferenceType)bcelWorld.resolve(javaUtilHashMap );
+        
+        ReferenceType rawReflectType =(ReferenceType)world.resolve(javaUtilHashMap );
+        ResolvedMember[] rms1 = rawType.getDelegate().getDeclaredMethods();
+        ResolvedMember[] rms2 = rawReflectType.getDelegate().getDeclaredMethods();
+        StringBuffer errors = new StringBuffer();
+        Set one = new HashSet();
+        for (int i = 0; i < rms1.length; i++) {
+                       one.add(rms1[i].toString());
+               }
+        Set two = new HashSet();
+        for (int i = 0; i < rms2.length; i++) {
+                       two.add(rms2[i].toString());
+               }
+        for (int i = 0;i<rms2.length;i++) {
+               if (!one.contains(rms2[i].toString())) {
+                       errors.append("Couldn't find "+rms2[i].toString()+" in the bcel set\n");
+               }
+        }
+        for (int i = 0;i<rms1.length;i++) {
+               if (!two.contains(rms1[i].toString())) {
+                       if (!barfIfClinitMissing && rms1[i].getName().equals("<clinit>")) continue;
+                       errors.append("Couldn't find "+rms1[i].toString()+" in the reflection set\n");
+               }
+        }
+        assertTrue("Errors:"+errors.toString(),errors.length()==0);
+        
+        if (barfIfClinitMissing) {
+               // the numbers must be exact
+            assertEquals(rms1.length,rms2.length);             
+        } else {
+               // the numbers can be out by one in favour of bcel
+               assertTrue("Should be one extra (clinit) in BCEL case, but bcel="+rms1.length+" reflect="+rms2.length,rms1.length==rms2.length+1);
+        }
+    }
+           
        // todo: array of int   
 
        protected void setUp() throws Exception {
index d153ccdc75548b728d2a4c92d6aec2495331a45e..a5c57f13f6e120fc718ee0a6733c5d6d6f235155 100644 (file)
@@ -213,8 +213,9 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends
                new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.METHOD,
                        getGenericResolvedType(),
                        forConstructor.getModifiers(),
-                       getGenericResolvedType(),
-                       "init",
+                       // to return what BCEL returns the return type is void
+                       ResolvedType.VOID,//getGenericResolvedType(),
+                       "<init>",
                        typeConverter.fromTypes(forConstructor.getParameterTypes()),
                        typeConverter.fromTypes(forConstructor.getExceptionTypes()),
                        forConstructor