KotlinLanguageInjector: "kotlin" injections in annotations handled by injectWithCall

This commit is contained in:
Nicolay Mitropolsky
2018-02-28 13:52:11 +03:00
parent fd4f4ef853
commit 08c41474af
2 changed files with 20 additions and 3 deletions
@@ -247,8 +247,11 @@ class KotlinLanguageInjector(
val ktHost: KtElement = host
val argument = ktHost.parent as? KtValueArgument ?: return null
val callExpression = PsiTreeUtil.getParentOfType(ktHost, KtCallExpression::class.java) ?: return null
val callee = callExpression.calleeExpression ?: return null
val callExpression = PsiTreeUtil.getParentOfType(ktHost, KtCallElement::class.java) ?: return null
var callee = callExpression.calleeExpression ?: return null
if (callee is KtConstructorCalleeExpression)
callee = callee.constructorReferenceExpression ?: return null
if (isAnalyzeOff()) return null
@@ -286,7 +289,6 @@ class KotlinLanguageInjector(
}
val callee = calleeReference?.resolve()
when (callee) {
is KtFunction -> return injectionForKotlinCall(argument, callee, calleeReference)
is PsiClass -> {
val psiClass = callee as? PsiClass ?: return null
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() {
doAnnotationInjectionTest(
patternLanguage = "kotlin",