]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr99136 (dup adviceDidNotMatch warnings), plus extended testing...
authoracolyer <acolyer>
Fri, 2 Sep 2005 10:40:19 +0000 (10:40 +0000)
committeracolyer <acolyer>
Fri, 2 Sep 2005 10:40:19 +0000 (10:40 +0000)
tests/bugs150/pr105479/Driver.java [new file with mode: 0644]
tests/bugs150/pr105479/ReturnTypeTest.aj [new file with mode: 0644]
tests/bugs150/pr105479/ReturnTypeTester.java [new file with mode: 0644]
tests/bugs150/pr105479part2.aj [new file with mode: 0644]
tests/harness/XLintcflow.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
tests/src/org/aspectj/systemtest/xlint/XLintTests.java
tests/src/org/aspectj/systemtest/xlint/xlint-tests.xml
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

diff --git a/tests/bugs150/pr105479/Driver.java b/tests/bugs150/pr105479/Driver.java
new file mode 100644 (file)
index 0000000..6bc4b1b
--- /dev/null
@@ -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 (file)
index 0000000..108c531
--- /dev/null
@@ -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 (file)
index 0000000..b26445e
--- /dev/null
@@ -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 (file)
index 0000000..0a2d394
--- /dev/null
@@ -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 (file)
index 0000000..e77445b
--- /dev/null
@@ -0,0 +1,6 @@
+// "Two Xlint warnings wth cflow?"
+
+aspect A {
+         before(): call(* *(..)) && cflow(execution(* *(..))) {
+         }
+}
index af147c2bf2bec92aaed47a02a45c08096f5f7b08..4f6d82ac400fc992fbb2aaf4c0d7a2b668174023 100644 (file)
@@ -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) {
index f6e20ebc83ae50519f4363f3b08aaffc8a23c554..f36716f536d273031503de741a351d2173858d61 100644 (file)
     <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>
+         
     <!-- ============================================================================ -->
     <!-- ============================================================================ -->
     
index e113205c17dc0cb60020e83e60753c55bbc96ed3..21e0fd1f912bd71919b6349584425e81be25edb4 100644 (file)
@@ -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();
+         }
+  }
 
 }
 
index 1620fb5d36333c5ec5fda1318f0fa7515a79904a..05052cce71b78415a3e41e835275baf1b322221b 100644 (file)
   </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
index f27fad1dd7ce980929894650cb8cb6700370034a..45b1bb869a079251e14ec66dcaba27a619cabe67 100644 (file)
@@ -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