From 9d83510af5c21572a6f066440225b63270d26561 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 23 Jun 2015 21:05:24 +0300 Subject: [PATCH] KT-7144 Intention action on an argument in a call to use named arguments form #KT-7144 Fixed --- .../org/jetbrains/kotlin/psi/JetPsiFactory.kt | 4 +- .../kotlin/idea/core/psiModificationUtils.kt | 8 +- .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 5 + idea/src/META-INF/plugin.xml | 5 + .../intentions/AddNameToArgumentIntention.kt | 74 +++++++++++++++ .../idea/quickfix/AddNameToArgumentFix.java | 3 +- .../quickfix/DeprecatedLambdaSyntaxFix.kt | 10 +- .../quickfix/DeprecatedSymbolUsageFixBase.kt | 2 +- ...aceJavaAnnotationPositionedArgumentsFix.kt | 2 +- .../intentions/addNameToArgument/.intention | 1 + .../addNameToArgument/alreadyNamed.kt | 6 ++ .../addNameToArgument/ambiguousCall.kt | 8 ++ .../functionLiteralArgument.kt | 6 ++ .../addNameToArgument/incompleteCall.kt | 7 ++ .../addNameToArgument/incompleteCall.kt.after | 7 ++ .../addNameToArgument/javaMethod.kt | 6 ++ .../intentions/addNameToArgument/notLast.kt | 6 ++ .../addNameToArgument/notResolved.kt | 5 + .../addNameToArgument/rangeForLambda1.kt | 5 + .../rangeForLambda1.kt.after | 5 + .../addNameToArgument/rangeForLambda2.kt | 5 + .../rangeForLambda2.kt.after | 5 + .../addNameToArgument/rangeForLambda3.kt | 7 ++ .../intentions/addNameToArgument/simple.kt | 5 + .../addNameToArgument/simple.kt.after | 5 + .../intentions/addNameToArgument/vararg1.kt | 5 + .../addNameToArgument/vararg1.kt.after | 5 + .../intentions/addNameToArgument/vararg2.kt | 5 + .../addNameToArgument/vararg2.kt.after | 5 + .../intentions/addNameToArgument/vararg3.kt | 7 ++ .../intentions/IntentionTestGenerated.java | 93 +++++++++++++++++++ 33 files changed, 309 insertions(+), 15 deletions(-) create mode 100644 idea/resources/intentionDescriptions/AddNameToArgumentIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/AddNameToArgumentIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/AddNameToArgumentIntention/description.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt create mode 100644 idea/testData/intentions/addNameToArgument/.intention create mode 100644 idea/testData/intentions/addNameToArgument/alreadyNamed.kt create mode 100644 idea/testData/intentions/addNameToArgument/ambiguousCall.kt create mode 100644 idea/testData/intentions/addNameToArgument/functionLiteralArgument.kt create mode 100644 idea/testData/intentions/addNameToArgument/incompleteCall.kt create mode 100644 idea/testData/intentions/addNameToArgument/incompleteCall.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/javaMethod.kt create mode 100644 idea/testData/intentions/addNameToArgument/notLast.kt create mode 100644 idea/testData/intentions/addNameToArgument/notResolved.kt create mode 100644 idea/testData/intentions/addNameToArgument/rangeForLambda1.kt create mode 100644 idea/testData/intentions/addNameToArgument/rangeForLambda1.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/rangeForLambda2.kt create mode 100644 idea/testData/intentions/addNameToArgument/rangeForLambda2.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/rangeForLambda3.kt create mode 100644 idea/testData/intentions/addNameToArgument/simple.kt create mode 100644 idea/testData/intentions/addNameToArgument/simple.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/vararg1.kt create mode 100644 idea/testData/intentions/addNameToArgument/vararg1.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/vararg2.kt create mode 100644 idea/testData/intentions/addNameToArgument/vararg2.kt.after create mode 100644 idea/testData/intentions/addNameToArgument/vararg3.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt index 2dc927c6ccf..cb1c6790cd8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt @@ -354,12 +354,12 @@ public class JetPsiFactory(private val project: Project) { createExpressionByPattern("if ($0) $1", condition, thenExpr)) as JetIfExpression } - public fun createArgument(expression: JetExpression, name: String? = null, isSpread: Boolean = false): JetValueArgument { + public fun createArgument(expression: JetExpression, name: Name? = null, isSpread: Boolean = false): JetValueArgument { val argumentList = buildByPattern({ pattern, args -> createByPattern(pattern, *args) { createCallArguments(it) } }) { appendFixedText("(") if (name != null) { - appendName(Name.identifier(name)) + appendName(name) appendFixedText("=") } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt index dbf680eca3f..9fef29ecc06 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt @@ -20,8 +20,8 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses @@ -43,10 +43,10 @@ public fun JetFunctionLiteralArgument.moveInsideParentheses(bindingContext: Bind return moveInsideParenthesesAndReplaceWith(this.getArgumentExpression(), bindingContext) } -public fun JetFunctionLiteralArgument.getFunctionLiteralArgumentName(bindingContext: BindingContext): String? { +public fun JetFunctionLiteralArgument.getFunctionLiteralArgumentName(bindingContext: BindingContext): Name? { val callExpression = getParent() as JetCallExpression val resolvedCall = callExpression.getResolvedCall(bindingContext) - return (resolvedCall?.getArgumentMapping(this) as? ArgumentMatch)?.valueParameter?.getName()?.toString() + return (resolvedCall?.getArgumentMapping(this) as? ArgumentMatch)?.valueParameter?.getName() } public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith( @@ -56,7 +56,7 @@ public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith( public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith( replacement: JetExpression, - functionLiteralArgumentName: String? + functionLiteralArgumentName: Name? ): JetCallExpression { val oldCallExpression = getParent() as JetCallExpression val newCallExpression = oldCallExpression.copy() as JetCallExpression diff --git a/idea/resources/intentionDescriptions/AddNameToArgumentIntention/after.kt.template b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/after.kt.template new file mode 100644 index 00000000000..849c0707e19 --- /dev/null +++ b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/after.kt.template @@ -0,0 +1 @@ +list.joinToString(separator = "\n") \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/AddNameToArgumentIntention/before.kt.template b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/before.kt.template new file mode 100644 index 00000000000..0db4c3c434f --- /dev/null +++ b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/before.kt.template @@ -0,0 +1 @@ +list.joinToString("\n") \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/AddNameToArgumentIntention/description.html b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/description.html new file mode 100644 index 00000000000..27583fbee74 --- /dev/null +++ b/idea/resources/intentionDescriptions/AddNameToArgumentIntention/description.html @@ -0,0 +1,5 @@ + + +This intention adds name to an argument of a function call to use named argument syntax. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index a2373e50d38..79124537eaf 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -923,6 +923,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.AddNameToArgumentIntention + Kotlin + + (javaClass(), "Use named argument"), LowPriorityAction { + + override fun isApplicableTo(element: JetValueArgument, caretOffset: Int): Boolean { + val expression = element.getArgumentExpression() ?: return false + if (detectNameToAdd(element) == null) return false + + if (expression is JetFunctionLiteralExpression) { + val range = expression.getTextRange() + return caretOffset == range.start || caretOffset == range.end + } + + return true + } + + override fun applyTo(element: JetValueArgument, editor: Editor) { + val name = detectNameToAdd(element)!! + val newArgument = JetPsiFactory(element).createArgument(element.getArgumentExpression()!!, name, element.getSpreadElement() != null) + element.replace(newArgument) + } + + private fun detectNameToAdd(argument: JetValueArgument): Name? { + if (argument.isNamed()) return null + if (argument is JetFunctionLiteralArgument) return null + + val argumentList = argument.getParent() as? JetValueArgumentList ?: return null + if (argument != argumentList.getArguments().last()) return null + + val callExpr = argumentList.getParent() as? JetExpression ?: return null + val resolvedCall = callExpr.getResolvedCall(callExpr.analyze(BodyResolveMode.PARTIAL)) ?: return null + val argumentMatch = resolvedCall.getArgumentMapping(argument) as? ArgumentMatch ?: return null + if (argumentMatch.status != ArgumentMatchStatus.SUCCESS) return null + + if (!resolvedCall.getResultingDescriptor().hasStableParameterNames()) return null + + if (argumentMatch.valueParameter.getVarargElementType() != null) { + val varargArgument = resolvedCall.getValueArguments()[argumentMatch.valueParameter] as? VarargValueArgument ?: return null + if (varargArgument.getArguments().size() != 1) return null + } + + return argumentMatch.valueParameter.getName() + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.java index 33951415721..7312f01b2e5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.java @@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.JetIcons; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; import org.jetbrains.kotlin.idea.core.CorePackage; import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil; +import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.JetCallElement; import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetFile; @@ -147,7 +148,7 @@ public class AddNameToArgumentFix extends JetIntentionAction { private static JetValueArgument getParsedArgumentWithName(@NotNull String name, @NotNull JetValueArgument argument) { JetExpression argumentExpression = argument.getArgumentExpression(); assert argumentExpression != null : "Argument should be already parsed."; - return JetPsiFactory(argument).createArgument(argumentExpression, name, false); + return JetPsiFactory(argument).createArgument(argumentExpression, Name.identifier(name), argument.getSpreadElement() != null); } @NotNull diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt index fbd791fa89d..56034bdbae8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt @@ -23,17 +23,15 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.DiagnosticUtils import org.jetbrains.kotlin.idea.JetBundle import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.core.getFunctionLiteralArgumentName +import org.jetbrains.kotlin.idea.core.moveInsideParenthesesAndReplaceWith import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ShortenReferences -import org.jetbrains.kotlin.idea.core.getFunctionLiteralArgumentName -import org.jetbrains.kotlin.idea.core.moveInsideParenthesesAndReplaceWith +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.siblings -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.utils.sure -import java.util.ArrayList public class DeprecatedLambdaSyntaxFix(element: JetFunctionLiteralExpression) : JetIntentionAction(element), CleanupFix { override fun getText() = JetBundle.message("migrate.lambda.syntax") @@ -102,7 +100,7 @@ private class DeparenthesizeParameterList( private class LambdaToFunctionExpression( val functionLiteralExpression: JetFunctionLiteralExpression ): DeprecatedSyntaxFix { - val functionLiteralArgumentName: String? + val functionLiteralArgumentName: Name? val receiverType: String? val returnType: String? diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixBase.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixBase.kt index 3e0fd5d9500..b486972817f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixBase.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixBase.kt @@ -485,7 +485,7 @@ public abstract class DeprecatedSymbolUsageFixBase( if (argument.isNamed()) continue if (argument is JetFunctionLiteralArgument) continue val argumentMatch = resolvedCall.getArgumentMapping(argument) as ArgumentMatch - val name = argumentMatch.valueParameter.getName().asString() + val name = argumentMatch.valueParameter.getName() //TODO: not always correct for vararg's val newArgument = psiFactory.createArgument(argument.getArgumentExpression()!!, name, argument.getSpreadElement() != null) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt index b05b64938c0..956d3da2a94 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt @@ -43,7 +43,7 @@ public class ReplaceJavaAnnotationPositionedArgumentsFix(element: JetAnnotationE val valueArgument = (argument.value as? ExpressionValueArgument)?.getValueArgument() ?: return@argumentProcessor val expression = valueArgument.getArgumentExpression() ?: return@argumentProcessor - valueArgument.asElement().replace(psiFactory.createArgument(expression, argument.getKey().getName().asString())) + valueArgument.asElement().replace(psiFactory.createArgument(expression, argument.getKey().getName())) } } diff --git a/idea/testData/intentions/addNameToArgument/.intention b/idea/testData/intentions/addNameToArgument/.intention new file mode 100644 index 00000000000..f3a9c7bdc06 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.AddNameToArgumentIntention diff --git a/idea/testData/intentions/addNameToArgument/alreadyNamed.kt b/idea/testData/intentions/addNameToArgument/alreadyNamed.kt new file mode 100644 index 00000000000..053ea430f8d --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/alreadyNamed.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +fun foo(s: String, b: Boolean){} + +fun bar() { + foo("", b = true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/ambiguousCall.kt b/idea/testData/intentions/addNameToArgument/ambiguousCall.kt new file mode 100644 index 00000000000..93340866822 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/ambiguousCall.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +// ERROR: None of the following functions can be called with the arguments supplied.
  • foo(String, Boolean, Char) defined in root package
  • foo(String, Boolean, Int) defined in root package
+fun foo(s: String, b: Boolean, p: Int){} +fun foo(s: String, b: Boolean, c: Char){} + +fun bar() { + foo("", true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/functionLiteralArgument.kt b/idea/testData/intentions/addNameToArgument/functionLiteralArgument.kt new file mode 100644 index 00000000000..227f6d28aae --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/functionLiteralArgument.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +fun foo(s: String, handler: () -> Unit){} + +fun bar() { + foo("") { } +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/incompleteCall.kt b/idea/testData/intentions/addNameToArgument/incompleteCall.kt new file mode 100644 index 00000000000..f5d22d4c1cd --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/incompleteCall.kt @@ -0,0 +1,7 @@ +// ERROR: No value passed for parameter p + +fun foo(s: String, b: Boolean, p: Int){} + +fun bar() { + foo("", true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/incompleteCall.kt.after b/idea/testData/intentions/addNameToArgument/incompleteCall.kt.after new file mode 100644 index 00000000000..bd02e1887c5 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/incompleteCall.kt.after @@ -0,0 +1,7 @@ +// ERROR: No value passed for parameter p + +fun foo(s: String, b: Boolean, p: Int){} + +fun bar() { + foo("", b = true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/javaMethod.kt b/idea/testData/intentions/addNameToArgument/javaMethod.kt new file mode 100644 index 00000000000..3f2be7469d2 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/javaMethod.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +fun f() { + java.io.File("file") +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/notLast.kt b/idea/testData/intentions/addNameToArgument/notLast.kt new file mode 100644 index 00000000000..a26620dbd31 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/notLast.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +fun foo(s: String, b: Boolean){} + +fun bar() { + foo("", true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/notResolved.kt b/idea/testData/intentions/addNameToArgument/notResolved.kt new file mode 100644 index 00000000000..144692c079d --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/notResolved.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +// ERROR: Unresolved reference: foo +fun bar() { + foo("", true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt b/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt new file mode 100644 index 00000000000..f25c74f0e46 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt @@ -0,0 +1,5 @@ +fun foo(handler: () -> Unit){} + +fun bar() { + foo({ }) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt.after b/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt.after new file mode 100644 index 00000000000..fe800ef995a --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/rangeForLambda1.kt.after @@ -0,0 +1,5 @@ +fun foo(handler: () -> Unit){} + +fun bar() { + foo(handler = { }) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt b/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt new file mode 100644 index 00000000000..d7f679cd595 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt @@ -0,0 +1,5 @@ +fun foo(handler: () -> Unit){} + +fun bar() { + foo({ }) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt.after b/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt.after new file mode 100644 index 00000000000..7c9806c1469 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/rangeForLambda2.kt.after @@ -0,0 +1,5 @@ +fun foo(handler: () -> Unit){} + +fun bar() { + foo(handler = { }) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/rangeForLambda3.kt b/idea/testData/intentions/addNameToArgument/rangeForLambda3.kt new file mode 100644 index 00000000000..a1058acde1c --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/rangeForLambda3.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun foo(handler: () -> Unit){} + +fun bar() { + foo({}) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/simple.kt b/idea/testData/intentions/addNameToArgument/simple.kt new file mode 100644 index 00000000000..b7db1f3a687 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/simple.kt @@ -0,0 +1,5 @@ +fun foo(s: String, b: Boolean){} + +fun bar() { + foo("", true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/simple.kt.after b/idea/testData/intentions/addNameToArgument/simple.kt.after new file mode 100644 index 00000000000..b865ed623af --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/simple.kt.after @@ -0,0 +1,5 @@ +fun foo(s: String, b: Boolean){} + +fun bar() { + foo("", b = true) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/vararg1.kt b/idea/testData/intentions/addNameToArgument/vararg1.kt new file mode 100644 index 00000000000..def4a0a050e --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/vararg1.kt @@ -0,0 +1,5 @@ +fun foo(vararg s: String){} + +fun bar() { + foo("") +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/vararg1.kt.after b/idea/testData/intentions/addNameToArgument/vararg1.kt.after new file mode 100644 index 00000000000..0efa7fed654 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/vararg1.kt.after @@ -0,0 +1,5 @@ +fun foo(vararg s: String){} + +fun bar() { + foo(s = "") +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/vararg2.kt b/idea/testData/intentions/addNameToArgument/vararg2.kt new file mode 100644 index 00000000000..88e3158faa8 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/vararg2.kt @@ -0,0 +1,5 @@ +fun foo(vararg s: String){} + +fun bar(array: Array) { + foo(*array) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/vararg2.kt.after b/idea/testData/intentions/addNameToArgument/vararg2.kt.after new file mode 100644 index 00000000000..823cb27db63 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/vararg2.kt.after @@ -0,0 +1,5 @@ +fun foo(vararg s: String){} + +fun bar(array: Array) { + foo(s = *array) +} \ No newline at end of file diff --git a/idea/testData/intentions/addNameToArgument/vararg3.kt b/idea/testData/intentions/addNameToArgument/vararg3.kt new file mode 100644 index 00000000000..b59b21bfca5 --- /dev/null +++ b/idea/testData/intentions/addNameToArgument/vararg3.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun foo(vararg s: String){} + +fun bar() { + foo("a", "b") +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 5c8a15df2ab..e0b489741cf 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -92,6 +92,99 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/addNameToArgument") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddNameToArgument extends AbstractIntentionTest { + public void testAllFilesPresentInAddNameToArgument() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/addNameToArgument"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); + } + + @TestMetadata("alreadyNamed.kt") + public void testAlreadyNamed() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/alreadyNamed.kt"); + doTest(fileName); + } + + @TestMetadata("ambiguousCall.kt") + public void testAmbiguousCall() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/ambiguousCall.kt"); + doTest(fileName); + } + + @TestMetadata("functionLiteralArgument.kt") + public void testFunctionLiteralArgument() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/functionLiteralArgument.kt"); + doTest(fileName); + } + + @TestMetadata("incompleteCall.kt") + public void testIncompleteCall() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/incompleteCall.kt"); + doTest(fileName); + } + + @TestMetadata("javaMethod.kt") + public void testJavaMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/javaMethod.kt"); + doTest(fileName); + } + + @TestMetadata("notLast.kt") + public void testNotLast() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/notLast.kt"); + doTest(fileName); + } + + @TestMetadata("notResolved.kt") + public void testNotResolved() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/notResolved.kt"); + doTest(fileName); + } + + @TestMetadata("rangeForLambda1.kt") + public void testRangeForLambda1() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/rangeForLambda1.kt"); + doTest(fileName); + } + + @TestMetadata("rangeForLambda2.kt") + public void testRangeForLambda2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/rangeForLambda2.kt"); + doTest(fileName); + } + + @TestMetadata("rangeForLambda3.kt") + public void testRangeForLambda3() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/rangeForLambda3.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/simple.kt"); + doTest(fileName); + } + + @TestMetadata("vararg1.kt") + public void testVararg1() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/vararg1.kt"); + doTest(fileName); + } + + @TestMetadata("vararg2.kt") + public void testVararg2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/vararg2.kt"); + doTest(fileName); + } + + @TestMetadata("vararg3.kt") + public void testVararg3() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/addNameToArgument/vararg3.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/intentions/branched") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)