From b91e3abfe2d9fcafac1eabaefab0f1c3ba8ae55a Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 19 Feb 2008 22:01:34 +0000 Subject: [PATCH] 204505: testcode and fix: poorly documented method in ResolvedMemberImpl now creates a sig based on the erasure of the type variable rather than using the type variable itself. Passes this case but could be related situations that fail... --- tests/bugs160/pr204505/Bug.java | 16 ++++ ...terfaceWithGenericArgumentPointcutBug.java | 88 +++++++++++++++++++ .../systemtest/ajc160/Ajc160Tests.java | 4 +- .../org/aspectj/systemtest/ajc160/ajc160.xml | 12 +++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tests/bugs160/pr204505/Bug.java create mode 100644 tests/bugs160/pr204505/GenericInterfaceWithGenericArgumentPointcutBug.java diff --git a/tests/bugs160/pr204505/Bug.java b/tests/bugs160/pr204505/Bug.java new file mode 100644 index 000000000..e1e1ec55e --- /dev/null +++ b/tests/bugs160/pr204505/Bug.java @@ -0,0 +1,16 @@ +import java.util.*; + +interface GenericIFace { + public void save(B bean); + public void saveAll(Collection beans); +} + +class C implements GenericIFace { + public void save(A bean) {} + public void saveAll(Collection bean) {} +} + +aspect X { + before(): execution(* GenericIFace.save*(..)) { } +// before(): execution(* GenericIFace+.save*(..)) { } +} diff --git a/tests/bugs160/pr204505/GenericInterfaceWithGenericArgumentPointcutBug.java b/tests/bugs160/pr204505/GenericInterfaceWithGenericArgumentPointcutBug.java new file mode 100644 index 000000000..f355eb6ee --- /dev/null +++ b/tests/bugs160/pr204505/GenericInterfaceWithGenericArgumentPointcutBug.java @@ -0,0 +1,88 @@ +package mypackage; + +import java.util.Collection; +import junit.framework.TestCase; + +/** + * A test case depicting the scenario where a parameterized interface includes a method + * that takes a parameterized object. A interface-based pointcut (that does not include + * '+') fails to select such a method. + * + * @author Ramnivas Laddad + * + */ +public class GenericInterfaceWithGenericArgumentPointcutBug extends TestCase { + private GenericInterface testObject = new GenericImpl(); + + public static void main(String[] args) throws Exception { + GenericInterfaceWithGenericArgumentPointcutBug instance = new GenericInterfaceWithGenericArgumentPointcutBug(); + instance.setUp(); + instance.testGenericInterfaceGenericArgExecution(); + instance.setUp(); + instance.testGenericInterfaceNonGenericArgExecution(); + instance.setUp(); + instance.testgenericInterfaceSubtypeGenericArgExecution(); + } + + @Override + protected void setUp() throws Exception { + TestAspect.aspectOf().genericInterfaceNonGenericArgExecutionCount = 0; + TestAspect.aspectOf().genericInterfaceGenericArgExecutionCount = 0; + TestAspect.aspectOf().genericInterfaceSubtypeGenericArgExecutionCount = 0; + } + + public void testGenericInterfaceNonGenericArgExecution() { + testObject.save(""); + assertEquals(1, TestAspect.aspectOf().genericInterfaceNonGenericArgExecutionCount); + } + + public void testGenericInterfaceGenericArgExecution() { + testObject.saveAll(null); + assertEquals(1, TestAspect.aspectOf().genericInterfaceGenericArgExecutionCount); + } + + public void testgenericInterfaceSubtypeGenericArgExecution() { + testObject.saveAll(null); + assertEquals(1, TestAspect.aspectOf().genericInterfaceSubtypeGenericArgExecutionCount); + } + + static interface GenericInterface { + public void save(T bean); + public void saveAll(Collection beans); + } + + static class GenericImpl implements GenericInterface { + public void save(T bean) {} + public void saveAll(Collection beans) {} + } + + static aspect TestAspect { + int genericInterfaceNonGenericArgExecutionCount; + int genericInterfaceGenericArgExecutionCount; + int genericInterfaceSubtypeGenericArgExecutionCount; + + pointcut genericInterfaceNonGenericArgExecution() + : execution(* GenericInterface.save(..)); + + pointcut genericInterfaceGenericArgExecution() + : execution(* GenericInterface.saveAll(..)); + + pointcut genericInterfaceSubtypeGenericArgExecution() + : execution(* GenericInterface+.saveAll(..)); + + before() : genericInterfaceNonGenericArgExecution() { + genericInterfaceNonGenericArgExecutionCount++; + } + + before() : genericInterfaceGenericArgExecution() { + genericInterfaceGenericArgExecutionCount++; + } + + before() : genericInterfaceSubtypeGenericArgExecution() { + genericInterfaceSubtypeGenericArgExecutionCount++; + } + } +} + + + diff --git a/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java b/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java index 56a16772b..3b635dd4b 100644 --- a/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java @@ -19,9 +19,11 @@ import junit.framework.Test; * These are tests for AspectJ1.6.0 */ public class Ajc160Tests extends org.aspectj.testing.XMLBasedAjcTestCase { - + public void testBoundsCheckShouldFail_pr219298() { runTest("bounds check failure");} public void testBoundsCheckShouldFail_pr219298_2() { runTest("bounds check failure - 2");} + public void testGenericMethodMatching_pr204505_1() { runTest("generics method matching - 1");} + public void testGenericMethodMatching_pr204505_2() { runTest("generics method matching - 2");} public void testDecFieldProblem_pr218167() { runTest("dec field problem");} public void testGenericsSuperITD_pr206911() { runTest("generics super itd"); } public void testGenericsSuperITD_pr206911_2() { runTest("generics super itd - 2"); } diff --git a/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml b/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml index 7fc993fc2..8d4225821 100644 --- a/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml +++ b/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml @@ -3,6 +3,18 @@ + + + + + + + + + + + + -- 2.39.5