diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java index 001f854915b..6c45b49b15a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java @@ -92,7 +92,7 @@ abstract class KtNamedDeclarationStub> extends PsiElement newIdentifier = KtPsiFactory(this).createNameIdentifierIfPossible(name); if (newIdentifier != null) { - identifier.replace(newIdentifier); + KtPsiUtilKt.astReplace(identifier, newIdentifier); } else { identifier.delete(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 9097ae3e112..09b7027a642 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -568,4 +568,6 @@ fun KtExpression.getLabeledParent(labelName: String): KtLabeledExpression? { } } return null -} \ No newline at end of file +} + +fun PsiElement.astReplace(newElement: PsiElement) = parent.node.replaceChild(node, newElement.node) \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt index d59cb422fa4..b4e2d3aa20e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt @@ -40,10 +40,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.isOneSegmentFQN import org.jetbrains.kotlin.plugin.references.SimpleNameReferenceExtension import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch -import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementOrCallableRef -import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector -import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DataClassDescriptorResolver import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor @@ -135,7 +132,12 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere } } - nameElement.replace(element) + if (element.node.elementType == KtTokens.IDENTIFIER) { + nameElement.astReplace(element) + } + else { + nameElement.replace(element) + } return expression } diff --git a/idea/testData/refactoring/rename/inplace/NoReformat.kt b/idea/testData/refactoring/rename/inplace/NoReformat.kt new file mode 100644 index 00000000000..304f319e9a5 --- /dev/null +++ b/idea/testData/refactoring/rename/inplace/NoReformat.kt @@ -0,0 +1,7 @@ +public class OneLineKotlin { + var subject = 1 + var aux = 1 + public fun simple0() { subject } + public fun simple1() { subject = 2 } + public fun simple2() { aux = subject } +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/inplace/NoReformat.kt.after b/idea/testData/refactoring/rename/inplace/NoReformat.kt.after new file mode 100644 index 00000000000..d5ffffefc1e --- /dev/null +++ b/idea/testData/refactoring/rename/inplace/NoReformat.kt.after @@ -0,0 +1,7 @@ +public class OneLineKotlin { + var subject2 = 1 + var aux = 1 + public fun simple0() { subject2 } + public fun simple1() { subject2 = 2 } + public fun simple2() { aux = subject2 } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt index ec946399811..f1a095a4e1f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt @@ -11,6 +11,7 @@ import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.impl.SimpleDataContext import com.intellij.openapi.command.WriteCommandAction +import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler import com.intellij.testFramework.LightPlatformCodeInsightTestCase import com.intellij.testFramework.fixtures.CodeInsightTestUtil @@ -81,6 +82,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { doTestInplaceRename("name1") } + fun testNoReformat() { + doTestInplaceRename("subject2", MemberInplaceRenameHandler()) + } + private fun doTestImplicitLambdaParameter(newName: String) { configureByFile(getTestName(false) + ".kt") @@ -131,7 +136,7 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { checkResultByFile(getTestName(false) + ".kt.after") } - private fun doTestInplaceRename(newName: String?) { + private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = VariableInplaceRenameHandler()) { configureByFile(getTestName(false) + ".kt") val element = TargetElementUtil.findTargetElement( LightPlatformCodeInsightTestCase.myEditor, @@ -143,7 +148,6 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, LightPlatformCodeInsightTestCase.getCurrentEditorDataContext()) - val handler = VariableInplaceRenameHandler() if (newName == null) { assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element) }