diff options
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java | 7 | ||||
-rw-r--r-- | tests/ajcTests.xml | 8 | ||||
-rw-r--r-- | tests/bugs/StaticInterfaceMethods.java | 10 |
3 files changed, 25 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java index 2039fd54c..404d74373 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java @@ -73,6 +73,13 @@ public class InterTypeMethodDeclaration extends InterTypeDeclaration { } public void resolveStatements() { if (!Modifier.isAbstract(declaredModifiers)) super.resolveStatements(); + if (Modifier.isStatic(declaredModifiers)) { + // Check the target for ITD is not an interface + if (onTypeBinding.isInterface()) { + scope.problemReporter().signalError(sourceStart, sourceEnd, + "methods in interfaces cannot be declared static"); + } + } } diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index 3b834af69..cdeece3b6 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -6835,4 +6835,12 @@ <message kind="error" line="6" text="Unhandled exception"/> </compile> </ajc-test> + + <ajc-test dir="bugs" pr="47754" + title="static method introduction on interfaces, should not be allowed"> + <compile files="StaticInterfaceMethods.java"> + <message kind="error" line="7" text="methods in interfaces cannot be declared static"/> + </compile> + </ajc-test> + </suite> diff --git a/tests/bugs/StaticInterfaceMethods.java b/tests/bugs/StaticInterfaceMethods.java new file mode 100644 index 000000000..fb08f0db4 --- /dev/null +++ b/tests/bugs/StaticInterfaceMethods.java @@ -0,0 +1,10 @@ +interface StaticInterfaceMethods { + +} + +aspect A { + + static int StaticInterfaceMethods.aMethod() { + return 1; + } +}
\ No newline at end of file |