aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-09-02 10:40:19 +0000
committeracolyer <acolyer>2005-09-02 10:40:19 +0000
commit047173e8683e4ab9004ae2151a8abad886d1b84b (patch)
tree7c70cd87214752972d5159ec43e52d4b703345d5
parentad753aa80558748ab918988809ba6f58b8c26419 (diff)
downloadaspectj-047173e8683e4ab9004ae2151a8abad886d1b84b.tar.gz
aspectj-047173e8683e4ab9004ae2151a8abad886d1b84b.zip
tests and fix for pr99136 (dup adviceDidNotMatch warnings), plus extended testing for pr105479
-rw-r--r--tests/bugs150/pr105479/Driver.java10
-rw-r--r--tests/bugs150/pr105479/ReturnTypeTest.aj13
-rw-r--r--tests/bugs150/pr105479/ReturnTypeTester.java14
-rw-r--r--tests/bugs150/pr105479part2.aj39
-rw-r--r--tests/harness/XLintcflow.java6
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java7
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ajc150.xml26
-rw-r--r--tests/src/org/aspectj/systemtest/xlint/XLintTests.java7
-rw-r--r--tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml7
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java51
10 files changed, 175 insertions, 5 deletions
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<ReturnTypeTester> set = new HashSet<ReturnTypeTester>();
+ 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<ReturnTypeTester> set = new HashSet<ReturnTypeTester>();
+ 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 @@
<ajc-test dir="bugs150" pr="108602" title="parse generic type signature with parameterized type in interface">
<compile files="pr108602.java" options="-1.5"/>
</ajc-test>
-
+
+ <ajc-test dir="bugs150" pr="105479" title="override and covariance with decp - runtime">
+ <compile files="pr105479part2.aj" options="-1.5"/>
+ <run class="pr105479part2">
+ <stdout>
+ <line text="in Test.hashCode()"/>
+ <line text="in Test.hashCode()"/>
+ <line text="id"/>
+ <line text="in Test.hashCode()"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs150/pr105479" pr="105479" title="override and covariance with decp - runtime separate files">
+ <compile files="ReturnTypeTest.aj,ReturnTypeTester.java,Driver.java" options="-1.5"/>
+ <run class="Driver">
+ <stdout>
+ <line text="in Test.hashCode()"/>
+ <line text="in Test.hashCode()"/>
+ <line text="id"/>
+ <line text="in Test.hashCode()"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
<!-- ============================================================================ -->
<!-- ============================================================================ -->
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 @@
</compile>
</ajc-test>
-->
+
+ <ajc-test dir="harness"
+ title="Two Xlint warnings wth cflow?">
+ <compile files="XLintcflow.java" options="-1.5">
+ <message kind="warning" line="4" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
+ </compile>
+ </ajc-test>
\ 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