]> source.dussan.org Git - aspectj.git/commitdiff
tests and fixes for 93345 and static imports. From Andrew Huff.
authoraclement <aclement>
Mon, 9 May 2005 11:08:28 +0000 (11:08 +0000)
committeraclement <aclement>
Mon, 9 May 2005 11:08:28 +0000 (11:08 +0000)
tests/bugs150/PR93345.aj [new file with mode: 0644]
tests/java5/staticImports/StaticImport.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
tests/src/org/aspectj/systemtest/ajc150/StaticImports.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/SuppressedWarnings.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

diff --git a/tests/bugs150/PR93345.aj b/tests/bugs150/PR93345.aj
new file mode 100644 (file)
index 0000000..4950aa6
--- /dev/null
@@ -0,0 +1,12 @@
+// "XLint warning for advice not applied with cflow(execution)"
+
+class AClass {
+}
+
+aspect AnAspect {
+        pointcut a() : cflow( execution(* *(..)) );
+
+        before() : a() {
+                System.out.println("before a");
+        }
+}
\ No newline at end of file
diff --git a/tests/java5/staticImports/StaticImport.aj b/tests/java5/staticImports/StaticImport.aj
new file mode 100644 (file)
index 0000000..3d82bcb
--- /dev/null
@@ -0,0 +1,9 @@
+// "import static java.lang.System.out"
+
+import static java.lang.System.out;
+
+public class StaticImport{
+ public static void main(String [] args){
+  out.println("hello world");
+ }
+}
index c71386e41dad50a8b01367cd7bf691c6d87b8279..004eb0a0d95269621242ceec6767667d72ca5805 100644 (file)
@@ -34,6 +34,7 @@ public class AllTestsAspectJ150 {
                suite.addTest(AnnotationsBinaryWeaving.suite());
                suite.addTest(AnnotationPointcutsTests.suite());
                suite.addTestSuite(VarargsTests.class);
+               suite.addTestSuite(StaticImports.class);
                suite.addTest(AnnotationRuntimeTests.suite());
                suite.addTestSuite(PerTypeWithinTests.class);
                
diff --git a/tests/src/org/aspectj/systemtest/ajc150/StaticImports.java b/tests/src/org/aspectj/systemtest/ajc150/StaticImports.java
new file mode 100644 (file)
index 0000000..a6de381
--- /dev/null
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *   Andrew Huff - initial implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+public class StaticImports extends XMLBasedAjcTestCase {
+
+   public static Test suite() {
+     return XMLBasedAjcTestCase.loadSuite(StaticImports.class);
+   }
+
+   protected File getSpecFile() {
+     return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+   }
+   
+  public void testImportStaticSystemDotOut() {
+   runTest("import static java.lang.System.out");
+  }
+
+}
index 8f1e7d29585572e4c8c5a788c570b063a6f33a9a..db407560ccaef3fb244c7eb0c386f183e6719367 100644 (file)
@@ -42,5 +42,8 @@ public class SuppressedWarnings extends XMLBasedAjcTestCase {
   public void testSuppression2() {
        runTest("suppressing non-matching advice warnings when multiple source files involved");
   }
-
+  
+  public void testSuppressionWithCflow_pr93345() {
+    runTest("XLint warning for advice not applied with cflow(execution)");
+  }
 }
\ No newline at end of file
index 15afabbfed6e7173439973f20e5bf3821c0bea5b..2832178157873199051d3cbd0928b40fac6b08f9 100644 (file)
@@ -5,6 +5,10 @@
 
 <suite>
 
+    <ajc-test dir="java5/staticImports" title="import static java.lang.System.out">
+        <compile files="StaticImport.aj" options="-1.5"/>
+    </ajc-test>
+
     <ajc-test dir="java5/bridgeMethods" pr="72766" title="Ignore bridge methods">
         <compile files="AspectX.aj" inpath="testcode.jar" options="-showWeaveInfo">
           <message kind="warning" line="7" text="pointcut did not match on the method call to a bridge method."/>
          <message kind="warning" line="11" file="A3.aj"/>
        </compile>
    </ajc-test>
+   
+   <ajc-test dir="bugs150" title="XLint warning for advice not applied with cflow(execution)" pr="93345">
+     <compile options="-Xlint,-1.5" files="PR93345.aj" >
+       <message kind="warning" line="7" text="advice defined in AnAspect has not been applied [Xlint:adviceDidNotMatch]"/>
+     </compile>
+  </ajc-test>
 
    <!-- ======================================================================================= -->
    <!--               annotated aspect members                                                  -->
index 028b229b0903acbff132203ed0ccda58635a901a..b32ebc0c7a8d817f39fd7d453f07632dd6d7e213 100644 (file)
@@ -995,6 +995,7 @@ public class BcelWeaver implements IWeaver {
                deletedTypenames = new ArrayList();
                
         
+               // 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.behaveInJava5Way && 
             world.getLint().adviceDidNotMatch.isEnabled()) {
@@ -1003,15 +1004,15 @@ public class BcelWeaver implements IWeaver {
                        ShadowMunger element = (ShadowMunger) iter.next();
                        if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers
                   BcelAdvice ba = (BcelAdvice)element;
-                  if (!ba.hasMatchedSomething()) {
-                    BcelMethod meth = (BcelMethod)ba.getSignature();
-                    if (meth!=null) {
-                      AnnotationX[] anns = (AnnotationX[])meth.getAnnotations();
-                      // Check if they want to suppress the warning on this piece of advice
-                             if (!Utility.isSuppressing(anns,"adviceDidNotMatch")) {
-                        world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation());
-                      }
-                    }
+                  if (!ba.hasMatchedSomething()) { 
+                                        // 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) {
+                                          if (!(ba.getSignature() instanceof BcelMethod)
+                                              || !Utility.isSuppressing((AnnotationX[])ba.getSignature().getAnnotations(),"adviceDidNotMatch")) {
+                                               world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation());
+                                          }                                                      
+                     }
                   }
                        }
                }