]> source.dussan.org Git - aspectj.git/commitdiff
420210: additional message keys for declare warning or error
authorAndy Clement <aclement@gopivotal.com>
Wed, 23 Oct 2013 20:16:20 +0000 (13:16 -0700)
committerAndy Clement <aclement@gopivotal.com>
Wed, 23 Oct 2013 20:16:20 +0000 (13:16 -0700)
org.aspectj.matcher/src/org/aspectj/weaver/Checker.java
tests/bugs174/extra_inserts/Code.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc174/Ajc174Tests.java
tests/src/org/aspectj/systemtest/ajc174/ajc174.xml

index 384c5d6cdfc893983149aa3fcd8c2f159e61b70f..4a765a9e5b91362b5d70bf918e1b5858297d5753 100644 (file)
@@ -222,6 +222,22 @@ public class Checker extends ShadowMunger {
                        return shadow.toString();
                } else if (key.equalsIgnoreCase("joinpoint.kind")) {
                        return shadow.getKind().getName();
+               } else if (key.equalsIgnoreCase("joinpoint.enclosingclass")) {
+                       return shadow.getEnclosingType().getName();
+               } else if (key.equalsIgnoreCase("joinpoint.enclosingmember.name")) {
+                       Member member = shadow.getEnclosingCodeSignature();
+                       if (member==null) {
+                               return "";
+                       } else {
+                               return member.getName();
+                       }
+               } else if (key.equalsIgnoreCase("joinpoint.enclosingmember")) {
+                       Member member = shadow.getEnclosingCodeSignature();
+                       if (member==null) {
+                               return "";
+                       } else {
+                               return member.toString();
+                       }
                } else if (key.equalsIgnoreCase("joinpoint.signature")) {
                        return shadow.getSignature().toString();
                } else if (key.equalsIgnoreCase("joinpoint.signature.declaringtype")) {
diff --git a/tests/bugs174/extra_inserts/Code.java b/tests/bugs174/extra_inserts/Code.java
new file mode 100644 (file)
index 0000000..fa4d859
--- /dev/null
@@ -0,0 +1,18 @@
+public aspect Code {
+  declare warning: call(* foo(..)): "Call to foo made inside class {joinpoint.enclosingclass}";
+  declare warning: call(* foo(..)): "Call to foo made inside member {joinpoint.enclosingmember.name}";
+  declare warning: call(* foo(..)): "Call to foo made inside member {joinpoint.enclosingmember}";
+}
+class Bar {
+  public void booble() {
+    foo();
+  }
+  public void foo() {}
+}
+
+class Boo {
+  public void m() {
+    foo();
+  }
+  public void foo() {}
+}
index bf7a4982593e0e7edbece533a774ba1d3479c7a2..e492c5646c7e283acbfbd91529f604060097f7e1 100644 (file)
@@ -21,6 +21,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  */
 public class Ajc174Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        
+       public void testExtraInserts() throws Exception {
+               runTest("extra inserts");
+       }
+       
        public void testMoreConfigurableLint_419279() throws Exception {
                runTest("more configurable lint");
        }
index 09a6c2957f3eba418308d16f897ef9a9a0c939b3..5440b4bad2ce40ed28607a7ad724ff260036c737 100644 (file)
@@ -2,6 +2,17 @@
 
 <suite>
 
+       <ajc-test dir="bugs174/extra_inserts" title="extra inserts">
+               <compile files="Code.java" options="-1.5">
+                       <message kind="warning" line="8"  text="Call to foo made inside class Bar"/>
+                       <message kind="warning" line="15" text="Call to foo made inside class Boo"/>
+                       <message kind="warning" line="8"  text="Call to foo made inside member booble"/>
+                       <message kind="warning" line="15" text="Call to foo made inside member m"/>
+                       <message kind="warning" line="8"  text="Call to foo made inside member void Bar.booble()"/>
+                       <message kind="warning" line="15" text="Call to foo made inside member void Boo.m()"/>
+               </compile>
+       </ajc-test>
+
        <ajc-test dir="bugs174/pr419279" title="more configurable lint">
                <compile files="Code.java" options="-1.5">
                        <message kind="warning" text="advice defined in Code has not been applied [Xlint:adviceDidNotMatch]"/>