Quick Fixes: Fix adding parameter to Java constructor
#KT-24574 In Progress
This commit is contained in:
@@ -264,9 +264,8 @@ open class KotlinChangeInfo(
|
|||||||
}
|
}
|
||||||
buffer.append('.')
|
buffer.append('.')
|
||||||
}
|
}
|
||||||
|
buffer.append(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(getNewParametersSignature(inheritedCallable))
|
buffer.append(getNewParametersSignature(inheritedCallable))
|
||||||
|
|||||||
+3
-2
@@ -153,16 +153,17 @@ class KotlinChangeSignature(
|
|||||||
// Generate new Java method signature from the Kotlin point of view
|
// Generate new Java method signature from the Kotlin point of view
|
||||||
val ktChangeInfo = KotlinChangeInfo(methodDescriptor = descriptor, context = defaultValueContext)
|
val ktChangeInfo = KotlinChangeInfo(methodDescriptor = descriptor, context = defaultValueContext)
|
||||||
val ktSignature = ktChangeInfo.getNewSignature(descriptor.originalPrimaryCallable)
|
val ktSignature = ktChangeInfo.getNewSignature(descriptor.originalPrimaryCallable)
|
||||||
|
val previewClassName = if (originalMethod.isConstructor) originalMethod.name else "Dummy"
|
||||||
val dummyFileText = with(StringBuilder()) {
|
val dummyFileText = with(StringBuilder()) {
|
||||||
contextFile.packageDirective?.let { append(it.text).append("\n") }
|
contextFile.packageDirective?.let { append(it.text).append("\n") }
|
||||||
append("class Dummy {\n").append(ktSignature).append("{}\n}")
|
append("class $previewClassName {\n").append(ktSignature).append("{}\n}")
|
||||||
toString()
|
toString()
|
||||||
}
|
}
|
||||||
val dummyFile = KtPsiFactory(project).createFileWithLightClassSupport("dummy.kt", dummyFileText, originalMethod)
|
val dummyFile = KtPsiFactory(project).createFileWithLightClassSupport("dummy.kt", dummyFileText, originalMethod)
|
||||||
val dummyDeclaration = (dummyFile.declarations.first() as KtClass).getBody()!!.declarations.first()
|
val dummyDeclaration = (dummyFile.declarations.first() as KtClass).getBody()!!.declarations.first()
|
||||||
|
|
||||||
// Convert to PsiMethod which can be used in Change Signature dialog
|
// Convert to PsiMethod which can be used in Change Signature dialog
|
||||||
val containingClass = PsiElementFactory.SERVICE.getInstance(project).createClass("Dummy")
|
val containingClass = PsiElementFactory.SERVICE.getInstance(project).createClass(previewClassName)
|
||||||
val preview = createJavaMethod(dummyDeclaration.getRepresentativeLightMethod()!!, containingClass)
|
val preview = createJavaMethod(dummyDeclaration.getRepresentativeLightMethod()!!, containingClass)
|
||||||
|
|
||||||
// Create JavaChangeInfo based on new signature
|
// Create JavaChangeInfo based on new signature
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
Foo(int n, String s, Set<String> of) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add parameter to constructor 'Foo'" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
private val foo = Foo(1, "2", <caret>setOf("3"))
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo {
|
||||||
|
Foo(int n, String s) {}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add parameter to constructor 'Foo'" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
private val foo = Foo(1, "2", <caret>setOf("3"))
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
void bar(int n, String s, Set<String> of) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add parameter to function 'bar'" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
private val foo = Foo().bar(1, "2", <caret>setOf("3"))
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo {
|
||||||
|
void bar(int n, String s) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Add parameter to function 'bar'" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
private val foo = Foo().bar(1, "2", <caret>setOf("3"))
|
||||||
+23
@@ -1100,6 +1100,29 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
runTest("idea/testData/quickfix/changeSignature/jk/jkRemoveSecondaryConstructorParameter.before.Main.java");
|
runTest("idea/testData/quickfix/changeSignature/jk/jkRemoveSecondaryConstructorParameter.before.Main.java");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/changeSignature/kj")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Kj extends AbstractQuickFixMultiFileTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addConstructorParameter.before.Main.kt")
|
||||||
|
public void testAddConstructorParameter() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/changeSignature/kj/addConstructorParameter.before.Main.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addMethodParameter.before.Main.kt")
|
||||||
|
public void testAddMethodParameter() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/changeSignature/kj/addMethodParameter.before.Main.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInKj() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/changeSignature/kj"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/changeToLabeledReturn")
|
@TestMetadata("idea/testData/quickfix/changeToLabeledReturn")
|
||||||
|
|||||||
@@ -1695,6 +1695,19 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/changeSignature/jk"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/changeSignature/jk"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/changeSignature/kj")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Kj extends AbstractQuickFixTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInKj() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/changeSignature/kj"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/changeToLabeledReturn")
|
@TestMetadata("idea/testData/quickfix/changeToLabeledReturn")
|
||||||
|
|||||||
Reference in New Issue
Block a user