summaryrefslogtreecommitdiffstats
path: root/weaver5/java5-testsrc
diff options
context:
space:
mode:
authoraclement <aclement>2010-04-05 19:37:01 +0000
committeraclement <aclement>2010-04-05 19:37:01 +0000
commitca7ff6d5d499067c7abe5d6536598e70d793d37b (patch)
treedd21b7227ba38fc3b9074594a22769e32765fd2e /weaver5/java5-testsrc
parent44e5de95094e70098bc64872efdd0a3237f90740 (diff)
downloadaspectj-ca7ff6d5d499067c7abe5d6536598e70d793d37b.tar.gz
aspectj-ca7ff6d5d499067c7abe5d6536598e70d793d37b.zip
refactored generic type handling
Diffstat (limited to 'weaver5/java5-testsrc')
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java77
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java64
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableTestCase.java105
3 files changed, 132 insertions, 114 deletions
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java b/weaver5/java5-testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java
index b46a5a6a6..403b2ecb1 100644
--- a/weaver5/java5-testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/BoundedReferenceTypeTestCase.java
@@ -11,10 +11,10 @@
* ******************************************************************/
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")) });
}
}
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java b/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java
index 15edbae4b..367a4fc93 100644
--- a/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableReferenceTypeTestCase.java
@@ -11,39 +11,71 @@
* ******************************************************************/
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 {
ReferenceType javaLangClass;
+ ReferenceType jlNumber;
ReferenceType javaLangObject;
BoundedReferenceType extendsClass;
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());
- }
-
+
+ @Override
protected void setUp() throws Exception {
super.setUp();
- world = new BcelWorld();
+ world = new BcelWorld("../bin");
+ world.setBehaveInJava5Way(true);
javaLangClass = (ReferenceType) world.resolve(UnresolvedType.forName("java/lang/Class"));
+ jlNumber = (ReferenceType) world.resolve(UnresolvedType.forSignature("Ljava/lang/Number;"));
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")) });
+ }
+
+ public void testConstructionByNameAndVariable() {
+ TypeVariable tv = new TypeVariable("T", javaLangClass);
+ TypeVariableReferenceType tvrt = new TypeVariableReferenceType(tv, world);
+ assertEquals("T", tvrt.getTypeVariable().getName());
+ assertEquals(javaLangClass, tvrt.getTypeVariable().getUpperBound());
+ }
+
+ public void testBounds() {
+ // Load up the testclass from below
+ ResolvedType testerClass = world.resolve(Tester1.class.getName());
+ ResolvedType genericTesterClass = testerClass.getGenericType();
+
+ // Check the declaration type variable
+ TypeVariable[] typevars = genericTesterClass.getTypeVariables();
+ TypeVariable typevar = typevars[0];
+ assertEquals(jlNumber, typevar.getUpperBound());
+ assertEquals("T", typevar.getName());
+ ResolvedMember member = genericTesterClass.getDeclaredMethods()[1];
+
+ // getParameterTypes() returning the erased parameter
+ UnresolvedType param = member.getParameterTypes()[0];
+ assertEquals(jlNumber, param);
+
+ // Check the type variable reference
+ TypeVariableReferenceType tvReference = (TypeVariableReferenceType) member.getGenericParameterTypes()[0];
+ assertEquals("T", tvReference.getTypeVariableName());
+ assertEquals(jlNumber, tvReference.getUpperBound());
+ assertEquals(jlNumber, tvReference.getDelegate().getResolvedTypeX());
+ }
+
+ class Tester1<T extends Number> {
+ public void method(T t) {
+ }
}
}
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableTestCase.java b/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableTestCase.java
index ec2547acd..8ef8f70c1 100644
--- a/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableTestCase.java
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/TypeVariableTestCase.java
@@ -11,104 +11,88 @@
* ******************************************************************/
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() {
+
+ public void testName() {
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());
+ assertEquals("T", tv.getName());
}
-
- public void testName() {
+
+ public void testDefaultBounds() {
TypeVariable tv = new TypeVariable("T");
- assertEquals("T",tv.getName());
+ assertEquals("Object", UnresolvedType.OBJECT, tv.getFirstBound());
+ assertNull(tv.getUpperBound());
+ assertEquals("no additional bounds", 0, tv.getSuperInterfaces().length);
}
-
+
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]);
+
+ tv = new TypeVariable("E", null, 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 +102,7 @@ public class TypeVariableTestCase extends TestCase {
world = new BcelWorld();
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
}