Finding class by class id instead of fq name in rename tests.

This commit is contained in:
Evgeny Gerashchenko
2015-03-13 18:32:56 +03:00
parent c875584d0c
commit 3a8ded5b58
41 changed files with 56 additions and 47 deletions
@@ -108,4 +108,15 @@ public final class ClassId {
if (packageFqName.isRoot()) return "/" + relativeClassName; if (packageFqName.isRoot()) return "/" + relativeClassName;
return packageFqName.toString().replace('.', '/') + "/" + relativeClassName; return packageFqName.toString().replace('.', '/') + "/" + relativeClassName;
} }
@NotNull
public static ClassId fromString(@NotNull String string) {
int lastSlash = string.lastIndexOf("/");
if (lastSlash == -1) {
throw new IllegalArgumentException("Class id should contain slash: " + string);
}
FqNameUnsafe relativeClassName = new FqNameUnsafe(string.substring(lastSlash + 1));
FqName packageFqName = new FqName(string.substring(0, lastSlash).replace('/', '.'));
return new ClassId(packageFqName, relativeClassName, false);
}
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "compareTo", "oldName": "compareTo",
"newName": "foo", "newName": "foo",
"mainFile": "compareTo.kt" "mainFile": "compareTo.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "contains", "oldName": "contains",
"newName": "foo", "newName": "foo",
"mainFile": "contains.kt" "mainFile": "contains.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "contains", "oldName": "contains",
"newName": "foo", "newName": "foo",
"mainFile": "containsWithConflicts.kt", "mainFile": "containsWithConflicts.kt",
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "equals", "oldName": "equals",
"newName": "foo", "newName": "foo",
"mainFile": "equals.kt" "mainFile": "equals.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "component1", "oldName": "component1",
"newName": "foo", "newName": "foo",
"mainFile": "explicitComponentFunction.kt", "mainFile": "explicitComponentFunction.kt",
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "get", "oldName": "get",
"newName": "foo", "newName": "foo",
"mainFile": "get.kt" "mainFile": "get.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "inc", "oldName": "inc",
"newName": "foo", "newName": "foo",
"mainFile": "inc.kt", "mainFile": "inc.kt",
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "invoke", "oldName": "invoke",
"newName": "foo", "newName": "foo",
"mainFile": "invoke.kt" "mainFile": "invoke.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "iterator", "oldName": "iterator",
"newName": "foo", "newName": "foo",
"mainFile": "iterator.kt", "mainFile": "iterator.kt",
@@ -1,5 +1,5 @@
{ {
"type": "JAVA_CLASS", "type": "JAVA_CLASS",
"classFQN": "testing.SomeClass", "classId": "testing/SomeClass",
"newName": "NewName" "newName": "NewName"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_CLASS", "type": "JAVA_CLASS",
"classFQN": "testing.SomeInterface", "classId": "testing/SomeInterface",
"newName": "NewInterfaceName", "newName": "NewInterfaceName",
"comment": "For KT-4100 Imports doesn't change after java interface name refactoring" "comment": "For KT-4100 Imports doesn't change after java interface name refactoring"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.JavaClass", "classId": "testing/JavaClass",
"methodSignature": "String foo()", "methodSignature": "String foo()",
"newName": "bar" "newName": "bar"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "testing.kotlin.KotlinClass", "classId": "testing/kotlin/KotlinClass",
"oldName": "foo", "oldName": "foo",
"newName": "bar", "newName": "bar",
"mainFile": "MethodUsages.kt" "mainFile": "MethodUsages.kt"
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.A", "classId": "testing/rename/A",
"methodSignature": "void first()", "methodSignature": "void first()",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.JavaClient.D", "classId": "testing/JavaClient.D",
"methodSignature": "void first()", "methodSignature": "void first()",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "testing.rename.A", "classId": "testing/rename/A",
"oldName": "first", "oldName": "first",
"newName": "second", "newName": "second",
"comment": "KT-2836 Rename method with all its implementations" "comment": "KT-2836 Rename method with all its implementations"
@@ -1,5 +1,5 @@
{ {
"type": "JAVA_CLASS", "type": "JAVA_CLASS",
"classFQN": "testing.rename.First", "classId": "testing/rename/First",
"newName": "Third" "newName": "Third"
} }
@@ -1,5 +1,5 @@
{ {
"type": "KOTLIN_CLASS", "type": "KOTLIN_CLASS",
"classFQN": "testing.rename.First", "classId": "testing/rename/First",
"newName": "Third" "newName": "Third"
} }
@@ -1,5 +1,5 @@
{ {
"type": "KOTLIN_CLASS", "type": "KOTLIN_CLASS",
"classFQN": "X", "classId": "/X",
"newName": "TestX" "newName": "TestX"
} }
@@ -1,5 +1,5 @@
{ {
"type": "JAVA_CLASS", "type": "JAVA_CLASS",
"classFQN": "testing.ClassBefore", "classId": "testing/ClassBefore",
"newName": "ClassAfter" "newName": "ClassAfter"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_CLASS", "type": "KOTLIN_CLASS",
"classFQN": "testing.ClassBefore", "classId": "testing/ClassBefore",
"newName": "ClassAfter", "newName": "ClassAfter",
"mainFile": "ClassBefore.kt" "mainFile": "ClassBefore.kt"
} }
@@ -1,5 +1,5 @@
{ {
"type": "KOTLIN_CLASS", "type": "KOTLIN_CLASS",
"classFQN": "test.E", "classId": "test/E",
"newName": "D" "newName": "D"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "test.E", "classId": "test/E",
"oldName": "foo", "oldName": "foo",
"newName": "bar" "newName": "bar"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.C", "classId": "testing/rename/C",
"methodSignature": "int first()", "methodSignature": "int first()",
"newName": "second", "newName": "second",
"comment": "KT-3256 Can't rename a Kotlin function from Java code" "comment": "KT-3256 Can't rename a Kotlin function from Java code"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "testing.rename.C", "classId": "testing/rename/C",
"oldName": "first", "oldName": "first",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_CLASS", "type": "JAVA_CLASS",
"hint": "Can\u0027t rename kotlin package class", "hint": "Can\u0027t rename kotlin package class",
"classFQN": "testing.rename.RenamePackage", "classId": "testing/rename/RenamePackage",
"newName": "NewPackageName" "newName": "NewPackageName"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.RenamePackage", "classId": "testing/rename/RenamePackage",
"methodSignature": "int foo()", "methodSignature": "int foo()",
"newName": "bar" "newName": "bar"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.BP", "classId": "testing/rename/BP",
"methodSignature": "int getFirst()", "methodSignature": "int getFirst()",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_PROPERTY", "type": "KOTLIN_PROPERTY",
"classFQN": "testing.rename.AP", "classId": "testing/rename/AP",
"oldName": "first", "oldName": "first",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_PROPERTY", "type": "KOTLIN_PROPERTY",
"classFQN": "testing.rename.CP", "classId": "testing/rename/CP",
"oldName": "first", "oldName": "first",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.AP", "classId": "testing/rename/AP",
"methodSignature": "int getFirst()", "methodSignature": "int getFirst()",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "JAVA_METHOD", "type": "JAVA_METHOD",
"classFQN": "testing.rename.AP", "classId": "testing/rename/AP",
"methodSignature": "void setFirst(int value)", "methodSignature": "void setFirst(int value)",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_PROPERTY", "type": "KOTLIN_PROPERTY",
"classFQN": "testing.rename.AP", "classId": "testing/rename/AP",
"oldName": "first", "oldName": "first",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_PROPERTY", "type": "KOTLIN_PROPERTY",
"classFQN": "testing.rename.BP", "classId": "testing/rename/BP",
"oldName": "first", "oldName": "first",
"newName": "second" "newName": "second"
} }
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "plus", "oldName": "plus",
"newName": "foo", "newName": "foo",
"mainFile": "plus.kt" "mainFile": "plus.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "plusAssign", "oldName": "plusAssign",
"newName": "foo", "newName": "foo",
"mainFile": "plusAssign.kt" "mainFile": "plusAssign.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "set", "oldName": "set",
"newName": "foo", "newName": "foo",
"mainFile": "set.kt" "mainFile": "set.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_PROPERTY", "type": "KOTLIN_PROPERTY",
"classFQN": "A", "classId": "/A",
"oldName": "n", "oldName": "n",
"newName": "foo", "newName": "foo",
"mainFile": "synthesizedComponentFunction.kt" "mainFile": "synthesizedComponentFunction.kt"
@@ -1,6 +1,6 @@
{ {
"type": "KOTLIN_FUNCTION", "type": "KOTLIN_FUNCTION",
"classFQN": "A", "classId": "/A",
"oldName": "minus", "oldName": "minus",
"newName": "foo", "newName": "foo",
"mainFile": "unaryMinus.kt" "mainFile": "unaryMinus.kt"
@@ -34,11 +34,8 @@ import com.intellij.psi.JavaPsiFacade
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import java.util.Collections import java.util.Collections
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.isSubpackageOf
import org.jetbrains.kotlin.idea.refactoring.move.getString import org.jetbrains.kotlin.idea.refactoring.move.getString
import org.jetbrains.kotlin.idea.refactoring.move.getNullableString import org.jetbrains.kotlin.idea.refactoring.move.getNullableString
import org.jetbrains.kotlin.idea.search.allScope import org.jetbrains.kotlin.idea.search.allScope
@@ -47,8 +44,9 @@ import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsExcepti
import com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException import com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException
import org.jetbrains.kotlin.idea.KotlinMultiFileTestCase import org.jetbrains.kotlin.idea.KotlinMultiFileTestCase
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
private enum class RenameType { private enum class RenameType {
JAVA_CLASS JAVA_CLASS
@@ -105,7 +103,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
} }
private fun renameJavaClassTest(renameParamsObject: JsonObject, context: TestContext) { private fun renameJavaClassTest(renameParamsObject: JsonObject, context: TestContext) {
val classFQN = renameParamsObject.getString("classFQN") val classFQN = ClassId.fromString(renameParamsObject.getString("classId")).asSingleFqName().asString()
val newName = renameParamsObject.getString("newName") val newName = renameParamsObject.getString("newName")
doTestCommittingDocuments { rootDir, rootAfter -> doTestCommittingDocuments { rootDir, rootAfter ->
@@ -117,7 +115,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
} }
private fun renameJavaMethodTest(renameParamsObject: JsonObject, context: TestContext) { private fun renameJavaMethodTest(renameParamsObject: JsonObject, context: TestContext) {
val classFQN = renameParamsObject.getString("classFQN") val classFQN = ClassId.fromString(renameParamsObject.getString("classId")).asSingleFqName().asString()
val methodSignature = renameParamsObject.getString("methodSignature") val methodSignature = renameParamsObject.getString("methodSignature")
val newName = renameParamsObject.getString("newName") val newName = renameParamsObject.getString("newName")
@@ -182,7 +180,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
private fun doRenameInKotlinClass( private fun doRenameInKotlinClass(
renameParamsObject: JsonObject, context: TestContext, findDescriptorToRename: (ClassDescriptor) -> DeclarationDescriptor renameParamsObject: JsonObject, context: TestContext, findDescriptorToRename: (ClassDescriptor) -> DeclarationDescriptor
) { ) {
val classFqName = FqName(renameParamsObject.getString("classFQN")) val classId = ClassId.fromString(renameParamsObject.getString("classId"))
val newName = renameParamsObject.getString("newName") val newName = renameParamsObject.getString("newName")
val mainFilePath = renameParamsObject.getNullableString("mainFile") ?: "${getTestDirName(false)}.kt" val mainFilePath = renameParamsObject.getNullableString("mainFile") ?: "${getTestDirName(false)}.kt"
@@ -192,7 +190,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
val jetFile = PsiDocumentManager.getInstance(context.project).getPsiFile(document) as JetFile val jetFile = PsiDocumentManager.getInstance(context.project).getPsiFile(document) as JetFile
val module = jetFile.analyzeFullyAndGetResult().moduleDescriptor val module = jetFile.analyzeFullyAndGetResult().moduleDescriptor
val classDescriptor = module.resolveTopLevelClass(classFqName)!! val classDescriptor = module.findClassAcrossModuleDependencies(classId)!!
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(findDescriptorToRename(classDescriptor))!! val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(findDescriptorToRename(classDescriptor))!!