import junit.framework.Test;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.apache.bcel.util.ClassPath;
+import org.aspectj.apache.bcel.util.SyntheticRepository;
import org.aspectj.testing.XMLBasedAjcTestCase;
public class GenericsTests extends XMLBasedAjcTestCase {
// runTest("itd incorrectly using type parameter");
// }
- // generic declare parents
+ // ----------------------------------------------------------------------------------------
+ // generic declare parents tests
+ // ----------------------------------------------------------------------------------------
+
public void testPR96220_GenericDecp() {
runTest("generic decp - simple");
+ verifyClassSignature("Basic","Ljava/lang/Object;LJ<Ljava/lang/Double;>;LI<Ljava/lang/Double;>;");
+ }
+
+ // Both the existing type decl and the one adding via decp are parameterized
+ public void testGenericDecpMultipleVariantsOfAParameterizedType1() {
+ runTest("generic decp - implementing two variants #1");
+ }
+
+ // Existing type decl is raw and the one added via decp is parameterized
+ public void testGenericDecpMultipleVariantsOfAParameterizedType2() {
+ runTest("generic decp - implementing two variants #2");
+ }
+
+ // Existing type decl is parameterized and the one added via decp is raw
+ public void testGenericDecpMultipleVariantsOfAParameterizedType3() {
+ runTest("generic decp - implementing two variants #3");
+ }
+
+ // decp is parameterized but it does match the one already on the type
+ public void testGenericDecpMultipleVariantsOfAParameterizedType4() {
+ runTest("generic decp - implementing two variants #4");
+ }
+
+ // same as above four tests for binary weaving
+ public void testGenericDecpMultipleVariantsOfAParameterizedType1_binaryWeaving() {
+ runTest("generic decp binary - implementing two variants #1");
+ }
+
+ public void testGenericDecpMultipleVariantsOfAParameterizedType2_binaryWeaving() {
+ runTest("generic decp binary - implementing two variants #2");
+ }
+
+ // Existing type decl is parameterized and the one added via decp is raw
+ public void testGenericDecpMultipleVariantsOfAParameterizedType3_binaryWeaving() {
+ runTest("generic decp binary - implementing two variants #3");
+ }
+
+ // decp is parameterized but it does match the one already on the type
+ public void testGenericDecpMultipleVariantsOfAParameterizedType4_binaryWeaving() {
+ runTest("generic decp binary - implementing two variants #4");
}
-// public void testGenericDecpMultipleVariantsOfAParameterizedType() {
-// runTest("generic decp - implementing two variants");
-// }
//
// public void testGenericDecpIncorrectNumberOfTypeParams() {
// runTest("generic decp - incorrect number of type parameters");
// 1. public ITDs and separate compilation - are the signatures correct for the new public members?
// 2. ITDF
+
+ // --- helpers
+
+ // Check the signature attribute on a class is correct
+ private void verifyClassSignature(String classname,String sig) {
+ try {
+ ClassPath cp =
+ new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
+ SyntheticRepository sRepos = SyntheticRepository.getInstance(cp);
+ JavaClass clazz = sRepos.loadClass(classname);
+ Signature sigAttr = null;
+ Attribute[] attrs = clazz.getAttributes();
+ for (int i = 0; i < attrs.length; i++) {
+ Attribute attribute = attrs[i];
+ if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
+ }
+ assertTrue("Failed to find signature attribute for class "+classname,sigAttr!=null);
+ assertTrue("Expected signature to be '"+sig+"' but was '"+sigAttr.getSignature()+"'",
+ sigAttr.getSignature().equals(sig));
+ } catch (ClassNotFoundException e) {
+ fail("Couldn't find class "+classname+" in the sandbox directory.");
+ }
+ }
+
}
<run class="Basic"/>
</ajc-test>
- <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants">
- <compile files="Basic2.aj" options="-1.5"/>
- <run class="Basic2"/>
+ <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #1">
+ <compile files="Basic2.aj" options="-1.5">
+ <message kind="error" line="11" text="Cannot declare parent I<java.lang.Integer> onto type Basic2 since it already has I<java.lang.String> in its hierarchy"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #2">
+ <compile files="Basic2b.aj" options="-1.5">
+ <message kind="error" line="10" text="Cannot declare parent I<java.lang.Integer> onto type Basic2b since it already has I in its hierarchy"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #3">
+ <compile files="Basic2c.aj" options="-1.5">
+ <message kind="error" line="10" text="Cannot declare parent I onto type Basic2c since it already has I<java.lang.Double> in its hierarchy"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #4">
+ <compile files="Basic2d.aj" options="-1.5"/>
</ajc-test>
+
+ <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #1">
+ <weave classesFiles="Base1.java" aspectsFiles="Asp1.aj" options="-1.5,-showWeaveInfo">
+ <message kind="error" line="2" text="Cannot declare parent I<java.lang.Integer> onto type Base1 since it already has I<java.lang.String> in its hierarchy"/>
+ </weave>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #2">
+ <weave classesFiles="Base2.java" aspectsFiles="Asp2.aj" options="-1.5,-showWeaveInfo">
+ <message kind="error" line="2" text="Cannot declare parent I<java.lang.Integer> onto type Base2 since it already has I in its hierarchy"/>
+ </weave>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #3">
+ <weave classesFiles="Base3.java" aspectsFiles="Asp3.aj" options="-1.5,-showWeaveInfo">
+ <message kind="error" line="2" text="Cannot declare parent I onto type Base3 since it already has I<java.lang.Double> in its hierarchy"/>
+ </weave>
+ </ajc-test>
+
+ <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #4">
+ <weave classesFiles="Base4.java" aspectsFiles="Asp4.aj" options="-1.5,-showWeaveInfo"/>
+ </ajc-test>
+
+<!-- -->
<ajc-test dir="java5/generics/decp" title="generic decp - incorrect number of type parameters">
<compile files="Basic3.aj" options="-1.5"/>