Add postfix template for the spread operator #KT-26249 Fixed
This commit is contained in:
committed by
Alexander Podkhalyuzin
parent
32d910320f
commit
f1dc09f839
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(list: List<String>) {
|
||||||
|
bar(<spot>*</spot>list.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(vararg args: String) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(list: List<String>) {
|
||||||
|
bar(<spot>list.toTypedArray()</spot>$key)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(vararg args: String) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
Add the spread operator to the prefix.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -62,7 +62,8 @@ class KtPostfixTemplateProvider : PostfixTemplateProvider {
|
|||||||
KtWrapWithListOfPostfixTemplate,
|
KtWrapWithListOfPostfixTemplate,
|
||||||
KtWrapWithSetOfPostfixTemplate,
|
KtWrapWithSetOfPostfixTemplate,
|
||||||
KtWrapWithArrayOfPostfixTemplate,
|
KtWrapWithArrayOfPostfixTemplate,
|
||||||
KtWrapWithSequenceOfPostfixTemplate
|
KtWrapWithSequenceOfPostfixTemplate,
|
||||||
|
KtSpreadPostfixTemplate
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun isTerminalSymbol(currentChar: Char) = currentChar == '.' || currentChar == '!'
|
override fun isTerminalSymbol(currentChar: Char) = currentChar == '.' || currentChar == '!'
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.template.impl.MacroCallNode
|
|||||||
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateExpressionSelector
|
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateExpressionSelector
|
||||||
import com.intellij.codeInsight.template.postfix.templates.StringBasedPostfixTemplate
|
import com.intellij.codeInsight.template.postfix.templates.StringBasedPostfixTemplate
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetection
|
import org.jetbrains.kotlin.idea.core.IterableTypesDetection
|
||||||
import org.jetbrains.kotlin.idea.liveTemplates.macro.SuggestVariableNameMacro
|
import org.jetbrains.kotlin.idea.liveTemplates.macro.SuggestVariableNameMacro
|
||||||
@@ -112,3 +113,10 @@ internal object KtWhilePostfixTemplate : ConstantStringBasedPostfixTemplate(
|
|||||||
"while (\$expr$) {\n\$END$\n}",
|
"while (\$expr$) {\n\$END$\n}",
|
||||||
createExpressionSelector(statementsOnly = true, typePredicate = KotlinType::isBoolean)
|
createExpressionSelector(statementsOnly = true, typePredicate = KotlinType::isBoolean)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal object KtSpreadPostfixTemplate : ConstantStringBasedPostfixTemplate(
|
||||||
|
"spread",
|
||||||
|
"*expr",
|
||||||
|
"*\$expr$\$END$",
|
||||||
|
createExpressionSelector(typePredicate = { KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it) })
|
||||||
|
)
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun test(list: List<String>) {
|
||||||
|
foo(list.toTypedArray().spread<caret>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(vararg args: String) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun test(list: List<String>) {
|
||||||
|
foo(*list.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(vararg args: String) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun test(a: IntArray) {
|
||||||
|
foo(a.spread<caret>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(vararg args: Int) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun test(a: IntArray) {
|
||||||
|
foo(*a)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(vararg args: Int) {}
|
||||||
Generated
+10
@@ -144,6 +144,16 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat
|
|||||||
runTest("idea/testData/codeInsight/postfix/soutInLoop.kt");
|
runTest("idea/testData/codeInsight/postfix/soutInLoop.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("spread.kt")
|
||||||
|
public void testSpread() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/postfix/spread.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("spreadIntArray.kt")
|
||||||
|
public void testSpreadIntArray() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/postfix/spreadIntArray.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("try.kt")
|
@TestMetadata("try.kt")
|
||||||
public void testTry() throws Exception {
|
public void testTry() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/postfix/try.kt");
|
runTest("idea/testData/codeInsight/postfix/try.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user