Add "Remove argument" quick fix for TOO_MANY_ARGUMENTS
#KT-34026 Fixed #KT-34332 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
13afb2e45e
commit
d54a35ef56
@@ -640,5 +640,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
|
||||
|
||||
MUST_BE_INITIALIZED.registerFactory(ChangeVariableMutabilityFix.MUST_BE_INITIALIZED_FACTORY)
|
||||
|
||||
TOO_MANY_ARGUMENTS.registerFactory(RemoveArgumentFix)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtLambdaArgument
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||
|
||||
class RemoveArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction<KtValueArgument>(argument) {
|
||||
override fun getText(): String = "Remove argument"
|
||||
|
||||
override fun getFamilyName(): String = text
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
val argument = element ?: return
|
||||
if (argument is KtLambdaArgument) {
|
||||
argument.delete()
|
||||
} else {
|
||||
(argument.parent as? KtValueArgumentList)?.removeArgument(argument)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtValueArgument>? {
|
||||
val argument = diagnostic.psiElement.parent as? KtValueArgument ?: return null
|
||||
return RemoveArgumentFix(argument)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -4,6 +4,7 @@
|
||||
// ACTION: Create secondary constructor
|
||||
// ERROR: Too many arguments for public constructor Foo(a: Int) defined in Foo
|
||||
// ACTION: Put arguments on separate lines
|
||||
// ACTION: Remove argument
|
||||
// ACTION: To raw string literal
|
||||
|
||||
class Foo(a: Int)
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
// "Create secondary constructor" "false"
|
||||
// ACTION: Add parameter to constructor 'A'
|
||||
// ACTION: Create function 'A'
|
||||
// ACTION: Remove argument
|
||||
// ERROR: No type arguments expected for constructor A()
|
||||
// ERROR: Too many arguments for public constructor A() defined in A
|
||||
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
// "Create secondary constructor" "false"
|
||||
// ERROR: Too many arguments for public constructor Any() defined in kotlin.Any
|
||||
// WITH_RUNTIME
|
||||
// ACTION: Remove argument
|
||||
|
||||
interface T {
|
||||
|
||||
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
// ACTION: Add parameter to constructor 'A'
|
||||
// ACTION: Change type of 'b' to 'A'
|
||||
// ACTION: Create function 'A'
|
||||
// ACTION: Remove argument
|
||||
// ERROR: Type mismatch: inferred type is A but B was expected
|
||||
// ERROR: Too many arguments for public constructor A() defined in A
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1, "2"<caret>)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1)
|
||||
b.foo("a", 1<caret>)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1)
|
||||
b.foo("a")
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1)
|
||||
b.foo("a") {}<caret>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove argument" "true"
|
||||
class Bar(s: String, i: Int) {
|
||||
fun foo(s: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar("2", 1)
|
||||
b.foo("a")
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Remove argument" "false"
|
||||
// ACTION: Add 'i =' to argument
|
||||
// ACTION: Convert to also
|
||||
// ACTION: Convert to apply
|
||||
// ACTION: Convert to run
|
||||
// ACTION: Convert to with
|
||||
// ACTION: Put arguments on separate lines
|
||||
class Bar() {
|
||||
fun foo(s: String, i: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar()
|
||||
b.foo("a", 1<caret>)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// "Remove argument" "false"
|
||||
// ACTION: Add 'toString()' call
|
||||
// ACTION: Change parameter 't' type of function 'foo' to 'Int'
|
||||
// ACTION: Convert to also
|
||||
// ACTION: Convert to apply
|
||||
// ACTION: Convert to run
|
||||
// ACTION: Convert to with
|
||||
// ACTION: Put arguments on separate lines
|
||||
// ERROR: The integer literal does not conform to the expected type String
|
||||
class Bar() {
|
||||
fun foo(s: String, vararg t: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val b = Bar()
|
||||
b.foo("a", "b", 1<caret>)
|
||||
}
|
||||
+13
@@ -3723,6 +3723,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/removeArgument")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class RemoveArgument extends AbstractQuickFixMultiFileTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInRemoveArgument() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/removeArgument"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/removeAtFromAnnotationArgument")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -10358,6 +10358,44 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/removeArgument")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class RemoveArgument extends AbstractQuickFixTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInRemoveArgument() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/removeArgument"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
runTest("idea/testData/quickfix/removeArgument/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("idea/testData/quickfix/removeArgument/function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaArgument.kt")
|
||||
public void testLambdaArgument() throws Exception {
|
||||
runTest("idea/testData/quickfix/removeArgument/lambdaArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("matchedArguments.kt")
|
||||
public void testMatchedArguments() throws Exception {
|
||||
runTest("idea/testData/quickfix/removeArgument/matchedArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeMismatch.kt")
|
||||
public void testTypeMismatch() throws Exception {
|
||||
runTest("idea/testData/quickfix/removeArgument/typeMismatch.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/removeAtFromAnnotationArgument")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user