diff --git a/ChangeLog.md b/ChangeLog.md index f1609513b61..6bf2b916b73 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -179,6 +179,7 @@ - [`KT-8860`](https://youtrack.jetbrains.com/issue/KT-8860) Allow renaming class by constructor delegation call referencing primary constructor - [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references - [`KT-9157`](https://youtrack.jetbrains.com/issue/KT-9157) Fixed in-place rename of Kotlin expression referring Java declaration +- [`KT-9444`](https://youtrack.jetbrains.com/issue/KT-9444) Rename dialog: Allow typing any identifier without backquotes - [`KT-10713`](https://youtrack.jetbrains.com/issue/KT-10713) Skip read-only declarations when renaming parameters #### Java to Kotlin converter diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index b955b47eaca..f3d69badf87 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -435,6 +435,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinDeclarationRenameInputValidator.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinDeclarationRenameInputValidator.kt new file mode 100644 index 00000000000..b6199494f29 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinDeclarationRenameInputValidator.kt @@ -0,0 +1,33 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin.idea.refactoring.rename + +import com.intellij.patterns.PlatformPatterns +import com.intellij.psi.PsiElement +import com.intellij.refactoring.rename.RenameInputValidator +import com.intellij.util.ProcessingContext +import org.jetbrains.kotlin.idea.core.KotlinNameSuggester +import org.jetbrains.kotlin.idea.core.quoteIfNeeded +import org.jetbrains.kotlin.psi.KtNamedDeclaration + +class KotlinDeclarationRenameInputValidator : RenameInputValidator { + override fun getPattern() = PlatformPatterns.psiElement(KtNamedDeclaration::class.java) + + override fun isInputValid(newName: String?, element: PsiElement?, context: ProcessingContext?): Boolean { + return newName != null && KotlinNameSuggester.isIdentifier(newName.quoteIfNeeded()) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt index 515384742e5..4ba771ba84b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt @@ -38,6 +38,8 @@ class RenameKotlinClassProcessor : RenameKotlinPsiProcessor() { override fun substituteElementToRename(element: PsiElement, editor: Editor?) = getClassOrObject(element) override fun prepareRenaming(element: PsiElement, newName: String, allRenames: MutableMap) { + super.prepareRenaming(element, newName, allRenames) + val classOrObject = getClassOrObject(element) as? KtClassOrObject ?: return val file = classOrObject.getContainingKtFile() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt index f21629cf68b..0f920cf1832 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt @@ -80,7 +80,8 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() { return substitutedJavaElement } - override fun prepareRenaming(element: PsiElement?, newName: String?, allRenames: MutableMap, scope: SearchScope) { + override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap, scope: SearchScope) { + super.prepareRenaming(element, newName, allRenames, scope) val psiMethod = wrapPsiMethod(element) if (psiMethod?.containingClass != null) { javaMethodProcessorInstance.prepareRenaming(psiMethod, newName, allRenames, scope) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinParameterProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinParameterProcessor.kt index 1511dc06303..da48e278655 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinParameterProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinParameterProcessor.kt @@ -32,8 +32,10 @@ import org.jetbrains.kotlin.resolve.OverrideResolver class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() { override fun canProcessElement(element: PsiElement) = element is KtParameter && element.ownerFunction is KtNamedFunction - override fun prepareRenaming(element: PsiElement, newName: String, allRenames: MutableMap, scope: SearchScope) { - if (element !is KtParameter) return + override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap, scope: SearchScope) { + super.prepareRenaming(element, newName, allRenames, scope) + + if (element !is KtParameter || newName == null) return val function = element.ownerFunction ?: return val originalDescriptor = function.resolveToDescriptor() as FunctionDescriptor diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt index a3b8db255ae..661a77616d1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt @@ -121,8 +121,10 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() { return declarationToRename } - override fun prepareRenaming(element: PsiElement?, newName: String?, allRenames: MutableMap, scope: SearchScope) { - val namedUnwrappedElement = element?.namedUnwrappedElement + override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap, scope: SearchScope) { + super.prepareRenaming(element, newName, allRenames, scope) + + val namedUnwrappedElement = element.namedUnwrappedElement val propertyMethods = when(namedUnwrappedElement) { is KtProperty -> runReadAction { LightClassUtil.getLightClassPropertyMethods(namedUnwrappedElement) } is KtParameter -> runReadAction { LightClassUtil.getLightClassPropertyMethods(namedUnwrappedElement) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt index 63eaaf71005..d2107f381c5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt @@ -18,9 +18,12 @@ package org.jetbrains.kotlin.idea.refactoring.rename import com.intellij.psi.PsiElement import com.intellij.psi.PsiReference +import com.intellij.psi.search.SearchScope import com.intellij.psi.search.searches.MethodReferencesSearch import com.intellij.refactoring.rename.RenamePsiElementProcessor import org.jetbrains.kotlin.asJava.toLightMethods +import org.jetbrains.kotlin.idea.core.KotlinNameSuggester +import org.jetbrains.kotlin.idea.core.quoteIfNeeded import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtParameter @@ -39,4 +42,10 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() { } return references } + + override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap, scope: SearchScope) { + if (newName != null && !KotlinNameSuggester.isIdentifier(newName)) { + allRenames[element] = newName.quoteIfNeeded() + } + } }