diff options
author | aclement <aclement> | 2005-08-12 11:02:56 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-08-12 11:02:56 +0000 |
commit | fcb69e778830899386023f587e0837b7e921e04e (patch) | |
tree | ffcc40889969437769f2587ade131d8b79006473 | |
parent | 7fd684f0621e8a8d0ed59b53f5abe2bd4331aa96 (diff) | |
download | aspectj-fcb69e778830899386023f587e0837b7e921e04e.tar.gz aspectj-fcb69e778830899386023f587e0837b7e921e04e.zip |
genericitds: field type mungers now understand a map from type variable names to positions (for generic itds). Some changes to assignable rules to support the new possibilities.
5 files changed, 65 insertions, 25 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index 99d9c8087..a97e52ddb 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -150,13 +150,11 @@ public class GenericsTests extends XMLBasedAjcTestCase { * PASS parameterizedITDs * PASS differing targets (interface/class/aspect) * PASS multiple type variables in an ITD - * TODO using type variables from the target type in your ITD (no type vars of your own) - * TODO parsing ITDs that share type variables with target type - * TODO sharing type variables (methods) - * TODO sharing type variables (fields) - * TODO sharing type variables (constructors) - * TODO sharing type variables and having your own type variables (methods/constructors) - * TODO signature attributes for generic ITDs (public only?) + * PASS parsing ITDs that share type variables with target type + * PASS using type variables from the target type in your field ITD + * TODO using type variables from the target type in your method ITD (but no type vars of your own) + * TODO using type variables from the target type in your ctor ITD (but no type vars of your own) + * TODO using type variables from the target type in your *STATIC* ITD (field/method/ctor) * TODO binary weaving with changing types (moving between generic and simple) * TODO bridge method creation * TODO reusing type variable letter but differing spec across multiple ITDs in one aspect @@ -165,6 +163,11 @@ public class GenericsTests extends XMLBasedAjcTestCase { * PASS recursive type variable definitions * TODO generic aspects * TODO parameterizing ITDs with type variables + * + * defer? + * TODO using type variables from the target type and having your own too (methods) + * TODO using type variables from the target type and having your own too (ctors) + * TODO signature attributes for generic ITDs (public only?) */ public static Test suite() { @@ -220,7 +223,6 @@ public class GenericsTests extends XMLBasedAjcTestCase { // parsing of generic ITD members - public void testParseItdNonStaticMethod() {runTest("Parsing generic ITDs - 1");} public void testParseItdStaticMethod() {runTest("Parsing generic ITDs - 2");} public void testParseItdCtor() {runTest("Parsing generic ITDs - 3");} @@ -228,15 +230,14 @@ public class GenericsTests extends XMLBasedAjcTestCase { // public void testParseItdSharingVars1() {runTest("Parsing generic ITDs - 5");} // public void testParseItdSharingVars2() {runTest("Parsing generic ITDs - 6");} - + // non static - - public void testGenericMethodITD1() {runTest("generic method itd - 1");} // <E> ... (List<? extends E>) - public void testGenericMethodITD2() {runTest("generic method itd - 2");} // <E extends Number> ... (List<? extends E>) called incorrectly - public void testGenericMethodITD3() {runTest("generic method itd - 3");} // <E> ... (List<E>,List<E>) - public void testGenericMethodITD4() {runTest("generic method itd - 4");} // <A,B> ... (List<A>,List<B>) - public void testGenericMethodITD5() {runTest("generic method itd - 5");} // <E> ... (List<E>,List<E>) called incorrectly - public void testGenericMethodITD6() {runTest("generic method itd - 6");} // <E extends Number> ... (List<? extends E>) + public void testGenericMethodITD1() {runTest("generic method itd - 1");} // <E> ... (List<? extends E>) + public void testGenericMethodITD2() {runTest("generic method itd - 2");} // <E extends Number> ... (List<? extends E>) called incorrectly + public void testGenericMethodITD3() {runTest("generic method itd - 3");} // <E> ... (List<E>,List<E>) + public void testGenericMethodITD4() {runTest("generic method itd - 4");} // <A,B> ... (List<A>,List<B>) + public void testGenericMethodITD5() {runTest("generic method itd - 5");} // <E> ... (List<E>,List<E>) called incorrectly + public void testGenericMethodITD6() {runTest("generic method itd - 6");} // <E extends Number> ... (List<? extends E>) public void testGenericMethodITD7() {runTest("generic method itd - 7"); } // <E> ... (List<E>,List<? extends E>) public void testGenericMethodITD8() {runTest("generic method itd - 8"); } // <E> ... (List<E>,List<? extends E>) called incorrectly public void testGenericMethodITD9() {runTest("generic method itd - 9"); } // <R extends Comparable<? super R>> ... (List<R>) @@ -248,7 +249,7 @@ public class GenericsTests extends XMLBasedAjcTestCase { public void testGenericMethodITD15() {runTest("generic method itd - 15");} // <R extends Comparable<? super R>> ... (List<R>) called correctly in a clever way - + // generic ctors public void testGenericCtorITD1() {runTest("generic ctor itd - 1");} // <T> new(List<T>) public void testGenericCtorITD2() {runTest("generic ctor itd - 2");} // <T> new(List<T>,List<? extends T>) @@ -276,10 +277,24 @@ public class GenericsTests extends XMLBasedAjcTestCase { - // sharing a type variable between the ITD and the target generic type -// public void testMethodITDsSharingTvar() {runTest("method itd sharing type variable with generic type");} -// public void testFieldITDsSharingTvar() {runTest("field itd sharing type variable with generic type");} - + // using a type variable from the target generic type in your ITD + public void testFieldITDsUsingTargetTypeVars1() {runTest("field itd using type variable from target type - 1");} + public void testFieldITDsUsingTargetTypeVars2() {runTest("field itd using type variable from target type - 2");} + public void testFieldITDsUsingTargetTypeVars3() {runTest("field itd using type variable from target type - 3");} + public void testFieldITDsUsingTargetTypeVars4() {runTest("field itd using type variable from target type - 4");} + public void testFieldITDsUsingTargetTypeVars5() {runTest("field itd using type variable from target type - 5");} + public void testFieldITDsUsingTargetTypeVars6() {runTest("field itd using type variable from target type - 6");} + public void testFieldITDsUsingTargetTypeVars7() {runTest("field itd using type variable from target type - 7");} + public void testFieldITDsUsingTargetTypeVars8() {runTest("field itd using type variable from target type - 8");} + public void testFieldITDsUsingTargetTypeVars9() {runTest("field itd using type variable from target type - 9");} + public void testFieldITDsUsingTargetTypeVars10(){runTest("field itd using type variable from target type -10");} + public void testFieldITDsUsingTargetTypeVars11(){runTest("field itd using type variable from target type -11");} + public void testFieldITDsUsingTargetTypeVars12(){runTest("field itd using type variable from target type -12");} + public void testFieldITDsUsingTargetTypeVars13(){runTest("field itd using type variable from target type -13");} + public void testFieldITDsUsingTargetTypeVars14(){runTest("field itd using type variable from target type -14");} + public void testFieldITDsUsingTargetTypeVars15(){runTest("field itd using type variable from target type -15");} + public void testFieldITDsUsingTargetTypeVars16(){runTest("field itd using type variable from target type -16");} + // general tests ... usually just more complex scenarios public void testReusingTypeVariableLetters() {runTest("reusing type variable letters");} diff --git a/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java b/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java index a3938ff30..4dd103115 100644 --- a/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java @@ -13,16 +13,18 @@ package org.aspectj.weaver; -import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.List; import java.util.Set; public class NewFieldTypeMunger extends ResolvedTypeMunger { - public NewFieldTypeMunger(ResolvedMember signature, Set superMethodsCalled) { + + public NewFieldTypeMunger(ResolvedMember signature, Set superMethodsCalled, List phantomTypeVariableToRealIndex) { super(Field, signature); signature.setAnnotatedElsewhere(true); this.setSuperMethodsCalled(superMethodsCalled); + this.typeVariableToGenericTypeVariableIndex = phantomTypeVariableToRealIndex; } public ResolvedMember getInitMethod(UnresolvedType aspectType) { @@ -39,7 +41,7 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger { public static ResolvedTypeMunger readField(VersionedDataInputStream s, ISourceContext context) throws IOException { ResolvedTypeMunger munger = new NewFieldTypeMunger( ResolvedMemberImpl.readResolvedMember(s, context), - readSuperMethodsCalled(s)); + readSuperMethodsCalled(s),null); if (ResolvedTypeMunger.persistSourceLocation) munger.setSourceLocation(readSourceLocation(s)); return munger; } diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index a26c851bd..6e92387f3 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -232,9 +232,15 @@ public class ReferenceType extends ResolvedType { } if (this == other) return true; - if (this.isRawType() && other.isParameterizedType()) { + if ((this.isRawType() || this.isGenericType()) && other.isParameterizedType()) { if (isAssignableFrom((ResolvedType)other.getRawType())) return true; } + if (this.isRawType() && other.isGenericType()) { + if (isAssignableFrom((ResolvedType)other.getRawType())) return true; + } + if (this.isGenericType() && other.isRawType()) { + if (isAssignableFrom((ResolvedType)other.getGenericType())) return true; + } if (this.isParameterizedType()) { // look at wildcards... diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java index c3bfaa34a..d548d1bc0 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java @@ -39,6 +39,14 @@ public abstract class ResolvedTypeMunger { protected Kind kind; protected ResolvedMember signature; + // This list records the occurences (in order) of any names specified in the <> + // for a target type for the ITD. So for example, for List<C,B,A> this list + // will be C,B,A - the list is used later to map other occurrences of C,B,A + // across the intertype declaration to the right type variables in the generic + // type upon which the itd is being made. + // might need serializing the class file for binary weaving. + protected List /*String*/ typeVariableToGenericTypeVariableIndex; + public static transient boolean persistSourceLocation = true; private Set /* resolvedMembers */ superMethodsCalled = Collections.EMPTY_SET; @@ -274,5 +282,13 @@ public abstract class ResolvedTypeMunger { return false; } } + + public int getGenericTypeVariableIndexFor(String name) { + return typeVariableToGenericTypeVariableIndex.indexOf(name); + } + + public boolean hasGenericTypeVariableMap() { + return typeVariableToGenericTypeVariableIndex!=null && typeVariableToGenericTypeVariableIndex.size()!=0; + } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index f9c2eabcb..d5f09d801 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -221,6 +221,7 @@ class BcelClassWeaver implements IClassWeaver { } private boolean addSuperInitializer(ResolvedType onType) { + if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType(); IfaceInitList l = (IfaceInitList) addedSuperInitializers.get(onType); if (l != null) return false; l = new IfaceInitList(onType); |