]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for 135068: verifyerror for @AJ
authoraclement <aclement>
Tue, 16 May 2006 07:38:53 +0000 (07:38 +0000)
committeraclement <aclement>
Tue, 16 May 2006 07:38:53 +0000 (07:38 +0000)
16 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
tests/bugs152/pr135068/A.java [new file with mode: 0644]
tests/bugs152/pr135068/Aaj.aj [new file with mode: 0644]
tests/bugs152/pr135068/Ajava.java [new file with mode: 0644]
tests/bugs152/pr135068/Ajava2.java [new file with mode: 0644]
tests/bugs152/pr135068/C.java [new file with mode: 0644]
tests/bugs152/pr135068/C2.java [new file with mode: 0644]
tests/bugs152/pr135068/aop.xml [new file with mode: 0644]
tests/bugs152/pr135068/t/Aaj.aj [new file with mode: 0644]
tests/bugs152/pr135068/t/Ajava.java [new file with mode: 0644]
tests/bugs152/pr135068/t/Ajava2.java [new file with mode: 0644]
tests/bugs152/pr135068/t/C.java [new file with mode: 0644]
tests/bugs152/pr135068/t/C2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java

index a79ef093138827719942bf58a3d246c1674becbe..09d6b441ee76cf89be03d9cc39d69dcb7cd9b15f 100644 (file)
@@ -282,6 +282,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
         * 3) Advice must not have any other @AspectJ annotations
         * 4) After throwing advice must declare the thrown formal
         * 5) After returning advice must declare the returning formal
+        * 6) Advice must not be static
         */
        private void validateAdvice(MethodDeclaration methodDeclaration) {
                
@@ -295,6 +296,11 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                        methodDeclaration.scope.problemReporter()
                                .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"advice must be public");
                }
+
+               if (Modifier.isStatic(methodDeclaration.modifiers)) {
+                       methodDeclaration.scope.problemReporter()
+                               .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"advice can not be declared static");
+               }
                                
                if (ajAnnotations.hasMultipleAdviceAnnotations) {
                        methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.duplicateAdviceAnnotation);
diff --git a/tests/bugs152/pr135068/A.java b/tests/bugs152/pr135068/A.java
new file mode 100644 (file)
index 0000000..adbab3f
--- /dev/null
@@ -0,0 +1,3 @@
+aspect A {
+  static before(): call(* *(..)) {}
+}
diff --git a/tests/bugs152/pr135068/Aaj.aj b/tests/bugs152/pr135068/Aaj.aj
new file mode 100644 (file)
index 0000000..48af01d
--- /dev/null
@@ -0,0 +1,8 @@
+import java.net.InetAddress;
+
+public aspect Aaj {
+
+       InetAddress around() throws java.net.UnknownHostException : call(public java.net.InetAddress C.getAddress() throws java.net.UnknownHostException) {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/Ajava.java b/tests/bugs152/pr135068/Ajava.java
new file mode 100644 (file)
index 0000000..c00aa79
--- /dev/null
@@ -0,0 +1,16 @@
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.*;
+
+@Aspect
+public class Ajava {
+
+       @Around("call(public java.net.InetAddress C.getAddress() throws java.net.UnknownHostException)")
+       public InetAddress getAddress() throws UnknownHostException {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/Ajava2.java b/tests/bugs152/pr135068/Ajava2.java
new file mode 100644 (file)
index 0000000..cfe0d05
--- /dev/null
@@ -0,0 +1,16 @@
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.*;
+
+@Aspect
+public class Ajava2 {
+
+       @Around("call(public java.net.InetAddress C2.getAddress() throws java.net.UnknownHostException)")
+       public static InetAddress getAddress() throws UnknownHostException {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/C.java b/tests/bugs152/pr135068/C.java
new file mode 100644 (file)
index 0000000..4e8c71d
--- /dev/null
@@ -0,0 +1,14 @@
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class C {
+
+       public static InetAddress getAddress() throws UnknownHostException {
+               return null;
+       }
+       
+       public static void main(String[] args) throws Exception {
+               System.out.println(getAddress().toString());
+       }
+}
diff --git a/tests/bugs152/pr135068/C2.java b/tests/bugs152/pr135068/C2.java
new file mode 100644 (file)
index 0000000..b363356
--- /dev/null
@@ -0,0 +1,14 @@
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class C2 {
+
+       public static InetAddress getAddress() throws UnknownHostException {
+               return null;
+       }
+       
+       public static void main(String[] args) throws Exception {
+               System.out.println(getAddress().toString());
+       }
+}
diff --git a/tests/bugs152/pr135068/aop.xml b/tests/bugs152/pr135068/aop.xml
new file mode 100644 (file)
index 0000000..eaef22b
--- /dev/null
@@ -0,0 +1,9 @@
+<aspectj>
+  <aspects>
+    <aspect name="t.Ajava"/>
+  </aspects>
+
+  <weaver>
+    <include within="t..*"/>
+  </weaver>
+</aspectj>
diff --git a/tests/bugs152/pr135068/t/Aaj.aj b/tests/bugs152/pr135068/t/Aaj.aj
new file mode 100644 (file)
index 0000000..8123292
--- /dev/null
@@ -0,0 +1,10 @@
+package t;
+
+import java.net.InetAddress;
+
+public aspect Aaj {
+
+       InetAddress around() throws java.net.UnknownHostException : call(public java.net.InetAddress t.C.getAddress() throws java.net.UnknownHostException) {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/t/Ajava.java b/tests/bugs152/pr135068/t/Ajava.java
new file mode 100644 (file)
index 0000000..fc51936
--- /dev/null
@@ -0,0 +1,16 @@
+package t;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class Ajava {
+
+       @Around("call(public java.net.InetAddress t.C.getAddress() throws java.net.UnknownHostException)")
+       public InetAddress getAddress() throws UnknownHostException {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/t/Ajava2.java b/tests/bugs152/pr135068/t/Ajava2.java
new file mode 100644 (file)
index 0000000..5bf933c
--- /dev/null
@@ -0,0 +1,16 @@
+package t;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class Ajava2 {
+
+       @Around("call(public java.net.InetAddress t.C2.getAddress() throws java.net.UnknownHostException)")
+       public static InetAddress getAddress() throws UnknownHostException {
+               return InetAddress.getLocalHost();
+       }
+}
diff --git a/tests/bugs152/pr135068/t/C.java b/tests/bugs152/pr135068/t/C.java
new file mode 100644 (file)
index 0000000..a36f333
--- /dev/null
@@ -0,0 +1,20 @@
+package t;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class C {
+
+       public InetAddress getAddress() throws UnknownHostException {
+               return null;
+       }
+       
+       private void test() throws UnknownHostException {
+               System.out.println(getAddress().toString());
+       }
+
+       public static void main(String[] args) throws Exception {
+               C c = new C();
+               c.test();
+       }
+}
diff --git a/tests/bugs152/pr135068/t/C2.java b/tests/bugs152/pr135068/t/C2.java
new file mode 100644 (file)
index 0000000..32cf001
--- /dev/null
@@ -0,0 +1,20 @@
+package t;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class C2 {
+
+       public InetAddress getAddress() throws UnknownHostException {
+               return null;
+       }
+       
+       private void test() throws UnknownHostException {
+               System.out.println(getAddress().toString());
+       }
+
+       public static void main(String[] args) throws Exception {
+               C2 c = new C2();
+               c.test();
+       }
+}
index 8344f1070d6bdd6a93962a5f555979ba3e8cd31d..67b599c879bddb27f41b4c34e2624a91cda22df6 100644 (file)
@@ -17,6 +17,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        
+  public void testVerifyErrorLTW_pr135068() { runTest("ltw verifyerror");}
+  public void testVerifyErrorLTW_pr135068_2() { runTest("ltw verifyerror - 2");}
+  public void testVerifyErrorLTW_pr135068_3() { runTest("ltw verifyerror - 3");}
+  public void testVerifyErrorLTW_pr135068_4() { runTest("ltw verifyerror - 4");}
   public void testVerifyErrorForComplexCflow_pr136026() { runTest("verifyerror");}
   public void testVerifyErrorForComplexCflow_pr136026_2() { runTest("verifyerror - 2");}
   public void testAnnotationsAndGenericsBCException_pr129704() { runTest("annotations and generics leading to BCException");}
index 08b008bdf3ad45a0bc3d120ffa8117f4863a4909..ee5ec2dedc6e7be6e7c1134ca97095327871ef93 100644 (file)
            <message kind="error" line="16" text="Stystems cannot be resolved"/>
          </compile>
        </ajc-test>
+       
+       <ajc-test dir="bugs152/pr135068" title="ltw verifyerror">
+           <compile files="C.java,Ajava.java" options="-1.5 -XnoInline"/>
+           <run class="C"/>
+    </ajc-test>
+    
+       <ajc-test dir="bugs152/pr135068" title="ltw verifyerror - 2">
+           <compile files="C2.java,Ajava2.java" options="-1.5 -XnoInline">
+             <message kind="error" line="13" text="advice can not be declared static"/>
+           </compile>
+    </ajc-test>
+    
+       <ajc-test dir="bugs152/pr135068" title="ltw verifyerror - 3">
+           <compile files="t/C.java" options="-1.5"/>
+        <compile files="t/Ajava.java" options="-1.5">
+          <message kind="warning" line="13" text="advice defined"/>
+        </compile>
+        <run class="t.C" ltw="aop.xml"/>
+    </ajc-test>
+    
+       <ajc-test dir="bugs152/pr135068" title="ltw verifyerror - 4">
+           <compile files="t/C2.java" options="-1.5"/>
+        <compile files="t/Ajava2.java" options="-1.5">
+             <message kind="error" line="13" text="advice can not be declared static"/>
+        </compile>
+    </ajc-test>
+    
 </suite>
\ No newline at end of file
index a32361ef3ee91c767cba048e979dcb6683c9378e..9715bcbe2fa7728202ecee22a4d58d78016eb435 100644 (file)
@@ -40,6 +40,7 @@ import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.weaver.Advice;
 import org.aspectj.weaver.AdviceKind;
 import org.aspectj.weaver.AjAttribute;
@@ -435,6 +436,20 @@ public class AtAjAttributes {
             );
             ;// go ahead
         }
+        
+        // semantic check - advice must not be static
+        if (hasAtAspectJAnnotation && struct.method.isStatic()) {
+            msgHandler.handleMessage(MessageUtil.error("Advice cannot be declared static '" + methodToString(struct.method) + "'",type.getSourceLocation()));
+//                    new Message(
+//                            "Advice cannot be declared static '" + methodToString(struct.method) + "'",
+//                            IMessage.ERROR,
+//                            null,
+//                            type.getSourceLocation()
+//                    )
+//            );
+            ;// go ahead
+        }
+        
         // semantic check for non around advice must return void
         if (hasAtAspectJAnnotationMustReturnVoid && !Type.VOID.equals(struct.method.getReturnType())) {
             msgHandler.handleMessage(