diff --git a/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/after.kt.template b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/after.kt.template new file mode 100644 index 00000000000..9245a9ddf50 --- /dev/null +++ b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/after.kt.template @@ -0,0 +1,3 @@ +fun foo(s: String) { + call(s) +} \ No newline at end of file diff --git a/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/before.kt.template b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/before.kt.template new file mode 100644 index 00000000000..c34759ecc7f --- /dev/null +++ b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/before.kt.template @@ -0,0 +1,3 @@ +fun foo(s: String) { + s$key +} \ No newline at end of file diff --git a/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/description.html b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/description.html new file mode 100644 index 00000000000..7a1383a4423 --- /dev/null +++ b/idea/resources/postfixTemplates/KtArgumentPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Wraps expression with a function call. + + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt index 5e7a4c30712..45caa12d8e8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt @@ -63,7 +63,8 @@ class KtPostfixTemplateProvider : PostfixTemplateProvider { KtWrapWithSetOfPostfixTemplate, KtWrapWithArrayOfPostfixTemplate, KtWrapWithSequenceOfPostfixTemplate, - KtSpreadPostfixTemplate + KtSpreadPostfixTemplate, + KtArgumentPostfixTemplate ) override fun isTerminalSymbol(currentChar: Char) = currentChar == '.' || currentChar == '!' diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt index d5adf11da95..ba1d56c9124 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt @@ -119,4 +119,15 @@ internal object KtSpreadPostfixTemplate : ConstantStringBasedPostfixTemplate( "*expr", "*\$expr$\$END$", createExpressionSelector(typePredicate = { KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it) }) -) \ No newline at end of file +) + +internal object KtArgumentPostfixTemplate : ConstantStringBasedPostfixTemplate( + "arg", + "functionCall(expr)", + "\$call$(\$expr$\$END$)", + createExpressionSelector(statementsOnly = true) +) { + override fun setVariables(template: Template, element: PsiElement) { + template.addVariable("call", "", "", true) + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/postfix/arg.kt b/idea/testData/codeInsight/postfix/arg.kt new file mode 100644 index 00000000000..cb9aadcc773 --- /dev/null +++ b/idea/testData/codeInsight/postfix/arg.kt @@ -0,0 +1,3 @@ +fun foo(s: String) { + s.arg +} \ No newline at end of file diff --git a/idea/testData/codeInsight/postfix/arg.kt.after b/idea/testData/codeInsight/postfix/arg.kt.after new file mode 100644 index 00000000000..1ea7dd2e0a1 --- /dev/null +++ b/idea/testData/codeInsight/postfix/arg.kt.after @@ -0,0 +1,3 @@ +fun foo(s: String) { + (s) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java index 125298d0a11..eff66f47f6c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java @@ -29,6 +29,11 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/postfix"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("arg.kt") + public void testArg() throws Exception { + runTest("idea/testData/codeInsight/postfix/arg.kt"); + } + @TestMetadata("assert.kt") public void testAssert() throws Exception { runTest("idea/testData/codeInsight/postfix/assert.kt");