Change Signature: Keep parameter 'val'/'var' when invoked from Java

#KT-20901 Fixed
 #KT-21159 Fixed
This commit is contained in:
Alexey Sedunov
2017-06-26 17:42:15 +03:00
parent 820ade41ed
commit 354a6cbfd9
16 changed files with 86 additions and 5 deletions
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.keysToMap
@@ -555,11 +556,14 @@ fun ChangeInfo.toJetChangeInfo(
}
val parameterType = if (oldIndex >= 0) originalParameterDescriptors[oldIndex].type else currentType
val originalKtParameter = originalParameterDescriptors.getOrNull(oldIndex)?.source?.getPsi() as? KtParameter
val valOrVar = originalKtParameter?.valOrVarKeyword?.toValVar() ?: KotlinValVar.None
KotlinParameterInfo(callableDescriptor = functionDescriptor,
originalIndex = oldIndex,
name = info.name,
originalTypeInfo = KotlinTypeInfo(false, parameterType),
defaultValueForCall = defaultValueExpr).apply {
defaultValueForCall = defaultValueExpr,
valOrVar = valOrVar).apply {
currentTypeInfo = KotlinTypeInfo(false, currentType)
}
}
@@ -0,0 +1 @@
class Foo(i: Int, val n: Int)
@@ -0,0 +1,7 @@
// "Add 'int' as 1st parameter to method 'Foo'" "true"
public class J {
void test() {
new Foo(<caret>1, 2);
}
}
@@ -0,0 +1 @@
class Foo(val n: Int)
@@ -0,0 +1,7 @@
// "Add 'int' as 1st parameter to method 'Foo'" "true"
public class J {
void test() {
new Foo(<caret>1, 2);
}
}
@@ -0,0 +1 @@
class Foo(val n: Int, i: Int)
@@ -0,0 +1,7 @@
// "Add 'int' as 2nd parameter to method 'Foo'" "true"
public class J {
void test() {
new Foo(<caret>1, 2);
}
}
@@ -0,0 +1 @@
class Foo(val n: Int)
@@ -0,0 +1,7 @@
// "Add 'int' as 2nd parameter to method 'Foo'" "true"
public class J {
void test() {
new Foo(<caret>1, 2);
}
}
@@ -0,0 +1,3 @@
class K(private val a: Int, val b: Int) {
override fun toString(): String = b.toString()
}
@@ -0,0 +1,7 @@
// "Change 1st parameter of method 'K' from 'String' to 'int'" "true"
public class J {
void foo() {
new K<caret>(1, 2);
}
}
@@ -0,0 +1,3 @@
class K(private val a: String, val b: Int) {
override fun toString(): String = b.toString()
}
@@ -0,0 +1,7 @@
// "Change 1st parameter of method 'K' from 'String' to 'int'" "true"
public class J {
void foo() {
new K<caret>(1, 2);
}
}
@@ -5,12 +5,18 @@ fun <caret>foo(a: Int, b: Int, d: Int, c: Int, e: Int) {
fun test() {
foo(1,
2,
4, 3, 5)
4,
3,
5)
foo(1, 2,
4, 3, 5)
4,
3,
5)
foo(
1,
2,
4, 3, 5
4,
3,
5
)
}
@@ -1,6 +1,7 @@
fun foo(
n: Int, s: String,
a: Any, l: Long
a: Any,
l: Long
) {
}
@@ -835,6 +835,24 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
doTestWithExtraFile(fileName);
}
@TestMetadata("jkKeepValOnAddingParameter1.before.Main.java")
public void testJkKeepValOnAddingParameter1() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/jk/jkKeepValOnAddingParameter1.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("jkKeepValOnAddingParameter2.before.Main.java")
public void testJkKeepValOnAddingParameter2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/jk/jkKeepValOnAddingParameter2.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("jkKeepValOnParameterTypeChange.before.Main.java")
public void testJkKeepValOnParameterTypeChange() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/jk/jkKeepValOnParameterTypeChange.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("jkRemoveFunctionParameter.before.Main.java")
public void testJkRemoveFunctionParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/jk/jkRemoveFunctionParameter.before.Main.java");