Support class rename in place of secondary ctor call
This commit is contained in:
committed by
Alexey Sedunov
parent
4b564fcc51
commit
25de64c6ab
+2
-1
@@ -548,7 +548,8 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException("Cannot modify compiled kotlin element");
|
||||
getOrigin().setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.refactoring.rename;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,15 +28,17 @@ import org.jetbrains.kotlin.asJava.KotlinLightClass;
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetSecondaryConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class RenameJetClassProcessor extends RenameKotlinPsiProcessor {
|
||||
@Override
|
||||
public boolean canProcessElement(@NotNull PsiElement element) {
|
||||
return element instanceof JetClassOrObject || element instanceof KotlinLightClass;
|
||||
return element instanceof JetClassOrObject || element instanceof KotlinLightClass || element instanceof JetSecondaryConstructor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -83,6 +86,9 @@ public class RenameJetClassProcessor extends RenameKotlinPsiProcessor {
|
||||
assert false : "Should not be suggested to rename element of type " + element.getClass() + " " + element;
|
||||
}
|
||||
}
|
||||
else if (element instanceof JetSecondaryConstructor) {
|
||||
return PsiTreeUtil.getParentOfType(element, JetClassOrObject.class);
|
||||
}
|
||||
|
||||
return (JetClassOrObject) element;
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
open class TestX {
|
||||
constructor(x: Int) {}
|
||||
}
|
||||
|
||||
class Y1 : TestX(1)
|
||||
class Y2 : TestX {
|
||||
constructor(): super(1) {}
|
||||
}
|
||||
|
||||
val x = TestX(1)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
open class X {
|
||||
constructor(x: Int) {}
|
||||
}
|
||||
|
||||
class Y1 : X(1)
|
||||
class Y2 : X {
|
||||
constructor(): super(1) {}
|
||||
}
|
||||
|
||||
val x = X(1)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classId": "/X",
|
||||
"newName": "TestX"
|
||||
}
|
||||
@@ -162,6 +162,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinClassSecondaryConstructor/renameKotlinSecondaryConstructor.test")
|
||||
public void testRenameKotlinClassSecondaryConstructor_RenameKotlinSecondaryConstructor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinClassSecondaryConstructor/renameKotlinSecondaryConstructor.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinClassWithFile/javaClassWrapper.test")
|
||||
public void testRenameKotlinClassWithFile_JavaClassWrapper() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinClassWithFile/javaClassWrapper.test");
|
||||
|
||||
Reference in New Issue
Block a user