]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for enh 108118, completes @SuppressAjWarnings implementation
authoracolyer <acolyer>
Thu, 29 Sep 2005 15:42:52 +0000 (15:42 +0000)
committeracolyer <acolyer>
Thu, 29 Sep 2005 15:42:52 +0000 (15:42 +0000)
tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj
tests/java5/covariance/CovAspect06.aj
tests/java5/suppressedWarnings/SuppressionDuringMatching.aj [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/BcelAdvice.java
weaver/src/org/aspectj/weaver/bcel/Utility.java

index 9739187f05b9e95ca13f86d628a23339eacfcca1..c4832bfe82373a0869dab896b5108474fd7febe7 100644 (file)
@@ -21,7 +21,7 @@ public aspect AnnotatedAspect05 {
        after() : handler(*) {}
        
        @MethodAnnotation
-       @SuppressAjWarnings
+       @SuppressAjWarnings("adviceDidNotMatch")
        Object around() : call(new(..)) { return proceed(); }
        
        public static void main(String[] args) {
index 34d575ba5ef91085f14b17213adc676284f46b1e..a96618b75309c227e18a46147bc029450403dc91 100644 (file)
@@ -2,7 +2,7 @@ aspect CovAspect06 {
        \r
   pointcut p(): call(Car Sub.getCar());\r
  \r
-  @org.aspectj.lang.annotation.SuppressAjWarnings\r
+  @org.aspectj.lang.annotation.SuppressAjWarnings("adviceDidNotMatch")\r
   before(): p() {\r
        System.out.println("[call(Car Sub.getCar()) matched on '"+thisJoinPoint+":"+thisJoinPoint.getSourceLocation()+"']");\r
   }\r
diff --git a/tests/java5/suppressedWarnings/SuppressionDuringMatching.aj b/tests/java5/suppressedWarnings/SuppressionDuringMatching.aj
new file mode 100644 (file)
index 0000000..0c0cfef
--- /dev/null
@@ -0,0 +1,46 @@
+import org.aspectj.lang.annotation.*;
+
+public aspect SuppressionDuringMatching {
+       
+//     // XLint:unmatchedSuperTypeInCall
+//     // XLint:adviceDidNotApply
+//     before() : call(* Sub.foo()) {
+//             
+//     }
+//     
+//     @SuppressAjWarnings
+//     before() : call(* Sub.foo()) {
+//             
+//     }
+//     
+//     // XLint:unmatchedSuperTypeInCall
+//     @SuppressAjWarnings("adviceDidNotApply")
+//     before() : call(* Sub.foo()) {
+//             
+//     }
+//     
+       
+       // XLint:adviceDidNotApply
+       @SuppressAjWarnings("unmatchedSuperTypeInCall")
+       before() : call(* Sub.foo()) {
+               
+       }
+       
+       
+}
+
+class Super {
+       
+       public void foo() {}
+       
+       void bar() {
+               foo();
+       }
+}
+
+class Sub extends Super {
+       
+       void bar() {
+               foo();
+       }
+}
\ No newline at end of file
index db407560ccaef3fb244c7eb0c386f183e6719367..af778b525f9cd137cd8fb5d97c5e9a521c16bc08 100644 (file)
@@ -46,4 +46,8 @@ public class SuppressedWarnings extends XMLBasedAjcTestCase {
   public void testSuppressionWithCflow_pr93345() {
     runTest("XLint warning for advice not applied with cflow(execution)");
   }
+  
+  public void testSuppressionOfMessagesIssuedDuringMatching() {
+         runTest("SuppressAjWarnings raised during matching");
+  }
 }
\ No newline at end of file
index 0f277569ccf736a1750660fc68d7b393cf708587..ad7ed2fbf6ff4a87ba4a5fb7fe22fcbf8d1b2d09 100644 (file)
         </stderr>
       </run>
    </ajc-test>
+   
+   <ajc-test dir="java5/suppressedWarnings" title="SuppressAjWarnings raised during matching">
+       <compile files="SuppressionDuringMatching.aj" options="-1.5">
+       </compile>
+   </ajc-test>
 
    <!-- ============================================================== -->
     
index 4b08cd5d60f10f39c6bcf8c1219f5d8975311e5a..0c119c09e7770fa9fac02548891e1db534ed84be 100644 (file)
@@ -33,6 +33,7 @@ import org.aspectj.weaver.Member;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.ShadowMunger;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.World;
@@ -40,6 +41,7 @@ import org.aspectj.weaver.ast.Literal;
 import org.aspectj.weaver.ast.Test;
 import org.aspectj.weaver.patterns.ExactTypePattern;
 import org.aspectj.weaver.patterns.ExposedState;
+import org.aspectj.weaver.patterns.PerClause;
 import org.aspectj.weaver.patterns.Pointcut;
 
 /**
@@ -76,6 +78,20 @@ public class BcelAdvice extends Advice {
 
     // ---- implementations of ShadowMunger's methods
     
+       public ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause) {
+               suppressLintWarnings(world);
+               ShadowMunger ret = super.concretize(fromType, world, clause);
+               clearLintSuppressions(world);
+               return ret;
+       }
+       
+       public boolean match(Shadow shadow, World world) {
+               suppressLintWarnings(world);
+               boolean ret = super.match(shadow, world);
+               clearLintSuppressions(world);
+               return ret;
+       }
+       
     public void specializeOn(Shadow shadow) {
                if (getKind() == AdviceKind.Around) {
                        ((BcelShadow)shadow).initializeForAroundClosure();
@@ -98,16 +114,9 @@ public class BcelAdvice extends Advice {
        }
        
        World world = shadow.getIWorld();
-       if (suppressedLintKinds == null) {
-               if (signature instanceof BcelMethod) {
-                       this.suppressedLintKinds = Utility.getSuppressedWarnings(signature.getAnnotations(), world.getLint());
-               } else {
-                       this.suppressedLintKinds = Collections.EMPTY_LIST;
-               }
-       }
-       world.getLint().suppressKinds(suppressedLintKinds);
+       suppressLintWarnings(world);
                pointcutTest = getPointcut().findResidue(shadow, exposedState);
-               world.getLint().clearSuppressions();
+               clearLintSuppressions(world);
                
                // these initializations won't be performed by findResidue, but need to be
                // so that the joinpoint is primed for weaving
@@ -566,4 +575,18 @@ public class BcelAdvice extends Advice {
                return hasMatchedAtLeastOnce;
        }
 
+       protected void suppressLintWarnings(World inWorld) {
+               if (suppressedLintKinds == null) {
+               if (signature instanceof BcelMethod) {
+                       this.suppressedLintKinds = Utility.getSuppressedWarnings(signature.getAnnotations(), inWorld.getLint());
+               } else {
+                       this.suppressedLintKinds = Collections.EMPTY_LIST;
+               }
+       }
+       inWorld.getLint().suppressKinds(suppressedLintKinds);
+       }
+       
+       protected void clearLintSuppressions(World inWorld) {
+               inWorld.getLint().clearSuppressions();
+       }
 }
index ebc3cc86359f696f686f755a4a488bf8e31cb43b..3e6af17a91c1ded2504129a1327ee08756335c69 100644 (file)
@@ -734,7 +734,8 @@ public class Utility {
                for (int j = 0; j < values.length; j++) {
                        // We know values in the array are strings
                                        SimpleElementValue value = (SimpleElementValue)values[j];
-                                       suppressedWarnings.add(lint.getLintKind(value.getValueString()));
+                                       Lint.Kind lintKind = lint.getLintKind(value.getValueString());
+                                       if (lintKind != null) suppressedWarnings.add(lintKind);
                                }
             }
           }