diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt deleted file mode 100644 index 9969201e98f..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.inspections - -import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor -import com.intellij.openapi.project.Project - -interface KotlinUniversalQuickFix : IntentionAction, LocalQuickFix { - @JvmDefault - override fun getName() = text - - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - invoke(project, null, descriptor.psiElement?.containingFile) - } -} \ No newline at end of file diff --git a/idea/idea-frontend-independent/resources-en/messages/KotlinBundleIndependent.properties b/idea/idea-frontend-independent/resources-en/messages/KotlinBundleIndependent.properties index 4e223ee9b58..57eb28b42d1 100644 --- a/idea/idea-frontend-independent/resources-en/messages/KotlinBundleIndependent.properties +++ b/idea/idea-frontend-independent/resources-en/messages/KotlinBundleIndependent.properties @@ -65,4 +65,9 @@ find.usages.type.packageMemberAccess=Package member access and.delete.initializer=\ and delete initializer change.to.val=Change to val -change.to.var=Change to var \ No newline at end of file +change.to.var=Change to var + +remove.redundant.0.modifier=Remove redundant ''{0}'' modifier +make.0.not.1=Make {0} not {1} +remove.0.modifier=Remove ''{0}'' modifier +remove.modifier=Remove modifier diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt new file mode 100644 index 00000000000..f825e6742b0 --- /dev/null +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2021 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.inspections + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.openapi.project.Project + +interface KotlinUniversalQuickFix : IntentionAction, LocalQuickFix { + @JvmDefault + override fun getName() = text + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + invoke(project, null, descriptor.psiElement?.containingFile) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.kt similarity index 58% rename from idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.kt rename to idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.kt index 7e3f065422d..8adde90d147 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinCrossLanguageQuickFixAction.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-2021 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 diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.kt similarity index 68% rename from idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.kt rename to idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.kt index 706baf8857c..a6b71395372 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/KotlinSingleIntentionActionFactory.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-2021 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 diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt similarity index 83% rename from idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt rename to idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt index 20bae155702..da1ed5968b7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt @@ -9,8 +9,9 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile +import com.intellij.psi.PsiNameIdentifierOwner import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.idea.KotlinBundle +import org.jetbrains.kotlin.idea.KotlinBundleIndependent import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* @@ -27,15 +28,15 @@ class RemoveModifierFix( val modifierText = modifier.value when { isRedundant -> - KotlinBundle.message("remove.redundant.0.modifier", modifierText) + KotlinBundleIndependent.message("remove.redundant.0.modifier", modifierText) modifier === KtTokens.ABSTRACT_KEYWORD || modifier === KtTokens.OPEN_KEYWORD -> - KotlinBundle.message("make.0.not.1", AddModifierFix.getElementName(element), modifierText) + KotlinBundleIndependent.message("make.0.not.1", getElementName(element), modifierText) else -> - KotlinBundle.message("remove.0.modifier", modifierText, modifier) + KotlinBundleIndependent.message("remove.0.modifier", modifierText, modifier) } } - override fun getFamilyName() = KotlinBundle.message("remove.modifier") + override fun getFamilyName() = KotlinBundleIndependent.message("remove.modifier") override fun getText() = text @@ -137,5 +138,23 @@ class RemoveModifierFix( listOf(RemoveModifierFix(funInterface, KtTokens.FUN_KEYWORD, isRedundant = false)) } } + + fun getElementName(modifierListOwner: KtModifierListOwner): String { + var name: String? = null + if (modifierListOwner is PsiNameIdentifierOwner) { + val nameIdentifier = modifierListOwner.nameIdentifier + if (nameIdentifier != null) { + name = nameIdentifier.text + } else if ((modifierListOwner as? KtObjectDeclaration)?.isCompanion() == true) { + name = "companion object" + } + } else if (modifierListOwner is KtPropertyAccessor) { + name = modifierListOwner.namePlaceholder.text + } + if (name == null) { + name = modifierListOwner.text + } + return "'$name'" + } } } diff --git a/idea/resources-en/messages/KotlinBundle.properties b/idea/resources-en/messages/KotlinBundle.properties index 1228cc0f613..5e6248339db 100644 --- a/idea/resources-en/messages/KotlinBundle.properties +++ b/idea/resources-en/messages/KotlinBundle.properties @@ -1104,7 +1104,6 @@ remove.from.annotation.argument=Remove @ from annotation argument remove.default.parameter.value=Remove default parameter value remove.final.upper.bound=Remove final upper bound remove.function.body=Remove function body -remove.redundant.0.modifier=Remove redundant ''{0}'' modifier make.0.not.1=Make {0} not {1} remove.0.modifier=Remove ''{0}'' modifier remove.modifier=Remove modifier diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddModifierFix.kt index 13f9422221e..b1eb3e62438 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddModifierFix.kt @@ -20,7 +20,6 @@ import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile -import com.intellij.psi.PsiNameIdentifierOwner import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor @@ -43,14 +42,14 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.TypeUtils - open class AddModifierFix( +open class AddModifierFix( element: KtModifierListOwner, protected val modifier: KtModifierKeywordToken ) : KotlinCrossLanguageQuickFixAction(element), KotlinUniversalQuickFix { override fun getText(): String { val element = element ?: return "" if (modifier in modalityModifiers || modifier in VISIBILITY_MODIFIERS || modifier == CONST_KEYWORD) { - return KotlinBundle.message("fix.add.modifier.text", getElementName(element), modifier.value) + return KotlinBundle.message("fix.add.modifier.text", RemoveModifierFix.getElementName(element), modifier.value) } return KotlinBundle.message("fix.add.modifier.text.generic", modifier.value) } @@ -90,24 +89,6 @@ import org.jetbrains.kotlin.types.TypeUtils private val modalityModifiers = setOf(ABSTRACT_KEYWORD, OPEN_KEYWORD, FINAL_KEYWORD) - fun getElementName(modifierListOwner: KtModifierListOwner): String { - var name: String? = null - if (modifierListOwner is PsiNameIdentifierOwner) { - val nameIdentifier = modifierListOwner.nameIdentifier - if (nameIdentifier != null) { - name = nameIdentifier.text - } else if ((modifierListOwner as? KtObjectDeclaration)?.isCompanion() == true) { - name = "companion object" - } - } else if (modifierListOwner is KtPropertyAccessor) { - name = modifierListOwner.namePlaceholder.text - } - if (name == null) { - name = modifierListOwner.text - } - return "'$name'" - } - fun createFactory(modifier: KtModifierKeywordToken): KotlinSingleIntentionActionFactory { return createFactory(modifier, KtModifierListOwner::class.java) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddReifiedToTypeParameterOfFunctionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddReifiedToTypeParameterOfFunctionFix.kt index e422a7e52a6..1e5efc6160d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddReifiedToTypeParameterOfFunctionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddReifiedToTypeParameterOfFunctionFix.kt @@ -50,10 +50,10 @@ class AddReifiedToTypeParameterOfFunctionFix( ) : AddModifierFix(typeParameter, KtTokens.REIFIED_KEYWORD) { private val inlineFix = AddInlineToFunctionWithReifiedFix(function) - private val elementName = getElementName(function) + private val elementName = RemoveModifierFix.getElementName(function) override fun getText() = - element?.let { KotlinBundle.message("fix.make.type.parameter.reified", getElementName(it), elementName) } ?: "" + element?.let { KotlinBundle.message("fix.make.type.parameter.reified", RemoveModifierFix.getElementName(it), elementName) } ?: "" override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) { super.invokeImpl(project, editor, file) diff --git a/idea/src/org/jetbrains/kotlin/idea/util/quickfixUtil.kt b/idea/src/org/jetbrains/kotlin/idea/util/quickfixUtil.kt index 1a657ab6f02..03e0d0d7c95 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/quickfixUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/quickfixUtil.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory -import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.getDataFlowValueFactory import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtPrimaryConstructor diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/diagnosticBasedPostProcessing.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/diagnosticBasedPostProcessing.kt index 3d80bb185fd..6b532712d0d 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/diagnosticBasedPostProcessing.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/diagnosticBasedPostProcessing.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.DiagnosticFactory import org.jetbrains.kotlin.idea.core.util.range import org.jetbrains.kotlin.idea.quickfix.AddExclExclCallFix -import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionsFactory import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory import org.jetbrains.kotlin.idea.quickfix.QuickFixFactory import org.jetbrains.kotlin.idea.resolve.ResolutionFacade