]> source.dussan.org Git - aspectj.git/commitdiff
work in progress to improve MemberImpl
authoraclement <aclement>
Mon, 16 Nov 2009 21:06:44 +0000 (21:06 +0000)
committeraclement <aclement>
Mon, 16 Nov 2009 21:06:44 +0000 (21:06 +0000)
weaver5/java5-testsrc/org/aspectj/weaver/MemberTestCase15.java

index 8014289e7dd393922a735e5a6b0ad9a8d72c6548..7838c069688620350015ac1bf60ff4370cd8799a 100644 (file)
  * ******************************************************************/
 package org.aspectj.weaver;
 
+import java.util.List;
+
 import org.aspectj.weaver.bcel.BcelWorld;
 
 import junit.framework.TestCase;
 
 /**
  * @author colyer
- *
+ * @author clement
  */
 public class MemberTestCase15 extends TestCase {
 
@@ -77,5 +79,79 @@ public class MemberTestCase15 extends TestCase {
                        assertTrue(add.canBeParameterized());
                }               
            }
+           /*
+           public void testGenericReferenceTypeCreation() {
+               UnresolvedType genericType = UnresolvedType.forGenericTypeSignature("Lorg/aspectj/weaver/MemberTestCase15$One;","<T:Ljava/lang/Object;>Ljava/lang/Object;");
+               assertEquals("Porg/aspectj/weaver/MemberTestCase15$One<TT;>;",genericType.getSignature());
+               assertEquals("Lorg/aspectj/weaver/MemberTestCase15$One;",genericType.getErasureSignature());
+           }
+           
+           public void testMemberSignatureCreation() {
+                       World world = new BcelWorld("../weaver5/bin/");
+               //new ReflectionWorld(false, getClass().getClassLoader());
+               world.setBehaveInJava5Way(true);
+               ResolvedType one = world.resolve("org.aspectj.weaver.MemberTestCase15$One<java.lang.String>");
+               assertNotNull(one);
+               assertFalse(one.isMissing());
+               
+               // Look at the methods on the parameterized type One<String>
+               ResolvedMember member = findMethod("getter",one);       
+               String erasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),true);
+               assertEquals("()Ljava/lang/String;",erasedSignature);
+               String nonErasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),false);
+               assertEquals("()Ljava/lang/String;",nonErasedSignature);
+               erasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),true);
+               assertEquals("()Ljava/lang/String;",erasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),false);
+               assertEquals("()Ljava/lang/String;",nonErasedSignature);
+
+               member = findMethod("getterTwo",one);
+               erasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),true);
+               assertEquals("()Ljava/util/List;",erasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),false);
+               assertEquals("()Pjava/util/List<Ljava/lang/String;>;",nonErasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getGenericReturnType(),member.getGenericParameterTypes(),true);
+               assertEquals("()Ljava/util/List;",nonErasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getGenericReturnType(),member.getGenericParameterTypes(),false);
+               assertEquals("()Pjava/util/List<Ljava/lang/String;>;",nonErasedSignature);
+               
+               // Grab the generic type backing the parameterized type
+               ResolvedType oneGeneric = one.getGenericType();
+               assertTrue(oneGeneric.isGenericType());
+               member = findMethod("getterTwo",oneGeneric);
+               erasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),true);
+               assertEquals("()Ljava/util/List;",erasedSignature);
+               erasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),false);
+               assertEquals("()Ljava/util/List;",erasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getReturnType(),member.getParameterTypes(),false);
+               assertEquals("()Pjava/util/List<TT;>;",nonErasedSignature);
+               nonErasedSignature = MemberImpl.typesToSignature(member.getGenericReturnType(),member.getGenericParameterTypes(),false);
+               assertEquals("()Ljava/util/List;",nonErasedSignature);
+               
+               
+               ResolvedType oneRaw = oneGeneric.getRawType();
+               member = findMethod("getterTwo",oneRaw);
+           }
            
+           private ResolvedMember findMethod(String name, ResolvedType type) {
+               ResolvedMember[] members = type.getDeclaredMethods();
+               for (ResolvedMember member: members) {
+                       if (member.getName().equals(name)) {
+                               return member;
+                       }
+               }
+               return null;
+           }
+           
+           // testcode
+           class One<T> {
+               T t;
+               T getter() {
+                       return null;
+               }
+               List<T> getterTwo() {
+                       return null;
+               }
+           }
+           */
 }