]> source.dussan.org Git - aspectj.git/commitdiff
refactored generic type handling
authoraclement <aclement>
Mon, 5 Apr 2010 19:37:10 +0000 (19:37 +0000)
committeraclement <aclement>
Mon, 5 Apr 2010 19:37:10 +0000 (19:37 +0000)
weaver/testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java
weaver/testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java
weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java

index b46a5a6a6f7cd4a1104fa7c1139dff4595900b8f..403b2ecb1b74c50f76a8710ec649150e9fde449a 100644 (file)
  * ******************************************************************/
 package org.aspectj.weaver;
 
-import org.aspectj.weaver.bcel.BcelWorld;
-
 import junit.framework.TestCase;
 
+import org.aspectj.weaver.bcel.BcelWorld;
+
 public class BoundedReferenceTypeTestCase extends TestCase {
 
        ReferenceType javaLangClass;
@@ -22,84 +22,85 @@ public class BoundedReferenceTypeTestCase extends TestCase {
        BoundedReferenceType extendsClass;
        BoundedReferenceType superClass;
        BoundedReferenceType extendsWithExtras;
-       
+
        public void testSignature() {
                String extendsSig = extendsClass.getSignature();
-               assertEquals("+Ljava/lang/Class;",extendsSig);
-               assertEquals("-Ljava/lang/Class;",superClass.getSignature());
+               assertEquals("+Ljava/lang/Class;", extendsSig);
+               assertEquals("-Ljava/lang/Class;", superClass.getSignature());
        }
-       
+
        public void testExtendsBounds() {
-               assertFalse("has no lower bound",extendsClass.hasLowerBound());
-               assertNull("no lower bound",extendsClass.getLowerBound());
-               assertEquals(javaLangClass,extendsClass.getUpperBound());
-               assertEquals("no interface bounds",0,extendsClass.getInterfaceBounds().length);
+               assertFalse("has no lower bound", extendsClass.hasLowerBound());
+               assertNull("no lower bound", extendsClass.getLowerBound());
+               assertEquals(javaLangClass, extendsClass.getUpperBound());
+               assertEquals("no interface bounds", 0, extendsClass.getAdditionalBounds().length);
        }
-       
+
        public void testSuperBounds() {
-               assertTrue("has lower bound",superClass.hasLowerBound());
-               assertEquals(javaLangClass,superClass.getLowerBound());
-               assertEquals("Ljava/lang/Object;",superClass.getUpperBound().getSignature());
-               assertEquals("no interface bounds",0,superClass.getInterfaceBounds().length);
+               assertTrue("has lower bound", superClass.hasLowerBound());
+               assertEquals(javaLangClass, superClass.getLowerBound());
+               assertEquals("Ljava/lang/Object;", superClass.getUpperBound().getSignature());
+               assertEquals("no interface bounds", 0, superClass.getAdditionalBounds().length);
        }
-       
+
        public void testIsExtends() {
-               assertTrue(extendsClass.isExtends);
-               assertFalse(superClass.isExtends);
+               assertTrue(extendsClass.kind == BoundedReferenceType.EXTENDS);
+               assertFalse(superClass.kind == BoundedReferenceType.EXTENDS);
        }
-       
+
        public void testIsSuper() {
-               assertTrue(superClass.isSuper);
-               assertFalse(extendsClass.isSuper);
+               assertTrue(superClass.kind == BoundedReferenceType.SUPER);
+               assertFalse(extendsClass.kind == BoundedReferenceType.SUPER);
        }
-       
+
        public void testGetDeclaredInterfacesNoAdditions() {
                ResolvedType[] rt1 = extendsClass.getDeclaredInterfaces();
                ResolvedType[] rt2 = javaLangClass.getDeclaredInterfaces();
-               assertEquals("same length",rt1.length,rt2.length);
+               assertEquals("same length", rt1.length, rt2.length);
                for (int i = 0; i < rt2.length; i++) {
-                       assertEquals("same methods",rt1[i],rt2[i]);
+                       assertEquals("same methods", rt1[i], rt2[i]);
                }
        }
-       
+
        public void testGetDeclaredInterfacesWithInterfaceBounds() {
                ResolvedType[] rt1 = extendsWithExtras.getDeclaredInterfaces();
                ResolvedType[] rt2 = javaLangClass.getDeclaredInterfaces();
-               assertEquals("one extra interface",rt1.length,rt2.length + 1);
+               assertEquals("one extra interface", rt1.length, rt2.length + 1);
                for (int i = 0; i < rt2.length; i++) {
-                       assertEquals("same methods",rt1[i],rt2[i]);
+                       assertEquals("same methods", rt1[i], rt2[i]);
                }
-               assertEquals("Ljava/util/List;",rt1[rt1.length-1].getSignature());
+               assertEquals("Ljava/util/List;", rt1[rt1.length - 1].getSignature());
        }
-       
-       // all other methods in signature are delegated to upper bound... 
+
+       // all other methods in signature are delegated to upper bound...
        // representative test
        public void testGetDeclaredMethodsExtends() {
                ResolvedMember[] rm1 = extendsClass.getDeclaredMethods();
                ResolvedMember[] rm2 = javaLangClass.getDeclaredMethods();
-               assertEquals("same length",rm1.length,rm2.length);
+               assertEquals("same length", rm1.length, rm2.length);
                for (int i = 0; i < rm2.length; i++) {
-                       assertEquals("same methods",rm1[i],rm2[i]);
+                       assertEquals("same methods", rm1[i], rm2[i]);
                }
        }
 
        public void testGetDeclaredMethodsSuper() {
                ResolvedMember[] rm1 = superClass.getDeclaredMethods();
                ResolvedMember[] rm2 = javaLangObject.getDeclaredMethods();
-               assertEquals("same length",rm1.length,rm2.length);
+               assertEquals("same length", rm1.length, rm2.length);
                for (int i = 0; i < rm2.length; i++) {
-                       assertEquals("same methods",rm1[i],rm2[i]);
+                       assertEquals("same methods", rm1[i], rm2[i]);
                }
        }
 
+       @Override
        protected void setUp() throws Exception {
                super.setUp();
                BcelWorld world = new BcelWorld();
                javaLangClass = (ReferenceType) world.resolve(UnresolvedType.forName("java/lang/Class"));
                javaLangObject = (ReferenceType) world.resolve(UnresolvedType.OBJECT);
-               extendsClass = new BoundedReferenceType(javaLangClass,true,world);
-               superClass = new BoundedReferenceType(javaLangClass,false,world);
-               extendsWithExtras = new BoundedReferenceType(javaLangClass,true,world,
-                               new ReferenceType[] {(ReferenceType)world.resolve(UnresolvedType.forName("java/util/List"))});
+               extendsClass = new BoundedReferenceType(javaLangClass, true, world);
+               superClass = new BoundedReferenceType(javaLangClass, false, world);
+               extendsWithExtras = new BoundedReferenceType(javaLangClass, true, world, new ReferenceType[] { (ReferenceType) world
+                               .resolve(UnresolvedType.forName("java/util/List")) });
        }
 }
index 15edbae4b5c49b700b4e15564ee4b884a376b784..9e49854916a621dfc9ea010bc413ecf734b23160 100644 (file)
  * ******************************************************************/
 package org.aspectj.weaver;
 
-import org.aspectj.weaver.bcel.BcelWorld;
-
 import junit.framework.TestCase;
 
+import org.aspectj.weaver.bcel.BcelWorld;
+
 /**
  * @author colyer
- *
+ * 
  */
 public class TypeVariableReferenceTypeTestCase extends TestCase {
 
@@ -27,23 +27,24 @@ public class TypeVariableReferenceTypeTestCase extends TestCase {
        BoundedReferenceType superClass;
        BoundedReferenceType extendsWithExtras;
        BcelWorld world;
-       
+
        public void testConstructionByNameAndVariable() {
-               TypeVariable tv = new TypeVariable("T",javaLangClass);
-               TypeVariableReferenceType tvrt = new TypeVariableReferenceType(tv,world);
-               assertEquals("T",tvrt.getTypeVariable().getName());
-               assertEquals(javaLangClass,tvrt.getUpperBound());
+               TypeVariable tv = new TypeVariable("T", javaLangClass);
+               TypeVariableReferenceType tvrt = new TypeVariableReferenceType(tv, world);
+               assertEquals("T", tvrt.getTypeVariable().getName());
+               assertEquals(javaLangClass, tvrt.getTypeVariable().getUpperBound());
        }
-       
+
+       @Override
        protected void setUp() throws Exception {
                super.setUp();
                world = new BcelWorld();
                javaLangClass = (ReferenceType) world.resolve(UnresolvedType.forName("java/lang/Class"));
                javaLangObject = (ReferenceType) world.resolve(UnresolvedType.OBJECT);
-               extendsClass = new BoundedReferenceType(javaLangClass,true,world);
-               superClass = new BoundedReferenceType(javaLangClass,false,world);
-               extendsWithExtras = new BoundedReferenceType(javaLangClass,true,world,
-                               new ReferenceType[] {(ReferenceType)world.resolve(UnresolvedType.forName("java/util/List"))});
+               extendsClass = new BoundedReferenceType(javaLangClass, true, world);
+               superClass = new BoundedReferenceType(javaLangClass, false, world);
+               extendsWithExtras = new BoundedReferenceType(javaLangClass, true, world, new ReferenceType[] { (ReferenceType) world
+                               .resolve(UnresolvedType.forName("java/util/List")) });
        }
 
 }
index ec2547acd34d3f416167756e36f3fdec2b2705c3..e213b610401439e0c1e6fa76576197c56b1c7e42 100644 (file)
  * ******************************************************************/
 package org.aspectj.weaver;
 
-import org.aspectj.weaver.bcel.BcelWorld;
-
 import junit.framework.TestCase;
 
+import org.aspectj.weaver.bcel.BcelWorld;
+
 public class TypeVariableTestCase extends TestCase {
-       
+
        private UnresolvedType javaLangNumber;
        private UnresolvedType javaLangDouble;
        private UnresolvedType javaUtilList;
        private UnresolvedType javaIoSerializable;
        private World world;
-       
+
        public void testDefaultBounds() {
-               TypeVariable tv = new TypeVariable("T");
-               assertEquals("Object",UnresolvedType.OBJECT,tv.getUpperBound());
-               assertEquals("no additional bounds",0,tv.getAdditionalInterfaceBounds().length);
-               assertNull("no lower bound",tv.getLowerBound());
+               TypeVariable typevariable = new TypeVariable("T");
+               assertNull(typevariable.getUpperBound());
+               assertEquals("Object", UnresolvedType.OBJECT, typevariable.getFirstBound());
+               assertEquals("no additional bounds", 0, typevariable.getSuperInterfaces().length);
        }
-       
+
        public void testName() {
                TypeVariable tv = new TypeVariable("T");
-               assertEquals("T",tv.getName());
+               assertEquals("T", tv.getName());
        }
-       
+
        public void testUpperBound() {
-               TypeVariable tv = new TypeVariable("N",javaLangNumber);
-               assertEquals("java.lang.Number",javaLangNumber,tv.getUpperBound());
+               TypeVariable tv = new TypeVariable("N", javaLangNumber);
+               assertEquals("java.lang.Number", javaLangNumber, tv.getUpperBound());
        }
-       
+
        public void testAdditionalUpperBounds() {
-               TypeVariable tv = new TypeVariable("E",UnresolvedType.OBJECT,new UnresolvedType[] {javaUtilList});
-               assertEquals("1 additional bound",1,tv.getAdditionalInterfaceBounds().length);
-               assertEquals("java.util.List",javaUtilList,tv.getAdditionalInterfaceBounds()[0]);
-       }
-       
-       public void testLowerBound() {
-               TypeVariable tv = new TypeVariable("X",UnresolvedType.OBJECT,new UnresolvedType[0],javaLangDouble);
-               assertEquals("java.lang.Double",javaLangDouble,tv.getLowerBound());
+               TypeVariable tv = new TypeVariable("E", UnresolvedType.OBJECT, new UnresolvedType[] { javaUtilList });
+               assertEquals("1 additional bound", 1, tv.getSuperInterfaces().length);
+               assertEquals("java.util.List", javaUtilList, tv.getSuperInterfaces()[0]);
        }
-       
+
        public void testResolution() {
-               TypeVariable tv = new TypeVariable(
-                                       "T",
-                                       javaLangNumber,
-                                       new UnresolvedType[] {javaUtilList},
-                                       javaLangDouble
-                               );
+               TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaUtilList });
                tv.resolve(world);
-               assertEquals("resolved number",javaLangNumber.resolve(world),tv.getUpperBound());
-               assertEquals("resolved list",javaUtilList.resolve(world),
-                                                                       tv.getAdditionalInterfaceBounds()[0]);
-               assertEquals("resolved double",javaLangDouble.resolve(world),tv.getLowerBound());
+               assertEquals("resolved number", javaLangNumber.resolve(world), tv.getUpperBound());
+               assertEquals("resolved list", javaUtilList.resolve(world), tv.getSuperInterfaces()[0]);
        }
-       
+
        public void testBindWithoutResolve() {
                TypeVariable tv = new TypeVariable("X");
                try {
                        tv.canBeBoundTo(null);
-                       fail ("Should throw illegal state exception");
-               } catch (IllegalStateException ex) {}
+                       fail("Should throw illegal state exception");
+               } catch (IllegalStateException ex) {
+               }
        }
-       
+
        public void testCanBindToUpperMatch() {
-               TypeVariable tv = new TypeVariable("X",javaLangNumber);
+               TypeVariable tv = new TypeVariable("X", javaLangNumber);
                tv.resolve(world);
                assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
        }
-       
+
        public void testCanBindToUpperFail() {
-               TypeVariable tv = new TypeVariable("X",javaLangNumber);
+               TypeVariable tv = new TypeVariable("X", javaLangNumber);
                tv.resolve(world);
-               assertFalse(tv.canBeBoundTo(UnresolvedType.OBJECT.resolve(world)));             
+               assertFalse(tv.canBeBoundTo(UnresolvedType.OBJECT.resolve(world)));
        }
-       
+
        public void testCanBindToInterfaceMatch() {
-               TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[] {javaIoSerializable});
+               TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaIoSerializable });
                tv.resolve(world);
                assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
        }
-       
+
        public void testCanBindToInterfaceFail() {
-               TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[] {javaUtilList});
+               TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaUtilList });
                tv.resolve(world);
-               assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));    
+               assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));
        }
-       
-       public void testCanBindToLowerMatch() {
-               TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[0],javaLangDouble);
-               tv.resolve(world);
-               assertTrue(tv.canBeBoundTo(javaLangNumber.resolve(world)));
-       }
-       
-       public void testCanBindToLowerFail() {
-               TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[0],javaLangNumber);
-               tv.resolve(world);
-               assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));            
-       }
-       
+
+       @Override
        protected void setUp() throws Exception {
                super.setUp();
                javaLangNumber = UnresolvedType.forSignature("Ljava/lang/Number;");
@@ -118,6 +96,7 @@ public class TypeVariableTestCase extends TestCase {
                world = new BcelWorld();
        }
 
+       @Override
        protected void tearDown() throws Exception {
                super.tearDown();
        }