KT-15320 Live templates: please add function which returns the "outer" class name
This commit is contained in:
committed by
Dmitry Jemerov
parent
e2306ecf94
commit
79ff36592d
+4
-1
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.template.Expression
|
|||||||
import com.intellij.codeInsight.template.ExpressionContext
|
import com.intellij.codeInsight.template.ExpressionContext
|
||||||
import com.intellij.codeInsight.template.Result
|
import com.intellij.codeInsight.template.Result
|
||||||
import com.intellij.codeInsight.template.TextResult
|
import com.intellij.codeInsight.template.TextResult
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
|
|
||||||
@@ -28,7 +29,9 @@ class KotlinClassNameMacro : KotlinMacro() {
|
|||||||
override fun getPresentableName() = "kotlinClassName()"
|
override fun getPresentableName() = "kotlinClassName()"
|
||||||
|
|
||||||
override fun calculateResult(params: Array<Expression>, context: ExpressionContext): Result? {
|
override fun calculateResult(params: Array<Expression>, context: ExpressionContext): Result? {
|
||||||
val element = context.psiElementAtStartOffset?.parentsWithSelf?.firstOrNull { it is KtClassOrObject && it.name != null } ?: return null
|
val element = context.psiElementAtStartOffset?.parentsWithSelf?.firstOrNull {
|
||||||
|
it is KtClassOrObject && it.name != null && !it.hasModifier(KtTokens.COMPANION_KEYWORD)
|
||||||
|
} ?: return null
|
||||||
return TextResult((element as KtClassOrObject).name!!)
|
return TextResult((element as KtClassOrObject).name!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class Test() {
|
||||||
|
fun test() {
|
||||||
|
println("Test.test")<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class Test() {
|
||||||
|
fun test() {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class Test() {
|
||||||
|
companion object {
|
||||||
|
fun test() {
|
||||||
|
println("Test.test")<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class Test() {
|
||||||
|
companion object {
|
||||||
|
fun test() {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -73,6 +73,14 @@ class LiveTemplatesTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
paremeterless()
|
paremeterless()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testSoutf() {
|
||||||
|
paremeterless()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSoutf_InCompanion() {
|
||||||
|
paremeterless()
|
||||||
|
}
|
||||||
|
|
||||||
fun testSerr() {
|
fun testSerr() {
|
||||||
paremeterless()
|
paremeterless()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user