Prohibit body for annotation class
#KT-1886 Fixed
This commit is contained in:
@@ -360,7 +360,7 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory<JetExpression> DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = SimpleDiagnosticFactory.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<JetAnnotationEntry, String> NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
SimpleDiagnosticFactory<PsiElement> ANNOTATION_CLASS_WITH_BODY = SimpleDiagnosticFactory.create(ERROR);
|
||||
|
||||
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
|
||||
+1
@@ -414,6 +414,7 @@ public class DefaultErrorMessages {
|
||||
"Separate it with a semicolon (;) if it is not intended to be an argument.");
|
||||
|
||||
MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", TO_STRING);
|
||||
MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class");
|
||||
|
||||
MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters");
|
||||
|
||||
|
||||
@@ -139,6 +139,11 @@ public class DeclarationResolver {
|
||||
JetClass jetClass = entry.getKey();
|
||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||
|
||||
JetClassBody jetClassBody = jetClass.getBody();
|
||||
if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS && jetClassBody != null) {
|
||||
trace.report(ANNOTATION_CLASS_WITH_BODY.on(jetClassBody));
|
||||
}
|
||||
|
||||
resolveFunctionAndPropertyHeaders(
|
||||
jetClass.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
|
||||
classDescriptor.getScopeForInitializers(), classDescriptor.getScopeForMemberResolution(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
annotation class test {}
|
||||
annotation class test
|
||||
|
||||
fun foo(test <!UNUSED_PARAMETER!>f<!> : Int) {}
|
||||
|
||||
@@ -8,4 +8,4 @@ var bar : Int = 1
|
||||
val x : (Int) -> Int = {([test] x : Int) -> x}
|
||||
|
||||
class Hello(test args: Any) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
annotation class Annotation2() <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
public val s: String = ""
|
||||
}<!>
|
||||
|
||||
annotation class Annotation3() <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
public fun foo() {}
|
||||
}<!>
|
||||
|
||||
annotation class Annotation4() <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
class Foo() {}
|
||||
}<!>
|
||||
|
||||
annotation class Annotation5() <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
class object {}
|
||||
}<!>
|
||||
|
||||
annotation class Annotation6() <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
{}
|
||||
}<!>
|
||||
|
||||
annotation class Annotation1() <!ANNOTATION_CLASS_WITH_BODY!>{}<!>
|
||||
|
||||
annotation class Annotation7(val name: String) <!ANNOTATION_CLASS_WITH_BODY!>{}<!>
|
||||
|
||||
annotation class Annotation8(var name: String = "") <!ANNOTATION_CLASS_WITH_BODY!>{}<!>
|
||||
|
||||
annotation class Annotation9(name: String)
|
||||
|
||||
annotation class Annotation10
|
||||
@@ -1,7 +1,6 @@
|
||||
package rendererTest
|
||||
|
||||
annotation class TheAnnotation {
|
||||
}
|
||||
annotation class TheAnnotation
|
||||
|
||||
[TheAnnotation]
|
||||
public open class TheClass<out T : Int, X> {
|
||||
@@ -38,4 +37,4 @@ trait TheTrait {
|
||||
//internal trait TheTrait defined in rendererTest
|
||||
//internal abstract fun abstractFun() : Unit defined in rendererTest.TheTrait
|
||||
//class object : rendererTest.TheClass<jet.Int, jet.Int> defined in rendererTest.TheTrait
|
||||
//internal final fun classObjectFunction() : jet.Int defined in rendererTest.TheTrait.<class-object-for-TheTrait>
|
||||
//internal final fun classObjectFunction() : jet.Int defined in rendererTest.TheTrait.<class-object-for-TheTrait>
|
||||
|
||||
@@ -567,6 +567,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/kt1860-positive.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1886annotationBody.kt")
|
||||
public void testKt1886annotationBody() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NonAnnotationClass.kt")
|
||||
public void testNonAnnotationClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.kt");
|
||||
|
||||
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
annotation class A {
|
||||
fun foo() {
|
||||
"" // A
|
||||
}
|
||||
}
|
||||
@@ -61,10 +61,6 @@ public class JetPositionManagerTest extends PositionManagerTestCase {
|
||||
doMultiTest("multiFileNamespace/a.kt", "multiFileNamespace/b.kt");
|
||||
}
|
||||
|
||||
public void testAnnotation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnonymousFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testAnnotationClass() {
|
||||
doBuildTest("annotation class Test {}",
|
||||
doBuildTest("annotation class Test",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" CLASS:PsiJetClassStubImpl[isAnnotation name=Test fqn=Test superNames=[]]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package js;
|
||||
|
||||
native
|
||||
public annotation class native(name : String = "") {}
|
||||
public annotation class native(name : String = "")
|
||||
native
|
||||
public annotation class library(name : String = "") {}
|
||||
public annotation class library(name : String = "")
|
||||
native
|
||||
public annotation class enumerable() {}
|
||||
public annotation class enumerable()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package org.junit;
|
||||
|
||||
native
|
||||
public annotation class Test(name : String = "") {}
|
||||
public annotation class Test(name : String = "")
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import jet.runtime.ArrayIterator
|
||||
/**
|
||||
* Annotates a class used to implement extension functions
|
||||
*/
|
||||
annotation class extension() {
|
||||
}
|
||||
annotation class extension()
|
||||
|
||||
/**
|
||||
* Defines the extension functions on a List<T>
|
||||
|
||||
@@ -4,10 +4,10 @@ package js
|
||||
* This annotation marks code as being a native JavaScript expression
|
||||
*/
|
||||
native
|
||||
annotation class native(name : String = "") {}
|
||||
annotation class native(name : String = "")
|
||||
|
||||
/**
|
||||
* Represents a function in the standard library
|
||||
*/
|
||||
native
|
||||
annotation class library(name : String = "") {}
|
||||
annotation class library(name : String = "")
|
||||
|
||||
Reference in New Issue
Block a user