KotlinLanguageInjector: "kotlin" injections in annotations handled by injectWithCall
This commit is contained in:
@@ -247,8 +247,11 @@ class KotlinLanguageInjector(
|
|||||||
val ktHost: KtElement = host
|
val ktHost: KtElement = host
|
||||||
val argument = ktHost.parent as? KtValueArgument ?: return null
|
val argument = ktHost.parent as? KtValueArgument ?: return null
|
||||||
|
|
||||||
val callExpression = PsiTreeUtil.getParentOfType(ktHost, KtCallExpression::class.java) ?: return null
|
val callExpression = PsiTreeUtil.getParentOfType(ktHost, KtCallElement::class.java) ?: return null
|
||||||
val callee = callExpression.calleeExpression ?: return null
|
var callee = callExpression.calleeExpression ?: return null
|
||||||
|
|
||||||
|
if (callee is KtConstructorCalleeExpression)
|
||||||
|
callee = callee.constructorReferenceExpression ?: return null
|
||||||
|
|
||||||
if (isAnalyzeOff()) return null
|
if (isAnalyzeOff()) return null
|
||||||
|
|
||||||
@@ -286,7 +289,6 @@ class KotlinLanguageInjector(
|
|||||||
}
|
}
|
||||||
val callee = calleeReference?.resolve()
|
val callee = calleeReference?.resolve()
|
||||||
when (callee) {
|
when (callee) {
|
||||||
is KtFunction -> return injectionForKotlinCall(argument, callee, calleeReference)
|
|
||||||
is PsiClass -> {
|
is PsiClass -> {
|
||||||
val psiClass = callee as? PsiClass ?: return null
|
val psiClass = callee as? PsiClass ?: return null
|
||||||
val argumentName = argument.getArgumentName()?.asName?.identifier ?: "value"
|
val argumentName = argument.getArgumentName()?.asName?.identifier ?: "value"
|
||||||
|
|||||||
@@ -463,6 +463,21 @@ class KotlinInjectionTest : AbstractInjectionTest() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testKotlinNestedAnnotationsPattern() {
|
||||||
|
doAnnotationInjectionTest(
|
||||||
|
patternLanguage = "kotlin",
|
||||||
|
injectedLanguage = RegExpLanguage.INSTANCE.id,
|
||||||
|
pattern = """kotlinParameter().ofFunction(0, kotlinFunction().withName("Matches").definedInClass("Matches"))""",
|
||||||
|
kotlinCode = """
|
||||||
|
annotation class Matches(val pattern: String)
|
||||||
|
annotation class ManyMatches(val patterns: Array<Matches>)
|
||||||
|
|
||||||
|
@ManyMatches(patterns = [Matches("[A-Z]<caret>[a-z]+")])
|
||||||
|
val name = "John"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun testKotlinAnnotationsPatternNamed() {
|
fun testKotlinAnnotationsPatternNamed() {
|
||||||
doAnnotationInjectionTest(
|
doAnnotationInjectionTest(
|
||||||
patternLanguage = "kotlin",
|
patternLanguage = "kotlin",
|
||||||
|
|||||||
Reference in New Issue
Block a user