diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index ac35425c555..5e6104ec522 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -155,6 +155,7 @@ public interface Errors { DiagnosticFactory0 SUPERTYPES_FOR_ANNOTATION_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 MISSING_VAL_ON_ANNOTATION_PARAMETER = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 VAR_ANNOTATION_PARAMETER = DiagnosticFactory0.create(ERROR, VAL_OR_VAR_NODE); DiagnosticFactory0 ANNOTATION_CLASS_CONSTRUCTOR_CALL = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 ANNOTATION_CLASS_WITH_BODY = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 70c2cff57c0..a05b0413a43 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -679,6 +679,7 @@ public class DefaultErrorMessages { MAP.put(SUPERTYPES_FOR_ANNOTATION_CLASS, "Annotation class cannot have supertypes"); MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter"); + MAP.put(VAR_ANNOTATION_PARAMETER, "An annotation parameter cannot be 'var'"); MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated"); MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", NAME); MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index 0e8198d44e1..52dd26f0792 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -368,6 +368,9 @@ class DeclarationsChecker( if (!parameter.hasValOrVar()) { trace.report(MISSING_VAL_ON_ANNOTATION_PARAMETER.on(parameter)) } + else if (parameter.isMutable) { + trace.report(VAR_ANNOTATION_PARAMETER.on(parameter)) + } } } diff --git a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt index 7c0f524f365..ed2250bcc44 100644 --- a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt +++ b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt @@ -22,7 +22,7 @@ annotation class Annotation1() {} annotation class Annotation7(val name: String) {} -annotation class Annotation8(var name: String = "") {} +annotation class Annotation8(var name: String = "") {} annotation class Annotation9(val name: String) diff --git a/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.kt b/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.kt index 799a8989e9d..178fe4ab723 100644 --- a/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.kt +++ b/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.kt @@ -1,5 +1,5 @@ annotation class Ann( val a: Int, - var b: Int, + var b: Int, c: String ) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt index 0af30e5b777..79f27879f1c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt @@ -74,5 +74,12 @@ class ChangeVariableMutabilityFix(element: KtValVarKeywordOwner, private val mak } } } + + val VAR_ANNOTATION_PARAMETER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val element = diagnostic.psiElement as KtParameter + return ChangeVariableMutabilityFix(element, false) + } + } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index dc37432c329..216c42ae69f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -171,6 +171,7 @@ class QuickFixRegistrar : QuickFixContributor { VAL_REASSIGNMENT.registerFactory(ChangeVariableMutabilityFix.VAL_REASSIGNMENT_FACTORY) CAPTURED_VAL_INITIALIZATION.registerFactory(ChangeVariableMutabilityFix.CAPTURED_VAL_INITIALIZATION_FACTORY) VAR_OVERRIDDEN_BY_VAL.registerFactory(ChangeVariableMutabilityFix.VAR_OVERRIDDEN_BY_VAL_FACTORY) + VAR_ANNOTATION_PARAMETER.registerFactory(ChangeVariableMutabilityFix.VAR_ANNOTATION_PARAMETER_FACTORY) VAL_OR_VAR_ON_FUN_PARAMETER.registerFactory(RemoveValVarFromParameterFix) VAL_OR_VAR_ON_LOOP_PARAMETER.registerFactory(RemoveValVarFromParameterFix)