Change Signature: Update enum entries w/o delegation specifier when changing signature of enum class constructor
#KT-5978 Fixed
This commit is contained in:
@@ -332,6 +332,10 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return createArgumentWithName(null, argumentExpression)
|
||||
}
|
||||
|
||||
public fun createDelegatorToSuperCall(text: String): JetDelegatorToSuperCall {
|
||||
return createClass("class A: $text").getDelegationSpecifiers().first() as JetDelegatorToSuperCall
|
||||
}
|
||||
|
||||
public inner class IfChainBuilder() {
|
||||
private val sb = StringBuilder()
|
||||
private var first = true
|
||||
|
||||
+9
-4
@@ -42,10 +42,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionCallUsage;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionDefinitionUsage;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetParameterUsage;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetUsageInfo;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.*;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.List;
|
||||
@@ -123,6 +120,14 @@ 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) {
|
||||
result.add(new JetEnumEntryWithoutSuperCallUsage((JetEnumEntry) declaration));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.refactoring.changeSignature.usages
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall
|
||||
|
||||
public class JetEnumEntryWithoutSuperCallUsage(enumEntry: JetEnumEntry) : JetUsageInfo<JetEnumEntry>(enumEntry) {
|
||||
override fun processUsage(changeInfo: JetChangeInfo, element: JetEnumEntry): Boolean {
|
||||
if (changeInfo.getNewParameters().size > 0) {
|
||||
val psiFactory = JetPsiFactory(element)
|
||||
|
||||
val enumClass = element.getParentByType(javaClass<JetClass>(), true)!!
|
||||
val delegatorToSuperCall = element.addAfter(
|
||||
psiFactory.createDelegatorToSuperCall("${enumClass.getName()}()"),
|
||||
element.getNameAsDeclaration()
|
||||
) as JetDelegatorToSuperCall
|
||||
element.addBefore(psiFactory.createColon(), delegatorToSuperCall)
|
||||
|
||||
return JetFunctionCallUsage(delegatorToSuperCall, enumClass, false).processUsage(changeInfo, delegatorToSuperCall)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
// "Create parameter 'foo'" "true"
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
|
||||
enum class E(foo: Int) {
|
||||
A
|
||||
B
|
||||
C
|
||||
A : E()
|
||||
B : E()
|
||||
C : E()
|
||||
|
||||
val t: Int = foo
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
// "Create parameter 'foo'" "true"
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
|
||||
enum class E(val foo: Int) {
|
||||
A
|
||||
B {
|
||||
A : E()
|
||||
B : E() {
|
||||
val t: Int = foo
|
||||
}
|
||||
C
|
||||
C : E()
|
||||
}
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// "Create parameter 'foo'" "true"
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
|
||||
enum class E {
|
||||
A
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// "Create parameter 'foo'" "true"
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: Missing delegation specifier 'E'
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
// ERROR: No value passed for parameter foo
|
||||
|
||||
enum class E {
|
||||
A
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class E(n: Int) {
|
||||
A : E(1)
|
||||
B : E(1)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum class <caret>E {
|
||||
A
|
||||
B
|
||||
}
|
||||
+8
@@ -287,6 +287,14 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
public void testEnumEntriesWithoutSuperCalls() throws Exception {
|
||||
JetChangeInfo changeInfo = getChangeInfo();
|
||||
JetParameterInfo newParameter = new JetParameterInfo("n", KotlinBuiltIns.getInstance().getIntType());
|
||||
newParameter.setDefaultValueText("1");
|
||||
changeInfo.addParameter(newParameter);
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user