Rename: Fix field identifier replacement #KT-8018 Fixed
This commit is contained in:
@@ -331,8 +331,8 @@ public class JetPsiFactory(private val project: Project) {
|
|||||||
public fun createLabeledExpression(labelName: String): JetLabeledExpression
|
public fun createLabeledExpression(labelName: String): JetLabeledExpression
|
||||||
= createExpression("$labelName@ 1") as JetLabeledExpression
|
= createExpression("$labelName@ 1") as JetLabeledExpression
|
||||||
|
|
||||||
public fun createFieldIdentifier(fieldName: String): JetExpression {
|
public fun createFieldIdentifier(fieldName: String): PsiElement {
|
||||||
return createExpression("$" + fieldName)
|
return (createExpression("$" + fieldName) as JetNameReferenceExpression).getReferencedNameElement()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun createTypeCodeFragment(text: String, context: PsiElement?): JetTypeCodeFragment {
|
public fun createTypeCodeFragment(text: String, context: PsiElement?): JetTypeCodeFragment {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class Exp(p1: String) {
|
||||||
|
val /*rename*/prop11: String = p1
|
||||||
|
get(): String {
|
||||||
|
return $prop11
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class Exp(p1: String) {
|
||||||
|
val /*rename*/prop1: String = p1
|
||||||
|
get(): String {
|
||||||
|
return $prop1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"newName": "prop11",
|
||||||
|
"mainFile": "test.kt",
|
||||||
|
"checkErrorsAfter": "true"
|
||||||
|
}
|
||||||
@@ -22,10 +22,13 @@ import com.intellij.openapi.extensions.Extensions
|
|||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.openapi.vfs.VirtualFileVisitor
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
|
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
|
||||||
@@ -39,6 +42,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
|||||||
import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
|
import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
|
||||||
import org.jetbrains.kotlin.idea.jsonUtils.getString
|
import org.jetbrains.kotlin.idea.jsonUtils.getString
|
||||||
import org.jetbrains.kotlin.idea.search.allScope
|
import org.jetbrains.kotlin.idea.search.allScope
|
||||||
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
import org.jetbrains.kotlin.name.*
|
import org.jetbrains.kotlin.name.*
|
||||||
@@ -94,6 +98,20 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
|||||||
if (hintDirective != null) {
|
if (hintDirective != null) {
|
||||||
Assert.fail("""Hint "$hintDirective" was expected""")
|
Assert.fail("""Hint "$hintDirective" was expected""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (renameObject["checkErrorsAfter"]?.getAsBoolean() ?: false) {
|
||||||
|
val psiManager = PsiManager.getInstance(myProject)
|
||||||
|
val visitor = object : VirtualFileVisitor<Any>() {
|
||||||
|
override fun visitFile(file: VirtualFile): Boolean {
|
||||||
|
(psiManager.findFile(file) as? JetFile)?.let { DirectiveBasedActionUtils.checkForUnexpectedErrors(it) }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (sourceRoot in ModuleRootManager.getInstance(myModule).getSourceRoots()) {
|
||||||
|
VfsUtilCore.visitChildrenRecursively(sourceRoot, visitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (e : Exception) {
|
catch (e : Exception) {
|
||||||
if (e !is RefactoringErrorHintException && e !is ConflictsInTestsException) throw e
|
if (e !is RefactoringErrorHintException && e !is ConflictsInTestsException) throw e
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameFieldIdentifier/fieldIdentifier.test")
|
||||||
|
public void testRenameFieldIdentifier_FieldIdentifier() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameFieldIdentifier/fieldIdentifier.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("renameGet/get.test")
|
@TestMetadata("renameGet/get.test")
|
||||||
public void testRenameGet_Get() throws Exception {
|
public void testRenameGet_Get() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameGet/get.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameGet/get.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user