From e2703cf67fe6c68cc0e91aecdbfa4e07e51c6fc7 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 16 Mar 2006 15:34:26 +0000 Subject: [PATCH] test and fix for 131932 --- tests/bugs151/pr131932.aj | 21 +++++ .../systemtest/ajc151/Ajc151Tests.java | 80 +++++++++++++++++++ .../org/aspectj/systemtest/ajc151/ajc151.xml | 3 + .../weaver/NewConstructorTypeMunger.java | 4 +- .../aspectj/weaver/NewFieldTypeMunger.java | 1 + .../aspectj/weaver/NewMethodTypeMunger.java | 1 + 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/bugs151/pr131932.aj diff --git a/tests/bugs151/pr131932.aj b/tests/bugs151/pr131932.aj new file mode 100644 index 000000000..648f9ed34 --- /dev/null +++ b/tests/bugs151/pr131932.aj @@ -0,0 +1,21 @@ +import java.util.List; + +aspect Slide74 { + + public X Bar.getFirst() { + return lts.get(0); + } + + Foo.new(List elements) { this(); } + + private List Bar.children;// = new ArrayList(); + + static class Bar { + List lts; + } + +} + +class Foo { + +} diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index c431e763a..93ea08893 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -11,6 +11,7 @@ package org.aspectj.systemtest.ajc151; import java.io.File; +import java.util.Iterator; import java.util.List; import junit.framework.Test; @@ -112,6 +113,85 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("no ClassCastException with generic aspect and unknown type"); } + public void testStructureModelForGenericITD_pr131932() { + //AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("structure model for generic itd"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + + // get the IProgramElements corresponding to the ITDs and classes + IProgramElement foo = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.CLASS,"Foo"); + assertNotNull("Couldn't find Foo element in the tree",foo); + IProgramElement bar = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.CLASS,"Bar"); + assertNotNull("Couldn't find Bar element in the tree",bar); + + IProgramElement method = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.INTER_TYPE_METHOD,"Bar.getFirst()"); + assertNotNull("Couldn't find 'Bar.getFirst()' element in the tree",method); + IProgramElement field = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.INTER_TYPE_FIELD,"Bar.children"); + assertNotNull("Couldn't find 'Bar.children' element in the tree",field); + IProgramElement constructor = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,"Foo.Foo(List)"); + assertNotNull("Couldn't find 'Foo.Foo(List)' element in the tree",constructor); + + // check that the relationship map has 'itd method declared on bar' + List matches = AsmManager.getDefault().getRelationshipMap().get(method); + assertNotNull("itd Bar.getFirst() should have some relationships but does not",matches); + assertTrue("method itd should have one relationship but has " + matches.size(), matches.size() == 1); + List matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("itd Bar.getFirst() should have one target but has " + matchesTargets.size(),matchesTargets.size() == 1); + IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0)); + assertEquals("target of relationship should be the Bar class but is IPE with label " + + target.toLabelString(),bar,target); + + // check that the relationship map has 'itd field declared on bar' + matches = AsmManager.getDefault().getRelationshipMap().get(field); + assertNotNull("itd Bar.children should have some relationships but does not",matches); + assertTrue("field itd should have one relationship but has " + matches.size(), matches.size() == 1); + matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("itd Bar.children should have one target but has " + matchesTargets.size(),matchesTargets.size() == 1); + target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0)); + assertEquals("target of relationship should be the Bar class but is IPE with label " + + target.toLabelString(),bar,target); + + // check that the relationship map has 'itd constructor declared on foo' + matches = AsmManager.getDefault().getRelationshipMap().get(constructor); + assertNotNull("itd Foo.Foo(List) should have some relationships but does not",matches); + assertTrue("constructor itd should have one relationship but has " + matches.size(), matches.size() == 1); + matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("itd Foo.Foo(List) should have one target but has " + matchesTargets.size(),matchesTargets.size() == 1); + target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0)); + assertEquals("target of relationship should be the Foo class but is IPE with label " + + target.toLabelString(),foo,target); + + // check that the relationship map has 'bar aspect declarations method and field itd' + matches = AsmManager.getDefault().getRelationshipMap().get(bar); + assertNotNull("Bar should have some relationships but does not",matches); + assertTrue("Bar should have one relationship but has " + matches.size(), matches.size() == 1); + matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("Bar should have two targets but has " + matchesTargets.size(),matchesTargets.size() == 2); + for (Iterator iter = matchesTargets.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + target = AsmManager.getDefault().getHierarchy().findElementForHandle(element); + if (!target.equals(method) && !target.equals(field)) { + fail("Expected rel target to be " + method.toLabelString() + " or " + field.toLabelString() + + ", found " + target.toLabelString()); + } + } + + // check that the relationship map has 'foo aspect declarations constructor itd' + matches = AsmManager.getDefault().getRelationshipMap().get(foo); + assertNotNull("Foo should have some relationships but does not",matches); + assertTrue("Foo should have one relationship but has " + matches.size(), matches.size() == 1); + matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("Foo should have one target but has " + matchesTargets.size(),matchesTargets.size() == 1); + target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0)); + assertEquals("target of relationship should be the Foo.Foo(List) itd but is IPE with label " + + target.toLabelString(),constructor,target); + } + /* * @AspectJ bugs and enhancements */ diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index 129c1b434..0c03c2b0b 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -252,6 +252,9 @@ + + + diff --git a/weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.java b/weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.java index 411b4d1f2..921a65da8 100644 --- a/weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.java @@ -136,7 +136,9 @@ public class NewConstructorTypeMunger extends ResolvedTypeMunger { // For raw and 'normal' parameterized targets (e.g. Interface, Interface) parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); } - return new NewConstructorTypeMunger(parameterizedSignature,syntheticConstructor,explicitConstructor,getSuperMethodsCalled(),typeVariableAliases); + NewConstructorTypeMunger nctm = new NewConstructorTypeMunger(parameterizedSignature,syntheticConstructor,explicitConstructor,getSuperMethodsCalled(),typeVariableAliases); + nctm.setSourceLocation(getSourceLocation()); + return nctm; } } diff --git a/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java b/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java index 989fa476f..c60a75452 100644 --- a/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java @@ -90,6 +90,7 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger { } NewFieldTypeMunger nftm = new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); nftm.setDeclaredSignature(getSignature()); + nftm.setSourceLocation(getSourceLocation()); return nftm; } diff --git a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java index 4febb7c95..0073b3b5a 100644 --- a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java @@ -107,6 +107,7 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger { } NewMethodTypeMunger nmtm = new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); nmtm.setDeclaredSignature(getSignature()); + nmtm.setSourceLocation(getSourceLocation()); return nmtm; } -- 2.39.5