diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt index 1dff374503b..7086332df8a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt @@ -28,11 +28,10 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.util.OperatorNameConventions -class OperatorToFunctionIntention : - SelfTargetingIntention( - KtExpression::class.java, - KotlinIdeaAnalysisBundle.message("replace.overloaded.operator.with.function.call") - ) { +class OperatorToFunctionIntention : SelfTargetingIntention( + KtExpression::class.java, + KotlinIdeaAnalysisBundle.lazyMessage("replace.overloaded.operator.with.function.call"), +) { companion object { private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean { if (element.baseExpression == null) return false @@ -65,7 +64,8 @@ class OperatorToFunctionIntention : return when (opRef.getReferencedNameElementType()) { KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE, KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ, - KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ -> true + KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ + -> true KtTokens.EQEQ, KtTokens.EXCLEQ -> listOf(element.left, element.right).none { it?.node?.elementType == KtNodeTypes.NULL } KtTokens.EQ -> element.left is KtArrayAccessExpression else -> false diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt index abfddfec2ca..c7b8dc44c20 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt @@ -30,7 +30,7 @@ abstract class SelfTargetingIntention( @Nls private val familyNameGetter: () -> String = textGetter, ) : IntentionAction { - @Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingIntention(elementType, { text }, { familyName })")) + @Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingIntention(elementType, { text }, { familyName })")) constructor( elementType: Class, @Nls text: String, @@ -130,7 +130,7 @@ abstract class SelfTargetingRangeIntention( @Nls familyNameGetter: () -> String = textGetter, ) : SelfTargetingIntention(elementType, textGetter, familyNameGetter) { - @Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingRangeIntention(elementType, { text }, { familyName })")) + @Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingRangeIntention(elementType, { text }, { familyName })")) constructor( elementType: Class, @Nls text: String, @@ -153,7 +153,7 @@ abstract class SelfTargetingOffsetIndependentIntention( @Deprecated( "Replace with primary constructor", - ReplaceWith("SelfTargetingOffsetIndependentIntention(elementType, { text }, { familyName })") + ReplaceWith("SelfTargetingOffsetIndependentIntention(elementType, { text }, { familyName })") ) constructor( elementType: Class, diff --git a/idea/resources/messages/KotlinBundle.properties b/idea/resources/messages/KotlinBundle.properties index ae50f1ca041..2e0f01ce494 100644 --- a/idea/resources/messages/KotlinBundle.properties +++ b/idea/resources/messages/KotlinBundle.properties @@ -2181,4 +2181,7 @@ inspection.trailing.comma.add.trailing.comma=Add trailing comma inspection.trailing.comma.missing.trailing.comma=Missing trailing comma inspection.trailing.comma.fix.comma.position=Fix comma position inspection.trailing.comma.comma.loses.the.advantages.in.this.position=Comma loses the advantages in this position -inspection.redundant.label.text=Redundant label \ No newline at end of file +inspection.redundant.label.text=Redundant label +intention.convert.lambda.line=Convert to {0,choice,0#single|1#multi}-line lambda +intention.trailing.comma.custom.text={0,choice,0#Enable|1#Disable} a trailing comma by default in the formatter +intention.trailing.comma.text=Enable/disable a trailing comma in the formatter \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAccessorIntentions.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAccessorIntentions.kt index f96db401699..b1dbd271833 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAccessorIntentions.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAccessorIntentions.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -103,10 +92,10 @@ abstract class AbstractAddAccessorsIntention( } } -private fun createFamilyName(addGetter: Boolean, addSetter: Boolean): String = when { - addGetter && addSetter -> KotlinBundle.message("text.add.getter.and.setter") - addGetter -> KotlinBundle.message("text.add.getter") - addSetter -> KotlinBundle.message("text.add.setter") +private fun createFamilyName(addGetter: Boolean, addSetter: Boolean): () -> String = when { + addGetter && addSetter -> KotlinBundle.lazyMessage("text.add.getter.and.setter") + addGetter -> KotlinBundle.lazyMessage("text.add.getter") + addSetter -> KotlinBundle.lazyMessage("text.add.setter") else -> throw AssertionError("At least one from (addGetter, addSetter) should be true") } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt index d2171bfe12d..46ae9b7c652 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -26,14 +26,15 @@ import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType class AddAnnotationUseSiteTargetIntention : SelfTargetingIntention( - KtAnnotationEntry::class.java, KotlinBundle.message("add.use.site.target") + KtAnnotationEntry::class.java, + KotlinBundle.lazyMessage("add.use.site.target") ) { override fun isApplicableTo(element: KtAnnotationEntry, caretOffset: Int): Boolean { val useSiteTargets = element.applicableUseSiteTargets() if (useSiteTargets.isEmpty()) return false if (useSiteTargets.size == 1) { - text = KotlinBundle.message("text.add.use.site.target.0", useSiteTargets.first().renderName) + setTextGetter(KotlinBundle.lazyMessage("text.add.use.site.target.0", useSiteTargets.first().renderName)) } return true } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index 212ca09c5ce..17ff0bdb6a0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -28,7 +17,7 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* -class AddBracesIntention : SelfTargetingIntention(KtElement::class.java, KotlinBundle.message("add.braces")) { +class AddBracesIntention : SelfTargetingIntention(KtElement::class.java, KotlinBundle.lazyMessage("add.braces")) { override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean { val expression = element.getTargetExpression(caretOffset) ?: return false if (expression is KtBlockExpression) return false @@ -36,11 +25,11 @@ class AddBracesIntention : SelfTargetingIntention(KtElement::class.ja return when (val parent = expression.parent) { is KtContainerNode -> { val description = parent.description() ?: return false - text = KotlinBundle.message("add.braces.to.0.statement", description) + setTextGetter(KotlinBundle.lazyMessage("add.braces.to.0.statement", description)) true } is KtWhenEntry -> { - text = KotlinBundle.message("add.braces.to.when.entry") + setTextGetter(KotlinBundle.lazyMessage("add.braces.to.when.entry")) true } else -> { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt index 4d29ff7b786..21df55acec1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -34,9 +23,8 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class AddForLoopIndicesIntention : SelfTargetingRangeIntention( KtForExpression::class.java, - KotlinBundle.message("add.indices.to.for.loop") -), - LowPriorityAction { + KotlinBundle.lazyMessage("add.indices.to.for.loop"), +), LowPriorityAction { private val WITH_INDEX_NAME = "withIndex" private val WITH_INDEX_FQ_NAMES: Set by lazy { sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet() @@ -88,8 +76,7 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention( val templateBuilder = TemplateBuilderImpl(forExpression) templateBuilder.replaceElement(indexVariable, ChooseStringExpression(listOf("index", "i"))) - val body = forExpression.body - when (body) { + when (val body = forExpression.body) { is KtBlockExpression -> { val statement = body.statements.firstOrNull() if (statement != null) { @@ -107,10 +94,9 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention( templateBuilder.run(editor, true) } - private fun createWithIndexExpression(originalExpression: KtExpression, reformat: Boolean): KtExpression { - return KtPsiFactory(originalExpression).createExpressionByPattern( + private fun createWithIndexExpression(originalExpression: KtExpression, reformat: Boolean): KtExpression = + KtPsiFactory(originalExpression).createExpressionByPattern( "$0.$WITH_INDEX_NAME()", originalExpression, reformat = reformat ) - } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmOverloadsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmOverloadsIntention.kt index 80bb8a4ccda..6150eadea55 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmOverloadsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmOverloadsIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs private val annotationFqName = FqName("kotlin.jvm.JvmOverloads") class AddJvmOverloadsIntention : SelfTargetingIntention( - KtModifierListOwner::class.java, KotlinBundle.message("add.jvmoverloads.annotation") + KtModifierListOwner::class.java, + KotlinBundle.lazyMessage("add.jvmoverloads.annotation"), ), LowPriorityAction { - override fun isApplicableTo(element: KtModifierListOwner, caretOffset: Int): Boolean { val (targetName, parameters) = when (element) { is KtNamedFunction -> { @@ -59,7 +59,7 @@ class AddJvmOverloadsIntention : SelfTargetingIntention( else -> return false } - text = KotlinBundle.message("add.jvmoverloads.annotation.to.0", targetName) + setTextGetter(KotlinBundle.lazyMessage("add.jvmoverloads.annotation.to.0", targetName)) return TargetPlatformDetector.getPlatform(element.containingKtFile).isJvm() && parameters.any { it.hasDefaultValue() } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmStaticIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmStaticIntention.kt index f8825802b92..4f0099334ee 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmStaticIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddJvmStaticIntention.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject class AddJvmStaticIntention : SelfTargetingRangeIntention( KtNamedDeclaration::class.java, - KotlinBundle.message("add.jvmstatic.annotation") + KotlinBundle.lazyMessage("add.jvmstatic.annotation") ), LowPriorityAction { private val JvmStaticFqName = FqName("kotlin.jvm.JvmStatic") private val JvmFieldFqName = FqName("kotlin.jvm.JvmField") diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddLabeledReturnInLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddLabeledReturnInLambdaIntention.kt index ab9a18fed10..4fa1adf4039 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddLabeledReturnInLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddLabeledReturnInLambdaIntention.kt @@ -19,8 +19,8 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention( KtBlockExpression::class.java, - KotlinBundle.message("add.labeled.return.to.last.expression.in.a.lambda") -), LowPriorityAction { + { KotlinBundle.message("add.labeled.return.to.last.expression.in.a.lambda") }, + { text }), LowPriorityAction { override fun applicabilityRange(element: KtBlockExpression): TextRange? { if (!isApplicableTo(element)) return null val labelName = element.getParentLambdaLabelName() ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt index 3ec14c3c9c8..78269aaf57b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,11 +16,10 @@ import org.jetbrains.kotlin.psi.KtDestructuringDeclaration import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createDestructuringDeclarationByPattern -class AddMissingDestructuringIntention : - SelfTargetingIntention( - KtDestructuringDeclaration::class.java, - KotlinBundle.message("add.missing.component") - ) { +class AddMissingDestructuringIntention : SelfTargetingIntention( + KtDestructuringDeclaration::class.java, + KotlinBundle.lazyMessage("add.missing.component") +) { override fun isApplicableTo(element: KtDestructuringDeclaration, caretOffset: Int): Boolean { val entriesCount = element.entries.size @@ -41,16 +40,18 @@ class AddMissingDestructuringIntention : ) val entriesSize = entries.size - val newEntries = entries.joinToString(postfix = if (entriesSize == 0) "" else ", ") { it.text } + - primaryParameters.asSequence().drop(entriesSize).joinToString { - KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator) - } - val initializer = element.initializer ?: return + val newEntries = entries.joinToString(postfix = if (entriesSize == 0) "" else ", ") { + it.text + } + primaryParameters.asSequence().drop(entriesSize).joinToString { + KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator) + } + val initializer = element.initializer ?: return val newDestructuringDeclaration = factory.createDestructuringDeclarationByPattern( if (element.isVar) "var ($0) = $1" else "val ($0) = $1", newEntries, initializer ) + element.replace(newDestructuringDeclaration) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt index 505e7413472..aac71865519 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -38,9 +27,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument class AddNameToArgumentIntention : SelfTargetingIntention( - KtValueArgument::class.java, KotlinBundle.message("add.name.to.argument") + KtValueArgument::class.java, KotlinBundle.lazyMessage("add.name.to.argument") ), LowPriorityAction { - override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean { val expression = element.getArgumentExpression() ?: return false val name = detectNameToAdd( @@ -48,7 +36,7 @@ class AddNameToArgumentIntention : SelfTargetingIntention( shouldBeLastUnnamed = !element.languageVersionSettings.supportsFeature(LanguageFeature.MixedNamedArgumentsInTheirOwnPosition) ) ?: return false - text = KotlinBundle.message("add.0.to.argument", name) + setTextGetter(KotlinBundle.lazyMessage("add.0.to.argument", name)) if (expression is KtLambdaExpression) { val range = expression.textRange @@ -58,8 +46,9 @@ class AddNameToArgumentIntention : SelfTargetingIntention( return true } - override fun allowCaretInsideElement(element: PsiElement) = - element !is KtValueArgumentList && element !is KtContainerNode && super.allowCaretInsideElement(element) + override fun allowCaretInsideElement(element: PsiElement) = element !is KtValueArgumentList && + element !is KtContainerNode && + super.allowCaretInsideElement(element) override fun applyTo(element: KtValueArgument, editor: Editor?) { apply(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNamesToFollowingArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNamesToFollowingArgumentsIntention.kt index 5640435d6cd..333c09d5cff 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNamesToFollowingArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNamesToFollowingArgumentsIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.psi.KtValueArgument import org.jetbrains.kotlin.psi.KtValueArgumentList class AddNamesToFollowingArgumentsIntention : SelfTargetingIntention( - KtValueArgument::class.java, KotlinBundle.message("add.names.to.this.argument.and.following.arguments") + KtValueArgument::class.java, KotlinBundle.lazyMessage("add.names.to.this.argument.and.following.arguments") ), LowPriorityAction { override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean { val argumentList = element.parent as? KtValueArgumentList ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOpenModifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOpenModifierIntention.kt index 347bcedd62f..95d4b24854d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOpenModifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOpenModifierIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,19 +16,16 @@ import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject class AddOpenModifierIntention : SelfTargetingIntention( - KtCallableDeclaration::class.java, KotlinBundle.message("make.open") + KtCallableDeclaration::class.java, KotlinBundle.lazyMessage("make.open") ), LowPriorityAction { - override fun isApplicableTo(element: KtCallableDeclaration, caretOffset: Int): Boolean { - if (element !is KtProperty && element !is KtNamedFunction) { - return false - } + if (element !is KtProperty && element !is KtNamedFunction) return false + if (element.hasModifier(KtTokens.OPEN_KEYWORD) || element.hasModifier(KtTokens.ABSTRACT_KEYWORD) || element.hasModifier(KtTokens.PRIVATE_KEYWORD) - ) { - return false - } + ) return false + val implicitModality = element.implicitModality() if (implicitModality == KtTokens.OPEN_KEYWORD || implicitModality == KtTokens.ABSTRACT_KEYWORD) return false val ktClassOrObject = element.containingClassOrObject ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddThrowsAnnotationIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddThrowsAnnotationIntention.kt index ffc79478c54..1155dc03d65 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddThrowsAnnotationIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddThrowsAnnotationIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -27,9 +27,8 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.getAbbreviatedType class AddThrowsAnnotationIntention : SelfTargetingIntention( - KtThrowExpression::class.java, KotlinBundle.message("add.throws.annotation") + KtThrowExpression::class.java, KotlinBundle.lazyMessage("add.throws.annotation") ) { - override fun isApplicableTo(element: KtThrowExpression, caretOffset: Int): Boolean { if (!element.platform.isJvm()) return false val containingDeclaration = element.getContainingDeclaration() ?: return false @@ -115,19 +114,16 @@ private fun KtDeclaration.findThrowsAnnotation(context: BindingContext): KtAnnot } } -private fun ValueArgument.hasType(type: KotlinType, context: BindingContext): Boolean { - val argumentExpression = getArgumentExpression() - val expressions = when (argumentExpression) { +private fun ValueArgument.hasType(type: KotlinType, context: BindingContext): Boolean = + when (val argumentExpression = getArgumentExpression()) { is KtClassLiteralExpression -> listOf(argumentExpression) is KtCollectionLiteralExpression -> argumentExpression.getInnerExpressions().filterIsInstance(KtClassLiteralExpression::class.java) is KtCallExpression -> argumentExpression.valueArguments.mapNotNull { it.getArgumentExpression() as? KtClassLiteralExpression } else -> emptyList() - } - return expressions.any { it.getType(context)?.arguments?.firstOrNull()?.type == type } -} + }.any { it.getType(context)?.arguments?.firstOrNull()?.type == type } -private fun KtPsiFactory.createCollectionLiteral(expressions: List, lastExpression: String): KtCollectionLiteralExpression { - return buildExpression { +private fun KtPsiFactory.createCollectionLiteral(expressions: List, lastExpression: String): KtCollectionLiteralExpression = + buildExpression { appendFixedText("[") expressions.forEach { appendExpression(it) @@ -135,5 +131,4 @@ private fun KtPsiFactory.createCollectionLiteral(expressions: List } appendFixedText(lastExpression) appendFixedText("]") - } as KtCollectionLiteralExpression -} \ No newline at end of file + } as KtCollectionLiteralExpression \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddWhenRemainingBranchesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddWhenRemainingBranchesIntention.kt index 4544e957faa..65440e42b77 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddWhenRemainingBranchesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddWhenRemainingBranchesIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.idea.quickfix.AddWhenRemainingBranchesFix import org.jetbrains.kotlin.psi.KtWhenExpression class AddWhenRemainingBranchesIntention : SelfTargetingIntention( - KtWhenExpression::class.java, KotlinBundle.message("add.remaining.branches") + KtWhenExpression::class.java, KotlinBundle.lazyMessage("add.remaining.branches") ) { override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean { if (element.entries.none { it.isElse }) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertArrayParameterToVarargIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertArrayParameterToVarargIntention.kt index 0ea2913650a..3bd351a1028 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertArrayParameterToVarargIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertArrayParameterToVarargIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType class ConvertArrayParameterToVarargIntention : SelfTargetingIntention( KtParameter::class.java, DEFAULT_TEXT ) { - override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean { val typeReference = element.getChildOfType() ?: return false if (element.parent.parent is KtFunctionLiteral) return false @@ -26,20 +25,22 @@ class ConvertArrayParameterToVarargIntention : SelfTargetingIntention { - text = DEFAULT_TEXT + setTextGetter(DEFAULT_TEXT) true } KotlinBuiltIns.isArray(type) -> { val typeArgument = typeReference.typeElement?.typeArgumentsAsTypes?.firstOrNull() val typeProjection = typeArgument?.parent as? KtTypeProjection if (typeProjection?.hasModifier(KtTokens.IN_KEYWORD) == false) { - text = if (!typeProjection.hasModifier(KtTokens.OUT_KEYWORD) - && !KotlinBuiltIns.isPrimitiveType(element.builtIns.getArrayElementType(type)) - ) { - BREAKING_TEXT - } else { - DEFAULT_TEXT - } + setTextGetter( + if (!typeProjection.hasModifier(KtTokens.OUT_KEYWORD) + && !KotlinBuiltIns.isPrimitiveType(element.builtIns.getArrayElementType(type)) + ) { + BREAKING_TEXT + } else { + DEFAULT_TEXT + } + ) true } else { false @@ -61,9 +62,9 @@ class ConvertArrayParameterToVarargIntention : SelfTargetingIntention String get() = KotlinBundle.lazyMessage("convert.to.vararg.parameter") - private val BREAKING_TEXT: String get() = KotlinBundle.message("0.may.break.code", DEFAULT_TEXT) + private val BREAKING_TEXT: () -> String get() = KotlinBundle.lazyMessage("0.may.break.code", DEFAULT_TEXT) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBlockCommentToLineCommentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBlockCommentToLineCommentIntention.kt index ca08217fb52..4226d4089b6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBlockCommentToLineCommentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBlockCommentToLineCommentIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -14,11 +14,9 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtPsiFactory class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention( - PsiComment::class.java, KotlinBundle.message("replace.with.end.of.line.comment") + PsiComment::class.java, KotlinBundle.lazyMessage("replace.with.end.of.line.comment") ) { - override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean { - return element.isBlockComment() - } + override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean = element.isBlockComment() override fun applyTo(element: PsiComment, editor: Editor?) { val psiFactory = KtPsiFactory(element) @@ -36,6 +34,7 @@ class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCollectionConstructorToFunction.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCollectionConstructorToFunction.kt index 1235f4288f2..86fc34a2ab0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCollectionConstructorToFunction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCollectionConstructorToFunction.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe class ConvertCollectionConstructorToFunction : SelfTargetingIntention( - KtCallExpression::class.java, KotlinBundle.message("convert.collection.constructor.to.function") + KtCallExpression::class.java, KotlinBundle.lazyMessage("convert.collection.constructor.to.function") ) { private val functionMap = hashMapOf( diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index 953d220c92d..2f1c410da38 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -58,7 +47,7 @@ import org.jetbrains.kotlin.types.typeUtil.supertypes import java.util.* class ConvertFunctionToPropertyIntention : - SelfTargetingIntention(KtNamedFunction::class.java, KotlinBundle.message("convert.function.to.property")), + SelfTargetingIntention(KtNamedFunction::class.java, KotlinBundle.lazyMessage("convert.function.to.property")), LowPriorityAction { private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD")) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaLineIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaLineIntention.kt index ecb1a024a98..4eddee613e5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaLineIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaLineIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiComment +import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.inspections.RedundantSemicolonInspection import org.jetbrains.kotlin.idea.refactoring.getLineNumber import org.jetbrains.kotlin.lexer.KtTokens @@ -17,7 +18,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace sealed class ConvertLambdaLineIntention(private val toMultiLine: Boolean) : SelfTargetingIntention( - KtLambdaExpression::class.java, "Convert to ${if (toMultiLine) "multi" else "single"}-line lambda" + KtLambdaExpression::class.java, + KotlinBundle.lazyMessage("intention.convert.lambda.line", 1.takeIf { toMultiLine } ?: 0), ) { override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean { val functionLiteral = element.functionLiteral diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLateinitPropertyToNullableIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLateinitPropertyToNullableIntention.kt index 72b772fff4f..cdf16eb6f6b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLateinitPropertyToNullableIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLateinitPropertyToNullableIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -19,14 +19,12 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.typeUtil.makeNullable class ConvertLateinitPropertyToNullableIntention : SelfTargetingIntention( - KtProperty::class.java, KotlinBundle.message("convert.to.nullable.var") + KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.nullable.var") ) { - override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { - return element.hasModifier(KtTokens.LATEINIT_KEYWORD) - && element.isVar - && element.typeReference?.typeElement !is KtNullableType - && element.initializer == null - } + override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = element.hasModifier(KtTokens.LATEINIT_KEYWORD) + && element.isVar + && element.typeReference?.typeElement !is KtNullableType + && element.initializer == null override fun applyTo(element: KtProperty, editor: Editor?) { val typeReference: KtTypeReference = element.typeReference ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLazyPropertyToOrdinaryIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLazyPropertyToOrdinaryIntention.kt index 59e62788833..27ed9367d35 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLazyPropertyToOrdinaryIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLazyPropertyToOrdinaryIntention.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.allChildren class ConvertLazyPropertyToOrdinaryIntention : SelfTargetingIntention( - KtProperty::class.java, KotlinBundle.message("convert.to.ordinary.property") + KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.ordinary.property") ) { override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { val delegateExpression = element.delegate?.expression as? KtCallExpression ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLineCommentToBlockCommentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLineCommentToBlockCommentIntention.kt index 59e18b6fbf4..717964b706c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLineCommentToBlockCommentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLineCommentToBlockCommentIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,12 +16,11 @@ import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace class ConvertLineCommentToBlockCommentIntention : SelfTargetingIntention( - PsiComment::class.java, KotlinBundle.message("replace.with.block.comment") + PsiComment::class.java, + KotlinBundle.lazyMessage("replace.with.block.comment") ) { - override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean { - return element.isEndOfLineComment() - } + override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean = element.isEndOfLineComment() override fun applyTo(element: PsiComment, editor: Editor?) { val project = element.project @@ -59,11 +58,7 @@ private fun PsiElement.isEndOfLineComment() = node.elementType == KtTokens.EOL_C private fun PsiComment.commentText() = text.substring(2).replace("/*", "/ *").replace("*/", "* /").trim() -private fun PsiComment.nextComment(): PsiComment? { - return (getNextSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() } -} +private fun PsiComment.nextComment(): PsiComment? = (getNextSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() } -private fun PsiComment.prevComment(): PsiComment? { - return (getPrevSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() } -} +private fun PsiComment.prevComment(): PsiComment? = (getPrevSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt index 62c35fc2b07..5501d53809b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNullablePropertyToLateinitIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.makeNotNullable class ConvertNullablePropertyToLateinitIntention : SelfTargetingIntention( - KtProperty::class.java, KotlinBundle.message("convert.to.lateinit.var") + KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.lateinit.var") ) { override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { if (element.hasModifier(KtTokens.LATEINIT_KEYWORD) || element.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertOrdinaryPropertyToLazyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertOrdinaryPropertyToLazyIntention.kt index afeb270c378..00f6d67d201 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertOrdinaryPropertyToLazyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertOrdinaryPropertyToLazyIntention.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -15,11 +15,10 @@ import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern class ConvertOrdinaryPropertyToLazyIntention : SelfTargetingIntention( - KtProperty::class.java, KotlinBundle.message("convert.to.lazy.property") + KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.lazy.property") ) { - override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { - return !element.isVar && element.initializer != null && element.getter == null && !element.isLocal - } + override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = + !element.isVar && element.initializer != null && element.getter == null && !element.isLocal override fun applyTo(element: KtProperty, editor: Editor?) { val initializer = element.initializer ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt index 53b92cc48fb..2da395cbb70 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -31,7 +20,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType class ConvertParameterToReceiverIntention : SelfTargetingIntention( KtParameter::class.java, - KotlinBundle.message("convert.parameter.to.receiver") + KotlinBundle.lazyMessage("convert.parameter.to.receiver") ) { override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean { val identifier = element.nameIdentifier ?: return false @@ -41,15 +30,14 @@ class ConvertParameterToReceiverIntention : SelfTargetingIntention( return function.valueParameterList == element.parent && function.receiverTypeReference == null } - private fun configureChangeSignature(parameterIndex: Int): KotlinChangeSignatureConfiguration { - return object : KotlinChangeSignatureConfiguration { + private fun configureChangeSignature(parameterIndex: Int): KotlinChangeSignatureConfiguration = + object : KotlinChangeSignatureConfiguration { override fun configure(originalDescriptor: KotlinMethodDescriptor): KotlinMethodDescriptor { return originalDescriptor.modify { it.receiver = originalDescriptor.parameters[parameterIndex] } } override fun performSilently(affectedFunctions: Collection) = true } - } override fun startInWriteAction() = false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPrimaryConstructorToSecondaryIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPrimaryConstructorToSecondaryIntention.kt index 0856f2c9176..280efc07315 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPrimaryConstructorToSecondaryIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPrimaryConstructorToSecondaryIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parents class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention( KtPrimaryConstructor::class.java, - KotlinBundle.message("convert.to.secondary.constructor") + KotlinBundle.lazyMessage("convert.to.secondary.constructor") ) { override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean { val containingClass = element.containingClassOrObject as? KtClass ?: return false @@ -38,15 +38,15 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention + false is ValueParameterDescriptor -> (referencedDescriptor.containingDeclaration as? ConstructorDescriptor)?.containingDeclaration != classDescriptor else -> classDescriptor !in referencedDescriptor.parents } - } private fun KtProperty.isIndependent(klass: KtClass, context: BindingContext): Boolean { val propertyInitializer = initializer ?: return true diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyGetterToInitializerIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyGetterToInitializerIntention.kt index 23787a07186..cea5ea8b7e7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyGetterToInitializerIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyGetterToInitializerIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClass import org.jetbrains.kotlin.psi.psiUtil.endOffset class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention( - KtPropertyAccessor::class.java, KotlinBundle.message("convert.property.getter.to.initializer") + KtPropertyAccessor::class.java, KotlinBundle.lazyMessage("convert.property.getter.to.initializer") ) { override fun isApplicableTo(element: KtPropertyAccessor, caretOffset: Int): Boolean { @@ -41,10 +41,7 @@ class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention (bodyExpression.statements.singleOrNull() as? KtReturnExpression)?.returnedExpression + else -> bodyExpression } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt index 3a244165ee7..b0a2ef4db38 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -50,9 +39,8 @@ import java.util.* class ConvertPropertyToFunctionIntention : SelfTargetingIntention( KtProperty::class.java, - KotlinBundle.message("convert.property.to.function") -), - LowPriorityAction { + KotlinBundle.lazyMessage("convert.property.to.function") +), LowPriorityAction { private inner class Converter( project: Project, descriptor: CallableDescriptor diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt index 3d6d5f37a5c..40f899af88f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -33,7 +22,8 @@ import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.kotlin.types.typeUtil.isUnit class ConvertToBlockBodyIntention : SelfTargetingIntention( - KtDeclarationWithBody::class.java, KotlinBundle.message("convert.to.block.body") + KtDeclarationWithBody::class.java, + KotlinBundle.lazyMessage("convert.to.block.body") ) { override fun isApplicableTo(element: KtDeclarationWithBody, caretOffset: Int): Boolean { if (element is KtFunctionLiteral || element.hasBlockBody() || !element.hasBody()) return false @@ -58,7 +48,6 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention( KtForExpression::class.java, - KotlinBundle.message("replace.with.a.foreach.function.call") + KotlinBundle.lazyMessage("replace.with.a.foreach.function.call") ) { override fun isApplicableTo(element: KtForExpression, caretOffset: Int): Boolean { val rParen = element.rightParenthesis ?: return false @@ -42,18 +31,19 @@ class ConvertToForEachFunctionCallIntention : SelfTargetingIntention\n$2}", element.loopRange!!, loopParameter, functionBodyArgument + "$0.forEach{$1->\n$2}", loopRange, loopParameter, functionBodyArgument ) - val result = element.replace(foreachExpression) as KtElement - result.findDescendantOfType()!!.getContinuesWithLabel(labelName).forEach { + val result = element.replace(foreachExpression) as KtElement + result.findDescendantOfType()?.getContinuesWithLabel(labelName)?.forEach { it.replace(psiFactory.createExpression("return@forEach")) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt index a8756d734ba..116a8ca9546 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToScopeIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -25,10 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.siblings -sealed class ConvertToScopeIntention( - private val scopeFunction: ScopeFunction -) : SelfTargetingIntention(KtExpression::class.java, KotlinBundle.message("convert.to.0", scopeFunction.functionName)) { - +sealed class ConvertToScopeIntention(private val scopeFunction: ScopeFunction) : SelfTargetingIntention( + KtExpression::class.java, + KotlinBundle.lazyMessage("convert.to.0", scopeFunction.functionName) +) { enum class ScopeFunction(val functionName: String, val isParameterScope: Boolean) { ALSO(functionName = "also", isParameterScope = true), APPLY(functionName = "apply", isParameterScope = false), @@ -87,8 +87,10 @@ sealed class ConvertToScopeIntention( val psiFactory = KtPsiFactory(expressionToApply) - val (scopeFunctionCall, block) = - createScopeFunctionCall(psiFactory, refactoringTarget.targetElement) ?: return false + val (scopeFunctionCall, block) = createScopeFunctionCall( + psiFactory, + refactoringTarget.targetElement + ) ?: return false replaceReference(referenceElement, refactoringTarget.targetElementValue, lastTarget, psiFactory) @@ -110,6 +112,7 @@ sealed class ConvertToScopeIntention( val thisDotSomethingExpressions = block.collectDescendantsOfType { it.receiverExpression is KtThisExpression && it.selectorExpression !== null } + thisDotSomethingExpressions.forEach { thisDotSomethingExpression -> thisDotSomethingExpression.selectorExpression?.let { selector -> thisDotSomethingExpression.replace(selector) @@ -211,11 +214,10 @@ sealed class ConvertToScopeIntention( } } - private fun KtExpression.collectTargetElements(referenceName: String, forward: Boolean): Sequence { - return siblings(forward, withItself = false) + private fun KtExpression.collectTargetElements(referenceName: String, forward: Boolean): Sequence = + siblings(forward, withItself = false) .filter { it !is PsiWhiteSpace && it !is PsiComment && !(it is LeafPsiElement && it.elementType == KtTokens.SEMICOLON) } .takeWhile { it.isTarget(referenceName) } - } private fun PsiElement.isTarget(referenceName: String): Boolean { when (this) { @@ -246,18 +248,15 @@ sealed class ConvertToScopeIntention( } else -> return false } + return !anyDescendantOfType { it.text == scopeFunction.receiver } } - private fun KtExpression.prevProperty(): KtProperty? { - val blockChildExpression = PsiTreeUtil.findFirstParent(this) { - it.parent is KtBlockExpression - } ?: return null - - return blockChildExpression - .siblings(forward = false, withItself = true) - .firstOrNull { it is KtProperty && it.isLocal } as? KtProperty + private fun KtExpression.prevProperty(): KtProperty? = PsiTreeUtil.findFirstParent(this) { + it.parent is KtBlockExpression } + ?.siblings(forward = false, withItself = true) + ?.firstOrNull { it is KtProperty && it.isLocal } as? KtProperty private fun createScopeFunctionCall(factory: KtPsiFactory, element: PsiElement): ScopedFunctionCallAndBlock? { val scopeFunctionName = scopeFunction.functionName diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertUnsafeCastCallToUnsafeCastIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertUnsafeCastCallToUnsafeCastIntention.kt index 010dd3cd360..3d6c94b0cb8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertUnsafeCastCallToUnsafeCastIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertUnsafeCastCallToUnsafeCastIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -17,7 +17,8 @@ import org.jetbrains.kotlin.psi.createExpressionByPattern import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention( - KtDotQualifiedExpression::class.java, KotlinBundle.message("convert.to.unsafe.cast") + KtDotQualifiedExpression::class.java, + KotlinBundle.lazyMessage("convert.to.unsafe.cast"), ) { override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean { @@ -29,7 +30,7 @@ class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention( - KtBinaryExpressionWithTypeRHS::class.java, KotlinBundle.message("convert.to.unsafecast.call") + KtBinaryExpressionWithTypeRHS::class.java, + KotlinBundle.lazyMessage("convert.to.unsafecast.call"), ) { - override fun isApplicableTo(element: KtBinaryExpressionWithTypeRHS, caretOffset: Int): Boolean { if (!element.platform.isJs()) return false @@ -32,7 +32,7 @@ class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention( - KtParameter::class.java, KotlinBundle.message("convert.to.array.parameter") + KtParameter::class.java, + KotlinBundle.lazyMessage("convert.to.array.parameter"), ) { - override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean { if (element.getChildOfType() == null) return false return element.isVarArg diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt index bd642ae6a3a..379b11d81e9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -24,8 +24,10 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier -class ImportAllMembersIntention : SelfTargetingIntention(KtElement::class.java, KotlinBundle.message("import.members.with")), - HighPriorityAction { +class ImportAllMembersIntention : SelfTargetingIntention( + KtElement::class.java, + KotlinBundle.lazyMessage("import.members.with") +), HighPriorityAction { override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean { val receiverExpression = element.receiverExpression() ?: return false if (!receiverExpression.range.containsOffset(caretOffset)) return false @@ -42,13 +44,11 @@ class ImportAllMembersIntention : SelfTargetingIntention(KtElement::c val helper = ImportInsertHelper.getInstance(project) if (helper.importDescriptor(dummyFile, target, forceAllUnderImport = true) == ImportDescriptorResult.FAIL) return false - text = KotlinBundle.message("import.members.from.0", targetFqName.parent().asString()) + setTextGetter(KotlinBundle.lazyMessage("import.members.from.0", targetFqName.parent().asString())) return true } - override fun applyTo(element: KtElement, editor: Editor?) { - element.importReceiverMembers() - } + override fun applyTo(element: KtElement, editor: Editor?) = element.importReceiverMembers() companion object { fun KtElement.importReceiverMembers() { @@ -56,12 +56,12 @@ class ImportAllMembersIntention : SelfTargetingIntention(KtElement::c val classFqName = target.importableFqName!!.parent() ImportInsertHelper.getInstance(project).importDescriptor(containingKtFile, target, forceAllUnderImport = true) - val qualifiedExpressions = containingKtFile.collectDescendantsOfType { qualifiedExpression -> val qualifierName = qualifiedExpression.receiverExpression.getQualifiedElementSelector() as? KtNameReferenceExpression qualifierName?.getReferencedNameAsName() == classFqName.shortName() && target(qualifiedExpression)?.importableFqName ?.parent() == classFqName } + val userTypes = containingKtFile.collectDescendantsOfType { userType -> val receiver = userType.receiverExpression()?.getQualifiedElementSelector() as? KtNameReferenceExpression receiver?.getReferencedNameAsName() == classFqName.shortName() && target(userType)?.importableFqName @@ -77,6 +77,7 @@ class ImportAllMembersIntention : SelfTargetingIntention(KtElement::c if (bindingContext[BindingContext.QUALIFIER, receiverExpression] !is ClassQualifier) { return null } + val selector = qualifiedElement.getQualifiedElementSelector() as? KtNameReferenceExpression ?: return null return selector.mainReference.resolveToDescriptors(bindingContext).firstOrNull() } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InfixCallToOrdinaryIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InfixCallToOrdinaryIntention.kt index e8ae0e13950..1db720e9bcd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InfixCallToOrdinaryIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InfixCallToOrdinaryIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -10,11 +10,10 @@ import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* -class InfixCallToOrdinaryIntention : - SelfTargetingIntention( - KtBinaryExpression::class.java, - KotlinBundle.message("replace.infix.call.with.ordinary.call") - ) { +class InfixCallToOrdinaryIntention : SelfTargetingIntention( + KtBinaryExpression::class.java, + KotlinBundle.lazyMessage("replace.infix.call.with.ordinary.call") +) { override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean { if (element.operationToken != KtTokens.IDENTIFIER || element.left == null || element.right == null) return false return element.operationReference.textRange.containsOffset(caretOffset) @@ -31,8 +30,14 @@ class InfixCallToOrdinaryIntention : is KtLambdaExpression -> " $2:'{}'" else -> "($2)" } - val replacement = - KtPsiFactory(element).createExpressionByPattern(pattern, element.left!!, element.operationReference.text, argument) + + val replacement = KtPsiFactory(element).createExpressionByPattern( + pattern, + element.left!!, + element.operationReference.text, + argument + ) + return element.replace(replacement) as KtExpression } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt index 94060070a5d..c9d52d2eb99 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IntroduceBackingPropertyIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -31,16 +20,14 @@ import org.jetbrains.kotlin.resolve.BindingContext class IntroduceBackingPropertyIntention : SelfTargetingIntention( KtProperty::class.java, - KotlinBundle.message("introduce.backing.property") + KotlinBundle.lazyMessage("introduce.backing.property") ) { override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { if (!canIntroduceBackingProperty(element)) return false return element.nameIdentifier?.textRange?.containsOffset(caretOffset) == true } - override fun applyTo(element: KtProperty, editor: Editor?) { - introduceBackingProperty(element) - } + override fun applyTo(element: KtProperty, editor: Editor?) = introduceBackingProperty(element) companion object { fun canIntroduceBackingProperty(property: KtProperty): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt index 5e83abf7ad9..7e5e6332adb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull class InvertIfConditionIntention : SelfTargetingIntention( KtIfExpression::class.java, - KotlinBundle.message("invert.if.condition") + KotlinBundle.lazyMessage("invert.if.condition") ) { override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean { if (!element.ifKeyword.textRange.containsOffset(caretOffset)) return false @@ -39,10 +39,9 @@ class InvertIfConditionIntention : SelfTargetingIntention( PsiChildRange(element, rBrace) else PsiChildRange.singleElement(element) + val commentSaver = CommentSaver(commentSavingRange) - if (rBrace != null) { - element.nextEolCommentOnSameLine()?.delete() - } + if (rBrace != null) element.nextEolCommentOnSameLine()?.delete() val condition = element.condition!! val newCondition = (condition as? KtQualifiedExpression)?.invertSelectorFunction() ?: condition.negate() @@ -53,6 +52,7 @@ class InvertIfConditionIntention : SelfTargetingIntention( PsiChildRange(newIf, rBrace) else PsiChildRange(newIf, parentBlockRBrace(newIf) ?: newIf) + commentSaver.restore(commentRestoreRange) val newIfCondition = newIf.condition @@ -207,12 +207,13 @@ class InvertIfConditionIntention : SelfTargetingIntention( val lastStatement = parent.statements.last() return if (expression == lastStatement) { exitStatementExecutedAfter(parent) - } else if (lastStatement.isExitStatement() && expression.siblings(withItself = false) - .firstIsInstance() == lastStatement + } else if (lastStatement.isExitStatement() && + expression.siblings(withItself = false).firstIsInstance() == lastStatement ) { lastStatement - } else + } else { null + } } when (parent) { @@ -225,18 +226,16 @@ class InvertIfConditionIntention : SelfTargetingIntention( } } - is KtContainerNode -> { - when (val pparent = parent.parent) { - is KtLoopExpression -> { - if (expression == pparent.body) { - return KtPsiFactory(expression).createExpression("continue") - } + is KtContainerNode -> when (val pparent = parent.parent) { + is KtLoopExpression -> { + if (expression == pparent.body) { + return KtPsiFactory(expression).createExpression("continue") } + } - is KtIfExpression -> { - if (expression == pparent.then || expression == pparent.`else`) { - return exitStatementExecutedAfter(pparent) - } + is KtIfExpression -> { + if (expression == pparent.then || expression == pparent.`else`) { + return exitStatementExecutedAfter(pparent) } } } @@ -244,13 +243,10 @@ class InvertIfConditionIntention : SelfTargetingIntention( return null } - private fun parentBlockRBrace(element: KtIfExpression): PsiElement? { - return (element.parent as? KtBlockExpression)?.rBrace - } + private fun parentBlockRBrace(element: KtIfExpression): PsiElement? = (element.parent as? KtBlockExpression)?.rBrace - private fun KtIfExpression.nextEolCommentOnSameLine(): PsiElement? { - val lastLineNumber = getLineNumber(false) - return siblings(withItself = false) + private fun KtIfExpression.nextEolCommentOnSameLine(): PsiElement? = getLineNumber(false).let { lastLineNumber -> + siblings(withItself = false) .takeWhile { it.getLineNumber() == lastLineNumber } .firstOrNull { it is PsiComment && it.node.elementType == KtTokens.EOL_COMMENT } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt index bd485000cb5..e015573d01f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.types.KotlinType class IterateExpressionIntention : SelfTargetingIntention( KtExpression::class.java, - KotlinBundle.message("iterate.over.collection") + KotlinBundle.lazyMessage("iterate.over.collection") ), HighPriorityAction { override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean { @@ -36,10 +36,13 @@ class IterateExpressionIntention : SelfTargetingIntention( val range = element.textRange if (caretOffset != range.startOffset && caretOffset != range.endOffset) return false val data = data(element) ?: return false - text = KotlinBundle.message( - "iterate.over.0", - IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType) + setTextGetter( + KotlinBundle.lazyMessage( + "iterate.over.0", + IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType) + ) ) + return true } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/LambdaToAnonymousFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/LambdaToAnonymousFunctionIntention.kt index 395fc40ddd5..4f598cd8ac7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/LambdaToAnonymousFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/LambdaToAnonymousFunctionIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -31,8 +31,8 @@ import org.jetbrains.kotlin.types.typeUtil.makeNotNullable class LambdaToAnonymousFunctionIntention : SelfTargetingIntention( KtLambdaExpression::class.java, - KotlinBundle.message("convert.to.anonymous.function"), - KotlinBundle.message("convert.lambda.expression.to.anonymous.function") + KotlinBundle.lazyMessage("convert.to.anonymous.function"), + KotlinBundle.lazyMessage("convert.lambda.expression.to.anonymous.function") ), LowPriorityAction { override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean { if (element.getStrictParentOfType() == null) return false @@ -75,6 +75,7 @@ class LambdaToAnonymousFunctionIntention : SelfTargetingIntention(KtIfExpression::class.java, KotlinBundle.message("merge.else.if")) { +class MergeElseIfIntention : SelfTargetingIntention( + KtIfExpression::class.java, + KotlinBundle.lazyMessage("merge.else.if") +) { override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean { val elseBody = element.`else` ?: return false val nestedIf = elseBody.nestedIf() ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MergeIfsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MergeIfsIntention.kt index 4ad8d06b9fb..97ecd7e2d46 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MergeIfsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MergeIfsIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -20,8 +9,7 @@ import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.psi.* -class MergeIfsIntention : SelfTargetingIntention(KtIfExpression::class.java, KotlinBundle.message("merge.if.s")) { - +class MergeIfsIntention : SelfTargetingIntention(KtIfExpression::class.java, KotlinBundle.lazyMessage("merge.if.s")) { override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean { if (element.`else` != null) return false val then = element.then ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt index fc6f4f29c66..e0cb9b63540 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -25,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtLambdaArgument import org.jetbrains.kotlin.psi.psiUtil.containsInside class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention( - KtLambdaArgument::class.java, KotlinBundle.message("move.lambda.argument.into.parentheses") + KtLambdaArgument::class.java, KotlinBundle.lazyMessage("move.lambda.argument.into.parentheses") ), LowPriorityAction { override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean { val body = element.getLambdaExpression()?.bodyExpression ?: return true diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToClassBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToClassBodyIntention.kt index 61c465160f0..bddb0d6c4b7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToClassBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToClassBodyIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -21,17 +21,15 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class MovePropertyToClassBodyIntention : SelfTargetingIntention( KtParameter::class.java, - KotlinBundle.message("move.to.class.body") + KotlinBundle.lazyMessage("move.to.class.body") ) { - override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean { - return element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation() - } + override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean = + element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation() override fun applyTo(element: KtParameter, editor: Editor?) { val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return - val propertyDeclaration = KtPsiFactory(element) - .createProperty("${element.valOrVarKeyword?.text} ${element.name} = ${element.name}") + val propertyDeclaration = KtPsiFactory(element).createProperty("${element.valOrVarKeyword?.text} ${element.name} = ${element.name}") val firstProperty = parentClass.getProperties().firstOrNull() parentClass.addDeclarationBefore(propertyDeclaration, firstProperty).apply { @@ -59,6 +57,7 @@ class MovePropertyToClassBodyIntention : SelfTargetingIntention( } else { element.modifierList?.delete() } + if (hasVararg) element.addModifier(KtTokens.VARARG_KEYWORD) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt index ecda92a0b01..2e63eb84d20 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -47,7 +36,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.KotlinType class MovePropertyToConstructorIntention : - SelfTargetingIntention(KtProperty::class.java, KotlinBundle.message("move.to.constructor")), + SelfTargetingIntention(KtProperty::class.java, KotlinBundle.lazyMessage("move.to.constructor")), LocalQuickFix { override fun applyFix(project: Project, descriptor: ProblemDescriptor) { @@ -102,8 +91,10 @@ class MovePropertyToConstructorIntention : commentSaver.restore(this) } } else { - val typeText = - element.typeReference?.text ?: (element.resolveToDescriptorIfAny() as? PropertyDescriptor)?.type?.render() ?: return + val typeText = element.typeReference?.text + ?: (element.resolveToDescriptorIfAny() as? PropertyDescriptor)?.type?.render() + ?: return + val parameterText = buildString { element.modifierList?.getModifiersText()?.let(this::append) propertyAnnotationsText?.takeIf(String::isNotBlank)?.let { appendWithSpaceBefore(it) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/NullableBooleanEqualityCheckToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/NullableBooleanEqualityCheckToElvisIntention.kt index 61fa4d0f204..dadb3403e01 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/NullableBooleanEqualityCheckToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/NullableBooleanEqualityCheckToElvisIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean class NullableBooleanEqualityCheckToElvisIntention : SelfTargetingIntention( - KtBinaryExpression::class.java, KotlinBundle.message("convert.boolean.const.to.elvis") + KtBinaryExpression::class.java, KotlinBundle.lazyMessage("convert.boolean.const.to.elvis") ) { override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean { if (element.operationToken != KtTokens.EQEQ && element.operationToken != KtTokens.EXCLEQ) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt index 5f1ea102b93..35024fde68b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -26,8 +15,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset -class RemoveBracesIntention : SelfTargetingIntention(KtElement::class.java, KotlinBundle.message("remove.braces")) { - +class RemoveBracesIntention : SelfTargetingIntention(KtElement::class.java, KotlinBundle.lazyMessage("remove.braces")) { private fun KtElement.findChildBlock() = when (this) { is KtBlockExpression -> this is KtLoopExpression -> body as? KtBlockExpression @@ -47,11 +35,11 @@ class RemoveBracesIntention : SelfTargetingIntention(KtElement::class } val description = container.description() ?: return false - text = KotlinBundle.message("remove.braces.from.0.statement", description) + setTextGetter(KotlinBundle.lazyMessage("remove.braces.from.0.statement", description)) return true } is KtWhenEntry -> { - text = KotlinBundle.message("remove.braces.from.when.entry") + setTextGetter(KotlinBundle.lazyMessage("remove.braces.from.when.entry")) return singleStatement !is KtNamedDeclaration } else -> return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveConstructorKeywordIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveConstructorKeywordIntention.kt index 3ecc989b680..7ce19ceb9fc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveConstructorKeywordIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveConstructorKeywordIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject class RemoveConstructorKeywordIntention : SelfTargetingIntention( KtPrimaryConstructor::class.java, - KotlinBundle.message("remove.constructor.keyword") + KotlinBundle.lazyMessage("remove.constructor.keyword") ) { override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) { element.removeRedundantConstructorKeywordAndSpace() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt index f4f2d8ea1f5..0109fc1c7b5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -11,11 +11,10 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.endOffset -class RemoveExplicitLambdaParameterTypesIntention : - SelfTargetingIntention( - KtLambdaExpression::class.java, - KotlinBundle.message("remove.explicit.lambda.parameter.types.may.break.code") - ) { +class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention( + KtLambdaExpression::class.java, + KotlinBundle.lazyMessage("remove.explicit.lambda.parameter.types.may.break.code") +) { override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean { if (element.valueParameters.none { it.typeReference != null }) return false val arrow = element.functionLiteral.arrow ?: return false @@ -28,6 +27,7 @@ class RemoveExplicitLambdaParameterTypesIntention : val parameterString = oldParameterList.parameters.asSequence().map { it.destructuringDeclaration?.text ?: it.name }.joinToString(", ") + val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString) oldParameterList.replace(newParameterList) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveLabeledReturnInLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveLabeledReturnInLambdaIntention.kt index 39786b4047e..2f54ebe8847 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveLabeledReturnInLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveLabeledReturnInLambdaIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType class RemoveLabeledReturnInLambdaIntention : SelfTargetingIntention( KtReturnExpression::class.java, - KotlinBundle.message("remove.labeled.return.from.last.expression.in.a.lambda") + KotlinBundle.lazyMessage("remove.labeled.return.from.last.expression.in.a.lambda") ), LowPriorityAction { override fun isApplicableTo(element: KtReturnExpression, caretOffset: Int): Boolean { val labelName = element.getLabelName() ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceUntilWithRangeToIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceUntilWithRangeToIntention.kt index fe682e8400a..c93e89b3a58 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceUntilWithRangeToIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceUntilWithRangeToIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -29,7 +18,7 @@ internal fun KtExpression.getArguments() = when (this) { class ReplaceUntilWithRangeToIntention : SelfTargetingIntention( KtExpression::class.java, - KotlinBundle.message("replace.with.0.operator", "..") + KotlinBundle.lazyMessage("replace.with.0.operator", "..") ) { override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean { if (element !is KtBinaryExpression && element !is KtDotQualifiedExpression) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOrdinaryAssignmentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOrdinaryAssignmentIntention.kt index ca855d6bdd0..037c314fa5c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOrdinaryAssignmentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOrdinaryAssignmentIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -14,9 +14,10 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern -class ReplaceWithOrdinaryAssignmentIntention : - SelfTargetingIntention(KtBinaryExpression::class.java, KotlinBundle.message("replace.with.ordinary.assignment")), - LowPriorityAction { +class ReplaceWithOrdinaryAssignmentIntention : SelfTargetingIntention( + KtBinaryExpression::class.java, + KotlinBundle.lazyMessage("replace.with.ordinary.assignment") +), LowPriorityAction { override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean { if (element.operationToken !in KtTokens.AUGMENTED_ASSIGNMENTS) return false if (element.left !is KtNameReferenceExpression) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt index be023effffd..de7e68a393c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis import org.jetbrains.kotlin.psi.psiUtil.startOffset -class SplitIfIntention : SelfTargetingIntention(KtExpression::class.java, KotlinBundle.message("split.if.into.two")) { +class SplitIfIntention : SelfTargetingIntention(KtExpression::class.java, KotlinBundle.lazyMessage("split.if.into.two")) { override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean { return when (element) { is KtOperationReferenceExpression -> isOperatorValid(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt index 810b398d91b..323b747346f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -20,9 +20,8 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions class SwapBinaryExpressionIntention : SelfTargetingIntention( KtBinaryExpression::class.java, - KotlinBundle.message("flip.binary.expression") -), - LowPriorityAction { + KotlinBundle.lazyMessage("flip.binary.expression") +), LowPriorityAction { companion object { private val SUPPORTED_OPERATIONS: Set by lazy { setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ) @@ -47,7 +46,7 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention if (operationToken in SUPPORTED_OPERATIONS || operationToken == IDENTIFIER && operationTokenText in SUPPORTED_OPERATION_NAMES ) { - text = KotlinBundle.message("flip.0", operationTokenText) + setTextGetter(KotlinBundle.lazyMessage("flip.0", operationTokenText)) return true } return false @@ -55,16 +54,16 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention override fun applyTo(element: KtBinaryExpression, editor: Editor?) { // Have to use text here to preserve names like "plus" - val operator = element.operationReference.text!! - val convertedOperator = when (operator) { + val convertedOperator = when (val operator = element.operationReference.text!!) { ">" -> "<" "<" -> ">" "<=" -> ">=" ">=" -> "<=" else -> operator } - val left = leftSubject(element)!! - val right = rightSubject(element)!! + + val left = leftSubject(element) ?: return + val right = rightSubject(element) ?: return val rightCopy = right.copied() val leftCopy = left.copied() left.replace(rightCopy) @@ -72,13 +71,11 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention element.replace(KtPsiFactory(element).createExpressionByPattern("$0 $convertedOperator $1", element.left!!, element.right!!)) } - private fun leftSubject(element: KtBinaryExpression): KtExpression? { - return firstDescendantOfTighterPrecedence(element.left, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getRight) - } + private fun leftSubject(element: KtBinaryExpression): KtExpression? = + firstDescendantOfTighterPrecedence(element.left, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getRight) - private fun rightSubject(element: KtBinaryExpression): KtExpression? { - return firstDescendantOfTighterPrecedence(element.right, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getLeft) - } + private fun rightSubject(element: KtBinaryExpression): KtExpression? = + firstDescendantOfTighterPrecedence(element.right, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getLeft) private fun firstDescendantOfTighterPrecedence( expression: KtExpression?, @@ -91,6 +88,7 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention return firstDescendantOfTighterPrecedence(expression.getChild(), precedence, getChild) } } + return expression } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt index a1ad642697c..b581e168cf9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -27,7 +16,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class ToInfixCallIntention : SelfTargetingIntention( KtCallExpression::class.java, - KotlinBundle.message("replace.with.infix.function.call") + KotlinBundle.lazyMessage("replace.with.infix.function.call") ) { override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean { val calleeExpr = element.calleeExpression as? KtNameReferenceExpression ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt index 7af1c21f10b..23795311cf5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt @@ -8,21 +8,22 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.application.options.CodeStyle import com.intellij.codeInsight.intention.LowPriorityAction import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings import org.jetbrains.kotlin.idea.util.addTrailingCommaIsAllowedForThis import org.jetbrains.kotlin.psi.KtElement -class TrailingCommaIntention : SelfTargetingIntention(KtElement::class.java, "Enable/disable a trailing comma in the formatter"), - LowPriorityAction { +class TrailingCommaIntention : SelfTargetingIntention( + KtElement::class.java, + KotlinBundle.lazyMessage("intention.trailing.comma.text") +), LowPriorityAction { override fun applyTo(element: KtElement, editor: Editor?) { val kotlinCustomSettings = CodeStyle.getSettings(element.project).kotlinCustomSettings kotlinCustomSettings.ALLOW_TRAILING_COMMA = !kotlinCustomSettings.ALLOW_TRAILING_COMMA } - override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean { - return element.addTrailingCommaIsAllowedForThis().also { - val action = if (CodeStyle.getSettings(element.project).kotlinCustomSettings.ALLOW_TRAILING_COMMA) "Disable" else "Enable" - text = "$action a trailing comma by default in the formatter" - } + override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean = element.addTrailingCommaIsAllowedForThis().also { + val actionNumber = 1.takeIf { CodeStyle.getSettings(element.project).kotlinCustomSettings.ALLOW_TRAILING_COMMA } ?: 0 + setTextGetter(KotlinBundle.lazyMessage("intention.trailing.comma.custom.text", actionNumber)) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UnderscoresInNumericLiteralIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UnderscoresInNumericLiteralIntention.kt index d6b68977af7..34eb74f06a3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UnderscoresInNumericLiteralIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UnderscoresInNumericLiteralIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.psi.stubs.ConstantValueKind import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType class AddUnderscoresToNumericLiteralIntention : SelfTargetingIntention( - KtConstantExpression::class.java, KotlinBundle.message("add.underscores") + KtConstantExpression::class.java, KotlinBundle.lazyMessage("add.underscores") ) { override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean { val text = element.text @@ -32,11 +32,10 @@ class AddUnderscoresToNumericLiteralIntention : SelfTargetingIntention( - KtConstantExpression::class.java, KotlinBundle.message("remove.underscores") + KtConstantExpression::class.java, KotlinBundle.lazyMessage("remove.underscores") ) { - override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean { - return element.isNumeric() && element.text.hasUnderscore() - } + override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean = + element.isNumeric() && element.text.hasUnderscore() override fun applyTo(element: KtConstantExpression, editor: Editor?) { element.replace(KtPsiFactory(element).createExpression(element.text.replace("_", ""))) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ValToObjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ValToObjectIntention.kt index fc580291bb8..9cd7facf09d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ValToObjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ValToObjectIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions @@ -26,9 +15,8 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset class ValToObjectIntention : SelfTargetingIntention( KtProperty::class.java, - KotlinBundle.message("convert.to.object.declaration") + KotlinBundle.lazyMessage("convert.to.object.declaration") ) { - override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { if (element.isVar) return false if (!element.isTopLevel) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt index 4c99493eba1..0501169cf06 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.psi.buildExpression import org.jetbrains.kotlin.psi.psiUtil.startOffset class EliminateWhenSubjectIntention : - SelfTargetingIntention(KtWhenExpression::class.java, KotlinBundle.message("eliminate.argument.of.when")), + SelfTargetingIntention(KtWhenExpression::class.java, KotlinBundle.lazyMessage("eliminate.argument.of.when")), LowPriorityAction { override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean { if (element.subjectExpression !is KtNameReferenceExpression) return false @@ -27,7 +27,7 @@ class EliminateWhenSubjectIntention : } override fun applyTo(element: KtWhenExpression, editor: Editor?) { - val subject = element.subjectExpression!! + val subject = element.subjectExpression ?: return val commentSaver = CommentSaver(element, saveLineBreaks = true) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt index e1fe0daad44..5f8a16f5361 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions @@ -28,7 +17,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset class FlattenWhenIntention : SelfTargetingIntention( KtWhenExpression::class.java, - KotlinBundle.message("flatten.when.expression") + KotlinBundle.lazyMessage("flatten.when.expression") ) { override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean { val subject = element.subjectExpression diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt index 75c19e91f6f..1adfb8dad31 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.quickfix @@ -69,15 +58,12 @@ class AddConstModifierFix(property: KtProperty) : AddModifierFix(property, KtTok } class AddConstModifierIntention : SelfTargetingIntention( - KtProperty::class.java, KotlinBundle.message("fix.add.const.modifier") + KtProperty::class.java, + KotlinBundle.lazyMessage("fix.add.const.modifier"), ) { - override fun applyTo(element: KtProperty, editor: Editor?) { - AddConstModifierFix.addConstModifier(element) - } + override fun applyTo(element: KtProperty, editor: Editor?) = AddConstModifierFix.addConstModifier(element) - override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { - return isApplicableTo(element) - } + override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = isApplicableTo(element) companion object { fun isApplicableTo(element: KtProperty): Boolean {