From 047173e8683e4ab9004ae2151a8abad886d1b84b Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 2 Sep 2005 10:40:19 +0000 Subject: [PATCH] tests and fix for pr99136 (dup adviceDidNotMatch warnings), plus extended testing for pr105479 --- tests/bugs150/pr105479/Driver.java | 10 ++++ tests/bugs150/pr105479/ReturnTypeTest.aj | 13 +++++ tests/bugs150/pr105479/ReturnTypeTester.java | 14 +++++ tests/bugs150/pr105479part2.aj | 39 ++++++++++++++ tests/harness/XLintcflow.java | 6 +++ .../systemtest/ajc150/Ajc150Tests.java | 7 +++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 26 +++++++++- .../aspectj/systemtest/xlint/XLintTests.java | 7 +++ .../aspectj/systemtest/xlint/xlint-tests.xml | 7 +++ .../org/aspectj/weaver/bcel/BcelWeaver.java | 51 +++++++++++++++++-- 10 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 tests/bugs150/pr105479/Driver.java create mode 100644 tests/bugs150/pr105479/ReturnTypeTest.aj create mode 100644 tests/bugs150/pr105479/ReturnTypeTester.java create mode 100644 tests/bugs150/pr105479part2.aj create mode 100644 tests/harness/XLintcflow.java diff --git a/tests/bugs150/pr105479/Driver.java b/tests/bugs150/pr105479/Driver.java new file mode 100644 index 000000000..6bc4b1bfc --- /dev/null +++ b/tests/bugs150/pr105479/Driver.java @@ -0,0 +1,10 @@ +public class Driver { + + public static void main(String[] args) { + ReturnTypeTester rtt = new ReturnTypeTester(); + rtt.hashCode(); + System.out.println(rtt.getId()); + if (rtt.hashCode() != "id".hashCode()) throw new RuntimeException("dispatch failure"); + } + +} \ No newline at end of file diff --git a/tests/bugs150/pr105479/ReturnTypeTest.aj b/tests/bugs150/pr105479/ReturnTypeTest.aj new file mode 100644 index 000000000..108c5319d --- /dev/null +++ b/tests/bugs150/pr105479/ReturnTypeTest.aj @@ -0,0 +1,13 @@ +public aspect ReturnTypeTest { + private interface Test { + Object getId(); + int hashCode(); + } + + public int Test.hashCode() { + System.out.println("in Test.hashCode()"); + return getId().hashCode(); + } + + declare parents : ReturnTypeTester implements Test; +} \ No newline at end of file diff --git a/tests/bugs150/pr105479/ReturnTypeTester.java b/tests/bugs150/pr105479/ReturnTypeTester.java new file mode 100644 index 000000000..b26445e1c --- /dev/null +++ b/tests/bugs150/pr105479/ReturnTypeTester.java @@ -0,0 +1,14 @@ +import java.util.HashSet; +import java.util.Set; + +public class ReturnTypeTester { + static Set set = new HashSet(); + static { + ReturnTypeTester tester = new ReturnTypeTester(); + set.add(tester); + } + + public String getId() { + return "id"; + } +} \ No newline at end of file diff --git a/tests/bugs150/pr105479part2.aj b/tests/bugs150/pr105479part2.aj new file mode 100644 index 000000000..0a2d39438 --- /dev/null +++ b/tests/bugs150/pr105479part2.aj @@ -0,0 +1,39 @@ +import java.util.HashSet; +import java.util.Set; + +aspect ReturnTypeTest { + private interface Test { + Object getId(); + int hashCode(); + } + + public int Test.hashCode() { + System.out.println("in Test.hashCode()"); + return getId().hashCode(); + } + + declare parents : ReturnTypeTester implements Test; +} + +class ReturnTypeTester { + static Set set = new HashSet(); + static { + ReturnTypeTester tester = new ReturnTypeTester(); + set.add(tester); + } + + public String getId() { + return "id"; + } +} + +public class pr105479part2 { + + public static void main(String[] args) { + ReturnTypeTester rtt = new ReturnTypeTester(); + rtt.hashCode(); + System.out.println(rtt.getId()); + if (rtt.hashCode() != "id".hashCode()) throw new RuntimeException("dispatch failure"); + } + +} \ No newline at end of file diff --git a/tests/harness/XLintcflow.java b/tests/harness/XLintcflow.java new file mode 100644 index 000000000..e77445b6e --- /dev/null +++ b/tests/harness/XLintcflow.java @@ -0,0 +1,6 @@ +// "Two Xlint warnings wth cflow?" + +aspect A { + before(): call(* *(..)) && cflow(execution(* *(..))) { + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index af147c2bf..4f6d82ac4 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -362,6 +362,13 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("parse generic type signature with parameterized type in interface"); } + public void testOverrideAndCovarianceWithDecPRuntime() { + runTest("override and covariance with decp - runtime"); + } + + public void testOverrideAndCovarianceWithDecPRuntimeMultiFiles() { + runTest("override and covariance with decp - runtime separate files"); + } // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index f6e20ebc8..f36716f53 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -432,7 +432,31 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/org/aspectj/systemtest/xlint/XLintTests.java b/tests/src/org/aspectj/systemtest/xlint/XLintTests.java index e113205c1..21e0fd1f9 100644 --- a/tests/src/org/aspectj/systemtest/xlint/XLintTests.java +++ b/tests/src/org/aspectj/systemtest/xlint/XLintTests.java @@ -105,6 +105,13 @@ public class XLintTests extends org.aspectj.testing.XMLBasedAjcTestCase { // if (is15VMOrGreater) // runTest("7 lint warnings"); // } + + public void testBug99136(){ + runTest("Two Xlint warnings wth cflow?"); + if(ajc.getLastCompilationResult().getWarningMessages().size() != 1){ + fail(); + } + } } diff --git a/tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml b/tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml index 1620fb5d3..05052cce7 100644 --- a/tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml +++ b/tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml @@ -178,5 +178,12 @@ --> + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index f27fad1dd..45b1bb869 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -1007,11 +1007,47 @@ public class BcelWeaver implements IWeaver { deletedTypenames = new ArrayList(); + warnOnUnmatchedAdvice(); + + requestor.weaveCompleted(); + return wovenClassNames; + } + + /** + * In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any + * mungers that did not match anything. + */ + private void warnOnUnmatchedAdvice() { + + class AdviceLocation { + private int lineNo; + private UnresolvedType inAspect; + + public AdviceLocation(BcelAdvice advice) { + this.lineNo = advice.getSourceLocation().getLine(); + this.inAspect = advice.getDeclaringAspect(); + } + + public boolean equals(Object obj) { + if (!(obj instanceof AdviceLocation)) return false; + AdviceLocation other = (AdviceLocation) obj; + if (this.lineNo != other.lineNo) return false; + if (!this.inAspect.equals(other.inAspect)) return false; + return true; + } + + public int hashCode() { + return 37 + 17*lineNo + 17*inAspect.hashCode(); + }; + } + // FIXME asc Should be factored out into Xlint code and done automatically for all xlint messages, ideally. // if a piece of advice hasn't matched anywhere and we are in -1.5 mode, put out a warning if (world.isInJava5Mode() && world.getLint().adviceDidNotMatch.isEnabled()) { List l = world.getCrosscuttingMembersSet().getShadowMungers(); + Set alreadyWarnedLocations = new HashSet(); + for (Iterator iter = l.iterator(); iter.hasNext();) { ShadowMunger element = (ShadowMunger) iter.next(); if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers @@ -1020,6 +1056,16 @@ public class BcelWeaver implements IWeaver { // Because we implement some features of AJ itself by creating our own kind of mungers, you sometimes // find that ba.getSignature() is not a BcelMethod - for example it might be a cflow entry munger. if (ba.getSignature()!=null) { + + // check we haven't already warned on this advice and line + // (cflow creates multiple mungers for the same advice) + AdviceLocation loc = new AdviceLocation(ba); + if (alreadyWarnedLocations.contains(loc)) { + continue; + } else { + alreadyWarnedLocations.add(loc); + } + if (!(ba.getSignature() instanceof BcelMethod) || !Utility.isSuppressing((AnnotationX[])ba.getSignature().getAnnotations(),"adviceDidNotMatch")) { world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation()); @@ -1029,10 +1075,7 @@ public class BcelWeaver implements IWeaver { } } } - - requestor.weaveCompleted(); - return wovenClassNames; - } + } /** * 'typeToWeave' is one from the 'typesForWeaving' list. This routine ensures we process -- 2.39.5