diff --git a/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/after.kt.template b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/after.kt.template
new file mode 100644
index 00000000000..043890cdac7
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/after.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = arrayOf(s)
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/before.kt.template b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/before.kt.template
new file mode 100644
index 00000000000..51cd5b36975
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/before.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = s$key
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/description.html b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/description.html
new file mode 100644
index 00000000000..575d9c2b091
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithArrayOfPostfixTemplate/description.html
@@ -0,0 +1,5 @@
+
+
+Wraps expression into 'arrayOf()'
+
+
diff --git a/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/after.kt.template b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/after.kt.template
new file mode 100644
index 00000000000..17851af9751
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/after.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = listOf(s)
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/before.kt.template b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/before.kt.template
new file mode 100644
index 00000000000..51cd5b36975
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/before.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = s$key
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/description.html b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/description.html
new file mode 100644
index 00000000000..c73b6e132e8
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithListOfPostfixTemplate/description.html
@@ -0,0 +1,5 @@
+
+
+Wraps expression into 'listOf()'
+
+
diff --git a/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/after.kt.template b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/after.kt.template
new file mode 100644
index 00000000000..b633d8ece53
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/after.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = sequenceOf(s)
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/before.kt.template b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/before.kt.template
new file mode 100644
index 00000000000..51cd5b36975
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/before.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = s$key
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/description.html b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/description.html
new file mode 100644
index 00000000000..84f63b19129
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSequenceOfPostfixTemplate/description.html
@@ -0,0 +1,5 @@
+
+
+Wraps expression into 'sequenceOf()'
+
+
diff --git a/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/after.kt.template b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/after.kt.template
new file mode 100644
index 00000000000..b224cca9282
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/after.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = setOf(s)
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/before.kt.template b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/before.kt.template
new file mode 100644
index 00000000000..51cd5b36975
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/before.kt.template
@@ -0,0 +1,3 @@
+fun foo(s: String) {
+ val x = s$key
+}
diff --git a/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/description.html b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/description.html
new file mode 100644
index 00000000000..f491fc2dc47
--- /dev/null
+++ b/idea/resources/postfixTemplates/KtWrapWithSetOfPostfixTemplate/description.html
@@ -0,0 +1,5 @@
+
+
+Wraps expression into 'setOf()'
+
+
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 182f9bdfb7a..aba98ab8860 100644
--- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/KtPostfixTemplateProvider.kt
@@ -58,7 +58,11 @@ class KtPostfixTemplateProvider : PostfixTemplateProvider {
KtParenthesizedPostfixTemplate,
KtSoutPostfixTemplate,
KtReturnPostfixTemplate,
- KtWhilePostfixTemplate
+ KtWhilePostfixTemplate,
+ KtWrapWithListOfPostfixTemplate,
+ KtWrapWithSetOfPostfixTemplate,
+ KtWrapWithArrayOfPostfixTemplate,
+ KtWrapWithSequenceOfPostfixTemplate
)
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 b3b317b7730..40582c11a79 100644
--- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/postfix/stringBasedPostfixTemplates.kt
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.liveTemplates.macro.SuggestVariableNameMacro
import org.jetbrains.kotlin.idea.resolve.ideService
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.psi.KtExpression
+import org.jetbrains.kotlin.psi.KtReturnExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.types.KotlinType
@@ -44,6 +45,18 @@ internal abstract class ConstantStringBasedPostfixTemplate(
override fun getElementToRemove(expr: PsiElement?) = expr
}
+internal abstract class KtWrapWithCallPostfixTemplate(val functionName: String) : ConstantStringBasedPostfixTemplate(
+ functionName,
+ "$functionName(expr)",
+ "$functionName(\$expr$)\$END$",
+ createExpressionSelectorWithComplexFilter { expression, _ -> expression !is KtReturnExpression }
+)
+
+internal object KtWrapWithListOfPostfixTemplate : KtWrapWithCallPostfixTemplate("listOf")
+internal object KtWrapWithSetOfPostfixTemplate : KtWrapWithCallPostfixTemplate("setOf")
+internal object KtWrapWithArrayOfPostfixTemplate : KtWrapWithCallPostfixTemplate("arrayOf")
+internal object KtWrapWithSequenceOfPostfixTemplate : KtWrapWithCallPostfixTemplate("sequenceOf")
+
internal class KtForEachPostfixTemplate(
name: String
) : ConstantStringBasedPostfixTemplate(
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt b/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt
new file mode 100644
index 00000000000..ed8cc0f3bb0
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ x.arrayOf
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt.after b/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt.after
new file mode 100644
index 00000000000..0b756e7fab3
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ arrayOf(x)
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt b/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt
new file mode 100644
index 00000000000..82d69b189f6
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ val y = x.listOf
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt.after b/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt.after
new file mode 100644
index 00000000000..d88663c7854
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ val y = listOf(x)
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt b/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt
new file mode 100644
index 00000000000..a88224962a2
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt
@@ -0,0 +1,3 @@
+fun foo(x: String): Any {
+ return x.sequenceOf
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt.after b/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt.after
new file mode 100644
index 00000000000..c0db8edd17c
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: String): Any {
+ return sequenceOf(x)
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt b/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt
new file mode 100644
index 00000000000..22afbaf34c0
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ val y = x.setOf
+}
diff --git a/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt.after b/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt.after
new file mode 100644
index 00000000000..031ef956355
--- /dev/null
+++ b/idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: String) {
+ val y = setOf(x)
+}
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 38175a7b50c..0fba48ce34d 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/postfix/PostfixTemplateProviderTestGenerated.java
@@ -213,4 +213,37 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat
public void testWhile() throws Exception {
runTest("idea/testData/codeInsight/postfix/while.kt");
}
+
+ @TestMetadata("idea/testData/codeInsight/postfix/wrapWithCall")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class WrapWithCall extends AbstractPostfixTemplateProviderTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInWrapWithCall() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/postfix/wrapWithCall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("arrayOfStatement.kt")
+ public void testArrayOfStatement() throws Exception {
+ runTest("idea/testData/codeInsight/postfix/wrapWithCall/arrayOfStatement.kt");
+ }
+
+ @TestMetadata("listOf.kt")
+ public void testListOf() throws Exception {
+ runTest("idea/testData/codeInsight/postfix/wrapWithCall/listOf.kt");
+ }
+
+ @TestMetadata("returnSequenceOf.kt")
+ public void testReturnSequenceOf() throws Exception {
+ runTest("idea/testData/codeInsight/postfix/wrapWithCall/returnSequenceOf.kt");
+ }
+
+ @TestMetadata("setOf.kt")
+ public void testSetOf() throws Exception {
+ runTest("idea/testData/codeInsight/postfix/wrapWithCall/setOf.kt");
+ }
+ }
}