Test for renaming file name after class rename
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
class ClassAfter
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
class ClassBefore
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// RENAME: JAVA_CLASS->testing.ClassBefore->ClassAfter
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// RENAME: KOTLIN_CLASS->testing.ClassBefore->ClassAfter
|
||||||
|
// FILE: ClassBefore.kt
|
||||||
@@ -31,6 +31,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
|
|||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
@@ -70,6 +71,8 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
|
|
||||||
String hintDirective = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// HINT:");
|
String hintDirective = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// HINT:");
|
||||||
|
|
||||||
|
String mainFile = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// FILE:");
|
||||||
|
|
||||||
String renameTypeStr = strings[0];
|
String renameTypeStr = strings[0];
|
||||||
RenameType type = RenameType.valueOf(renameTypeStr);
|
RenameType type = RenameType.valueOf(renameTypeStr);
|
||||||
|
|
||||||
@@ -84,13 +87,13 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
renameJavaMethodTest(fqNameUnsafe.asString(), strings[2], strings[3]);
|
renameJavaMethodTest(fqNameUnsafe.asString(), strings[2], strings[3]);
|
||||||
break;
|
break;
|
||||||
case KOTLIN_CLASS:
|
case KOTLIN_CLASS:
|
||||||
renameKotlinClassTest(fqNameUnsafe.toSafe(), strings[2]);
|
renameKotlinClassTest(fqNameUnsafe.toSafe(), strings[2], mainFile);
|
||||||
break;
|
break;
|
||||||
case KOTLIN_FUNCTION:
|
case KOTLIN_FUNCTION:
|
||||||
renameKotlinFunctionTest(fqNameUnsafe.parent().toSafe(), fqNameUnsafe.shortName().asString(), strings[2]);
|
renameKotlinFunctionTest(fqNameUnsafe.parent().toSafe(), fqNameUnsafe.shortName().asString(), strings[2], mainFile);
|
||||||
break;
|
break;
|
||||||
case KOTLIN_PROPERTY:
|
case KOTLIN_PROPERTY:
|
||||||
renameKotlinPropertyTest(fqNameUnsafe.parent().toSafe(), fqNameUnsafe.shortName().asString(), strings[2]);
|
renameKotlinPropertyTest(fqNameUnsafe.parent().toSafe(), fqNameUnsafe.shortName().asString(), strings[2], mainFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +156,7 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameKotlinFunctionTest(final FqName qClassName, final String oldMethodName, String newMethodName) throws Exception {
|
private void renameKotlinFunctionTest(final FqName qClassName, final String oldMethodName, String newMethodName, String mainFile) throws Exception {
|
||||||
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiElement fun(PsiFile file) {
|
public PsiElement fun(PsiFile file) {
|
||||||
@@ -166,10 +169,10 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
FunctionDescriptor methodDescriptor = scope.getFunctions(Name.identifier(oldMethodName)).iterator().next();
|
FunctionDescriptor methodDescriptor = scope.getFunctions(Name.identifier(oldMethodName)).iterator().next();
|
||||||
return BindingContextUtils.callableDescriptorToDeclaration(bindingContext, methodDescriptor);
|
return BindingContextUtils.callableDescriptorToDeclaration(bindingContext, methodDescriptor);
|
||||||
}
|
}
|
||||||
}, newMethodName);
|
}, newMethodName, mainFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameKotlinPropertyTest(final FqName qClassName, final String oldPropertyName, String newPropertyName) throws Exception {
|
private void renameKotlinPropertyTest(final FqName qClassName, final String oldPropertyName, String newPropertyName, String mainFile) throws Exception {
|
||||||
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiElement fun(PsiFile file) {
|
public PsiElement fun(PsiFile file) {
|
||||||
@@ -181,10 +184,10 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
VariableDescriptor propertyName = scope.getProperties(Name.identifier(oldPropertyName)).iterator().next();
|
VariableDescriptor propertyName = scope.getProperties(Name.identifier(oldPropertyName)).iterator().next();
|
||||||
return BindingContextUtils.descriptorToDeclaration(bindingContext, propertyName);
|
return BindingContextUtils.descriptorToDeclaration(bindingContext, propertyName);
|
||||||
}
|
}
|
||||||
}, newPropertyName);
|
}, newPropertyName, mainFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameKotlinClassTest(@NonNls final FqName qClassName, @NonNls String newName) throws Exception {
|
private void renameKotlinClassTest(@NonNls final FqName qClassName, @NonNls String newName, String mainFile) throws Exception {
|
||||||
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
doTestWithKotlinRename(new Function<PsiFile, PsiElement>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiElement fun(PsiFile file) {
|
public PsiElement fun(PsiFile file) {
|
||||||
@@ -196,14 +199,18 @@ public abstract class AbstractRenameTest extends MultiFileTestCase {
|
|||||||
|
|
||||||
return BindingContextUtils.classDescriptorToDeclaration(bindingContext, classDescriptor);
|
return BindingContextUtils.classDescriptorToDeclaration(bindingContext, classDescriptor);
|
||||||
}
|
}
|
||||||
}, newName);
|
}, newName, mainFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestWithKotlinRename(@NonNls final Function<PsiFile, PsiElement> elementToRenameCallback, final @NonNls String newName) throws Exception {
|
private void doTestWithKotlinRename(
|
||||||
|
@NonNls final Function<PsiFile, PsiElement> elementToRenameCallback,
|
||||||
|
@NonNls final String newName,
|
||||||
|
@Nullable final String mainFile
|
||||||
|
) throws Exception {
|
||||||
doTest(new MultiFileTestCase.PerformAction() {
|
doTest(new MultiFileTestCase.PerformAction() {
|
||||||
@Override
|
@Override
|
||||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||||
VirtualFile child = rootDir.findChild(getTestDirName(false) + ".kt");
|
VirtualFile child = rootDir.findChild(mainFile == null ? (getTestDirName(false) + ".kt") : mainFile);
|
||||||
assertNotNull(child);
|
assertNotNull(child);
|
||||||
|
|
||||||
Document document = FileDocumentManager.getInstance().getDocument(child);
|
Document document = FileDocumentManager.getInstance().getDocument(child);
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ import org.jetbrains.jet.plugin.refactoring.rename.AbstractRenameTest;
|
|||||||
@TestMetadata("idea/testData/refactoring/rename")
|
@TestMetadata("idea/testData/refactoring/rename")
|
||||||
public class RenameTestGenerated extends AbstractRenameTest {
|
public class RenameTestGenerated extends AbstractRenameTest {
|
||||||
public void testAllFilesPresentInRename() throws Exception {
|
public void testAllFilesPresentInRename() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests",
|
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/refactoring/rename"), Pattern.compile("^(.+)\\.test$"));
|
||||||
new File("idea/testData/refactoring/rename"),
|
|
||||||
Pattern.compile("^(.+)\\.test$"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("renameJavaClass/renameJavaClass.test")
|
@TestMetadata("renameJavaClass/renameJavaClass.test")
|
||||||
@@ -78,6 +76,16 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest("idea/testData/refactoring/rename/renameKotlinClassConstructor/renameKotlinConstructor.test");
|
doTest("idea/testData/refactoring/rename/renameKotlinClassConstructor/renameKotlinConstructor.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameKotlinClassWithFile/javaClassWrapper.test")
|
||||||
|
public void testRenameKotlinClassWithFile_JavaClassWrapper() throws Exception {
|
||||||
|
doTest("idea/testData/refactoring/rename/renameKotlinClassWithFile/javaClassWrapper.test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameKotlinClassWithFile/kotlinClass.test")
|
||||||
|
public void testRenameKotlinClassWithFile_KotlinClass() throws Exception {
|
||||||
|
doTest("idea/testData/refactoring/rename/renameKotlinClassWithFile/kotlinClass.test");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("renameKotlinMethod/javaWrapperForKotlinMethod.test")
|
@TestMetadata("renameKotlinMethod/javaWrapperForKotlinMethod.test")
|
||||||
public void testRenameKotlinMethod_JavaWrapperForKotlinMethod() throws Exception {
|
public void testRenameKotlinMethod_JavaWrapperForKotlinMethod() throws Exception {
|
||||||
doTest("idea/testData/refactoring/rename/renameKotlinMethod/javaWrapperForKotlinMethod.test");
|
doTest("idea/testData/refactoring/rename/renameKotlinMethod/javaWrapperForKotlinMethod.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user