diff options
author | aclement <aclement> | 2006-05-16 07:38:53 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-05-16 07:38:53 +0000 |
commit | 9ffc63b51aa49fa3bb67a4a1c40dd7d1fe4c97ae (patch) | |
tree | 849734d4b11d088f3f5159c69034c727093397ce | |
parent | 5c2da6f738945e027241703ef91c49099d9851d8 (diff) | |
download | aspectj-9ffc63b51aa49fa3bb67a4a1c40dd7d1fe4c97ae.tar.gz aspectj-9ffc63b51aa49fa3bb67a4a1c40dd7d1fe4c97ae.zip |
tests and fix for 135068: verifyerror for @AJ
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java | 6 | ||||
-rw-r--r-- | tests/bugs152/pr135068/A.java | 3 | ||||
-rw-r--r-- | tests/bugs152/pr135068/Aaj.aj | 8 | ||||
-rw-r--r-- | tests/bugs152/pr135068/Ajava.java | 16 | ||||
-rw-r--r-- | tests/bugs152/pr135068/Ajava2.java | 16 | ||||
-rw-r--r-- | tests/bugs152/pr135068/C.java | 14 | ||||
-rw-r--r-- | tests/bugs152/pr135068/C2.java | 14 | ||||
-rw-r--r-- | tests/bugs152/pr135068/aop.xml | 9 | ||||
-rw-r--r-- | tests/bugs152/pr135068/t/Aaj.aj | 10 | ||||
-rw-r--r-- | tests/bugs152/pr135068/t/Ajava.java | 16 | ||||
-rw-r--r-- | tests/bugs152/pr135068/t/Ajava2.java | 16 | ||||
-rw-r--r-- | tests/bugs152/pr135068/t/C.java | 20 | ||||
-rw-r--r-- | tests/bugs152/pr135068/t/C2.java | 20 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java | 4 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc152/ajc152.xml | 27 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java | 15 |
16 files changed, 214 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java index a79ef0931..09d6b441e 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java @@ -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 index 000000000..adbab3f93 --- /dev/null +++ b/tests/bugs152/pr135068/A.java @@ -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 index 000000000..48af01dba --- /dev/null +++ b/tests/bugs152/pr135068/Aaj.aj @@ -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 index 000000000..c00aa7952 --- /dev/null +++ b/tests/bugs152/pr135068/Ajava.java @@ -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 index 000000000..cfe0d05b0 --- /dev/null +++ b/tests/bugs152/pr135068/Ajava2.java @@ -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 index 000000000..4e8c71d98 --- /dev/null +++ b/tests/bugs152/pr135068/C.java @@ -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 index 000000000..b363356b1 --- /dev/null +++ b/tests/bugs152/pr135068/C2.java @@ -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 index 000000000..eaef22b32 --- /dev/null +++ b/tests/bugs152/pr135068/aop.xml @@ -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 index 000000000..8123292fe --- /dev/null +++ b/tests/bugs152/pr135068/t/Aaj.aj @@ -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 index 000000000..fc519368b --- /dev/null +++ b/tests/bugs152/pr135068/t/Ajava.java @@ -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 index 000000000..5bf933c5d --- /dev/null +++ b/tests/bugs152/pr135068/t/Ajava2.java @@ -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 index 000000000..a36f333a8 --- /dev/null +++ b/tests/bugs152/pr135068/t/C.java @@ -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 index 000000000..32cf00136 --- /dev/null +++ b/tests/bugs152/pr135068/t/C2.java @@ -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(); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java index 8344f1070..67b599c87 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java @@ -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");} diff --git a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml index 08b008bdf..ee5ec2ded 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml +++ b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml @@ -272,4 +272,31 @@ <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 diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index a32361ef3..9715bcbe2 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -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( |