Finding class by class id instead of fq name in rename tests.
This commit is contained in:
@@ -108,4 +108,15 @@ public final class ClassId {
|
||||
if (packageFqName.isRoot()) return "/" + 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",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "compareTo",
|
||||
"newName": "foo",
|
||||
"mainFile": "compareTo.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "contains",
|
||||
"newName": "foo",
|
||||
"mainFile": "contains.kt"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "contains",
|
||||
"newName": "foo",
|
||||
"mainFile": "containsWithConflicts.kt",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "equals",
|
||||
"newName": "foo",
|
||||
"mainFile": "equals.kt"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "component1",
|
||||
"newName": "foo",
|
||||
"mainFile": "explicitComponentFunction.kt",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "get",
|
||||
"newName": "foo",
|
||||
"mainFile": "get.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "inc",
|
||||
"newName": "foo",
|
||||
"mainFile": "inc.kt",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "invoke",
|
||||
"newName": "foo",
|
||||
"mainFile": "invoke.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "iterator",
|
||||
"newName": "foo",
|
||||
"mainFile": "iterator.kt",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "JAVA_CLASS",
|
||||
"classFQN": "testing.SomeClass",
|
||||
"classId": "testing/SomeClass",
|
||||
"newName": "NewName"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_CLASS",
|
||||
"classFQN": "testing.SomeInterface",
|
||||
"classId": "testing/SomeInterface",
|
||||
"newName": "NewInterfaceName",
|
||||
"comment": "For KT-4100 Imports doesn't change after java interface name refactoring"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.JavaClass",
|
||||
"classId": "testing/JavaClass",
|
||||
"methodSignature": "String foo()",
|
||||
"newName": "bar"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "testing.kotlin.KotlinClass",
|
||||
"classId": "testing/kotlin/KotlinClass",
|
||||
"oldName": "foo",
|
||||
"newName": "bar",
|
||||
"mainFile": "MethodUsages.kt"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.A",
|
||||
"classId": "testing/rename/A",
|
||||
"methodSignature": "void first()",
|
||||
"newName": "second"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.JavaClient.D",
|
||||
"classId": "testing/JavaClient.D",
|
||||
"methodSignature": "void first()",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "testing.rename.A",
|
||||
"classId": "testing/rename/A",
|
||||
"oldName": "first",
|
||||
"newName": "second",
|
||||
"comment": "KT-2836 Rename method with all its implementations"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "JAVA_CLASS",
|
||||
"classFQN": "testing.rename.First",
|
||||
"classId": "testing/rename/First",
|
||||
"newName": "Third"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classFQN": "testing.rename.First",
|
||||
"classId": "testing/rename/First",
|
||||
"newName": "Third"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classFQN": "X",
|
||||
"classId": "/X",
|
||||
"newName": "TestX"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "JAVA_CLASS",
|
||||
"classFQN": "testing.ClassBefore",
|
||||
"classId": "testing/ClassBefore",
|
||||
"newName": "ClassAfter"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classFQN": "testing.ClassBefore",
|
||||
"classId": "testing/ClassBefore",
|
||||
"newName": "ClassAfter",
|
||||
"mainFile": "ClassBefore.kt"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classFQN": "test.E",
|
||||
"classId": "test/E",
|
||||
"newName": "D"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "test.E",
|
||||
"classId": "test/E",
|
||||
"oldName": "foo",
|
||||
"newName": "bar"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.C",
|
||||
"classId": "testing/rename/C",
|
||||
"methodSignature": "int first()",
|
||||
"newName": "second",
|
||||
"comment": "KT-3256 Can't rename a Kotlin function from Java code"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "testing.rename.C",
|
||||
"classId": "testing/rename/C",
|
||||
"oldName": "first",
|
||||
"newName": "second"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_CLASS",
|
||||
"hint": "Can\u0027t rename kotlin package class",
|
||||
"classFQN": "testing.rename.RenamePackage",
|
||||
"classId": "testing/rename/RenamePackage",
|
||||
"newName": "NewPackageName"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.RenamePackage",
|
||||
"classId": "testing/rename/RenamePackage",
|
||||
"methodSignature": "int foo()",
|
||||
"newName": "bar"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.BP",
|
||||
"classId": "testing/rename/BP",
|
||||
"methodSignature": "int getFirst()",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_PROPERTY",
|
||||
"classFQN": "testing.rename.AP",
|
||||
"classId": "testing/rename/AP",
|
||||
"oldName": "first",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_PROPERTY",
|
||||
"classFQN": "testing.rename.CP",
|
||||
"classId": "testing/rename/CP",
|
||||
"oldName": "first",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.AP",
|
||||
"classId": "testing/rename/AP",
|
||||
"methodSignature": "int getFirst()",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "JAVA_METHOD",
|
||||
"classFQN": "testing.rename.AP",
|
||||
"classId": "testing/rename/AP",
|
||||
"methodSignature": "void setFirst(int value)",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_PROPERTY",
|
||||
"classFQN": "testing.rename.AP",
|
||||
"classId": "testing/rename/AP",
|
||||
"oldName": "first",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_PROPERTY",
|
||||
"classFQN": "testing.rename.BP",
|
||||
"classId": "testing/rename/BP",
|
||||
"oldName": "first",
|
||||
"newName": "second"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "plus",
|
||||
"newName": "foo",
|
||||
"mainFile": "plus.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "plusAssign",
|
||||
"newName": "foo",
|
||||
"mainFile": "plusAssign.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "set",
|
||||
"newName": "foo",
|
||||
"mainFile": "set.kt"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_PROPERTY",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "n",
|
||||
"newName": "foo",
|
||||
"mainFile": "synthesizedComponentFunction.kt"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classFQN": "A",
|
||||
"classId": "/A",
|
||||
"oldName": "minus",
|
||||
"newName": "foo",
|
||||
"mainFile": "unaryMinus.kt"
|
||||
|
||||
@@ -34,11 +34,8 @@ import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.module.Module
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
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.getNullableString
|
||||
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 org.jetbrains.kotlin.idea.KotlinMultiFileTestCase
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
||||
import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
|
||||
private enum class RenameType {
|
||||
JAVA_CLASS
|
||||
@@ -105,7 +103,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
doTestCommittingDocuments { rootDir, rootAfter ->
|
||||
@@ -117,7 +115,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
||||
}
|
||||
|
||||
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 newName = renameParamsObject.getString("newName")
|
||||
|
||||
@@ -182,7 +180,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
||||
private fun doRenameInKotlinClass(
|
||||
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 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 module = jetFile.analyzeFullyAndGetResult().moduleDescriptor
|
||||
val classDescriptor = module.resolveTopLevelClass(classFqName)!!
|
||||
val classDescriptor = module.findClassAcrossModuleDependencies(classId)!!
|
||||
|
||||
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(findDescriptorToRename(classDescriptor))!!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user