Change Signature: Fix processing of enum constructors
#KT-7170 Fixed
This commit is contained in:
@@ -122,6 +122,11 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
|
||||
return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getColon() {
|
||||
return findChildByType(JetTokens.COLON);
|
||||
}
|
||||
|
||||
public List<JetProperty> getProperties() {
|
||||
JetClassBody body = getBody();
|
||||
if (body == null) return Collections.emptyList();
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
|
||||
if (functionPsi instanceof JetClass && ((JetClass) functionPsi).isEnum()) {
|
||||
for (JetDeclaration declaration : ((JetClass) functionPsi).getDeclarations()) {
|
||||
if (declaration instanceof JetEnumEntry && ((JetEnumEntry) declaration).getDelegationSpecifierList() == null) {
|
||||
if (declaration instanceof JetEnumEntry && ((JetEnumEntry) declaration).getDelegationSpecifiers().isEmpty()) {
|
||||
result.add(new JetEnumEntryWithoutSuperCallUsage((JetEnumEntry) declaration));
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.refactoring.changeSignature.usages;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -69,6 +70,16 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
}
|
||||
}
|
||||
|
||||
if (changeInfo.getNewParametersCount() == 0
|
||||
&& element instanceof JetDelegatorToSuperCall) {
|
||||
JetEnumEntry enumEntry = PsiTreeUtil.getParentOfType(element, JetEnumEntry.class, true);
|
||||
if (enumEntry != null && enumEntry.getInitializerList() == element.getParent()) {
|
||||
PsiElement colon = enumEntry.getColon();
|
||||
JetInitializerList initializerList = enumEntry.getInitializerList();
|
||||
enumEntry.deleteChildRange(colon != null ? colon : initializerList, initializerList);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class Hi() {
|
||||
FOO
|
||||
BAR
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class <caret>Hi(a: Int, b: Int) {
|
||||
FOO : Hi(1, 2)
|
||||
BAR : Hi(3, 4)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class Hi(a: Int) {
|
||||
FOO : Hi(1)
|
||||
BAR : Hi(3)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class <caret>Hi(a: Int, b: Int) {
|
||||
FOO : Hi(1, 2)
|
||||
BAR : Hi(3, 4)
|
||||
}
|
||||
+14
@@ -826,6 +826,20 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
public void testRemoveEnumConstructorParameter() throws Exception {
|
||||
JetChangeInfo changeInfo = getChangeInfo();
|
||||
changeInfo.removeParameter(1);
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
public void testRemoveAllEnumConstructorParameters() throws Exception {
|
||||
JetChangeInfo changeInfo = getChangeInfo();
|
||||
for (int i = changeInfo.getNewParametersCount() - 1; i >= 0; i--) {
|
||||
changeInfo.removeParameter(i);
|
||||
}
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user