Introduce live templates for main without arguments #KT-27461 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-10-16 10:52:34 +03:00
parent 1c761c7864
commit 0f94c0901f
14 changed files with 60 additions and 2 deletions
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. 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.liveTemplates.macro
import com.intellij.codeInsight.template.Expression
import com.intellij.codeInsight.template.ExpressionContext
import com.intellij.codeInsight.template.Result
import com.intellij.codeInsight.template.TextResult
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.project.languageVersionSettings
class KotlinMainArgumentsMacro : KotlinMacro() {
override fun getName() = "kotlinMainArguments"
override fun getPresentableName() = "kotlinMainArguments()"
override fun calculateResult(params: Array<Expression>, context: ExpressionContext): Result? {
val languageVersionSettings = context.psiElementAtStartOffset?.languageVersionSettings ?: return null
if (languageVersionSettings.supportsFeature(LanguageFeature.ExtendedMainConvention)) return TextResult("")
return TextResult("args: Array<String>")
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
fun main(args: Array<String>) {
fun main() {
<caret>
}
+3
View File
@@ -0,0 +1,3 @@
fun main(args: Array<String>) {
<caret>
}
+1
View File
@@ -0,0 +1 @@
<caret>
@@ -72,6 +72,10 @@ class LiveTemplatesTest : KotlinLightCodeInsightFixtureTestCase() {
paremeterless()
}
fun testMaina() {
paremeterless()
}
fun testSoutv() {
start()