Add warning when 'val' keyword on annotation parameter is missing
#KT-1900
This commit is contained in:
@@ -111,6 +111,7 @@ public interface Errors {
|
||||
|
||||
// Annotations
|
||||
|
||||
DiagnosticFactory0<JetParameter> MISSING_VAL_ON_ANNOTATION_PARAMETER = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<JetCallExpression> ANNOTATION_CLASS_CONSTRUCTOR_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<JetAnnotationEntry, String> NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ANNOTATION_CLASS_WITH_BODY = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+1
@@ -451,6 +451,7 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME);
|
||||
|
||||
MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter");
|
||||
MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated");
|
||||
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");
|
||||
|
||||
@@ -277,6 +277,8 @@ public class DeclarationResolver {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAnnotationClass = DescriptorUtils.isAnnotationClass(classDescriptor);
|
||||
|
||||
// TODO : not all the parameters are real properties
|
||||
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
|
||||
ConstructorDescriptor constructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass, trace);
|
||||
@@ -298,6 +300,9 @@ public class DeclarationResolver {
|
||||
context.getPrimaryConstructorParameterProperties().put(parameter, propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
if (isAnnotationClass) {
|
||||
trace.report(MISSING_VAL_ON_ANNOTATION_PARAMETER.on(parameter));
|
||||
}
|
||||
notProperties.add(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
annotation class my
|
||||
annotation class my1(i : Int)
|
||||
annotation class my2(i : Int = 0)
|
||||
annotation class my1(val i : Int)
|
||||
annotation class my2(val i : Int = 0)
|
||||
|
||||
my fun foo() {}
|
||||
<!NO_VALUE_FOR_PARAMETER!>my1<!> fun foo2() {}
|
||||
|
||||
@@ -24,6 +24,6 @@ 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 Annotation9(val name: String)
|
||||
|
||||
annotation class Annotation10
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
annotation class Ann(
|
||||
val a: Int,
|
||||
var b: Int,
|
||||
<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>c: String<!>
|
||||
)
|
||||
@@ -610,6 +610,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("missingValOnParameter.kt")
|
||||
public void testMissingValOnParameter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/missingValOnParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NonAnnotationClass.kt")
|
||||
public void testNonAnnotationClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user