From f743fb210e1b7aa8cdb45e7bda53aa336f912edf Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 10 Feb 2006 11:25:44 +0000 Subject: fix for 120356 - better feedback for DEOW when using @AJ. (from helen) --- tests/bugs151/pr120356/A.java | 15 ++++++ tests/bugs151/pr120356/C.java | 11 ++++ .../org/aspectj/systemtest/ajc151/Ajc151Tests.java | 63 ++++++++++++++++++++++ tests/src/org/aspectj/systemtest/ajc151/ajc151.xml | 14 +++++ 4 files changed, 103 insertions(+) create mode 100644 tests/bugs151/pr120356/A.java create mode 100644 tests/bugs151/pr120356/C.java (limited to 'tests') diff --git a/tests/bugs151/pr120356/A.java b/tests/bugs151/pr120356/A.java new file mode 100644 index 000000000..628205610 --- /dev/null +++ b/tests/bugs151/pr120356/A.java @@ -0,0 +1,15 @@ + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.DeclareWarning; +import org.aspectj.lang.annotation.DeclareError; + +@Aspect +public class A { + + @DeclareWarning("execution(* C.warningMethod())") + static final String warning = "warning"; + + @DeclareError("execution(* C.badMethod())") + static final String error = "error"; + +} diff --git a/tests/bugs151/pr120356/C.java b/tests/bugs151/pr120356/C.java new file mode 100644 index 000000000..91ef6ab6c --- /dev/null +++ b/tests/bugs151/pr120356/C.java @@ -0,0 +1,11 @@ + + +public class C { + + public void warningMethod() { + } + + public void badMethod() { + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index c2080edb9..7e209d0b5 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -11,12 +11,14 @@ package org.aspectj.systemtest.ajc151; import java.io.File; +import java.util.List; import junit.framework.Test; import org.aspectj.asm.AsmManager; import org.aspectj.asm.IHierarchy; import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.internal.Relationship; import org.aspectj.systemtest.ajc150.GenericsTests; import org.aspectj.testing.XMLBasedAjcTestCase; @@ -86,6 +88,67 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("warning when inherited pointcut not made concrete"); } + public void testAtAspectDEOWInStructureModel_pr120356() { + //AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("@AJ deow appear correctly when structure model is generated"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + + // get the IProgramElements corresponding to the @DeclareWarning statement + // and the method it matches. + IProgramElement warningMethodIPE = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.METHOD,"warningMethod()"); + assertNotNull("Couldn't find 'warningMethod()' element in the tree",warningMethodIPE); + IProgramElement atDeclareWarningIPE = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.FIELD,"warning"); + assertNotNull("Couldn't find @DeclareWarning element in the tree",atDeclareWarningIPE); + + // check that the method has a matches declare relationship with @DeclareWarning + List matches = AsmManager.getDefault().getRelationshipMap().get(warningMethodIPE); + assertNotNull("warningMethod should have some relationships but does not",matches); + assertTrue("warningMethod should have one relationships but has " + matches.size(),matches.size()==1); + List matchesTargets = ((Relationship)matches.get(0)).getTargets(); + assertTrue("warningMethod should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1); + IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0)); + assertEquals("target of relationship should be the @DeclareWarning 'warning' but is IPE with label " + + target.toLabelString(),atDeclareWarningIPE,target); + + // check that the @DeclareWarning has a matches relationship with the warningMethod + List matchedBy = AsmManager.getDefault().getRelationshipMap().get(atDeclareWarningIPE); + assertNotNull("@DeclareWarning should have some relationships but does not",matchedBy); + assertTrue("@DeclareWarning should have one relationship but has " + matchedBy.size(), matchedBy.size() == 1); + List matchedByTargets = ((Relationship)matchedBy.get(0)).getTargets(); + assertTrue("@DeclareWarning 'matched by' relationship should have one target " + + "but has " + matchedByTargets.size(), matchedByTargets.size() == 1); + IProgramElement matchedByTarget = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchedByTargets.get(0)); + assertEquals("target of relationship should be the warningMethod but is IPE with label " + + matchedByTarget.toLabelString(),warningMethodIPE,matchedByTarget); + + // get the IProgramElements corresponding to the @DeclareError statement + // and the method it matches. + IProgramElement errorMethodIPE = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.METHOD,"badMethod()"); + assertNotNull("Couldn't find 'badMethod()' element in the tree",errorMethodIPE); + IProgramElement atDeclarErrorIPE = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.FIELD,"error"); + assertNotNull("Couldn't find @DeclareError element in the tree",atDeclarErrorIPE); + + // check that the @DeclareError has a matches relationship with the badMethod + List matchedByE = AsmManager.getDefault().getRelationshipMap().get(atDeclarErrorIPE); + assertNotNull("@DeclareError should have some relationships but does not",matchedByE); + assertTrue("@DeclareError should have one relationship but has " + matchedByE.size(), matchedByE.size() == 1); + List matchedByTargetsE = ((Relationship)matchedByE.get(0)).getTargets(); + assertTrue("@DeclareError 'matched by' relationship should have one target " + + "but has " + matchedByTargetsE.size(), matchedByTargetsE.size() == 1); + IProgramElement matchedByTargetE = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchedByTargetsE.get(0)); + assertEquals("target of relationship should be the badMethod but is IPE with label " + + matchedByTargetE.toLabelString(),errorMethodIPE,matchedByTargetE); + + } + + public void testAtAspectNoNPEWithDEOWWithoutStructureModel_pr120356() { + runTest("@AJ no NPE with deow when structure model isn't generated"); + } + /* * Load-time weaving bugs and enhancements */ diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index 5898a17a4..e3b67929a 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -142,6 +142,20 @@ + + + + + + + + + + + + + + -- cgit v1.2.3