From 3f53f9d9fb36929c385ffc0ca52aa956f2dcfc93 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 24 Oct 2018 15:12:33 +0300 Subject: [PATCH] Allow storing dot qualified expression in annotations arguments (KT-23738) --- .../kotlin/psi/KtDotQualifiedExpression.kt | 6 ++++-- .../jetbrains/kotlin/psi/KtValueArgument.java | 1 + .../KtDotQualifiedExpressionElementType.java | 18 ++++++++++++++---- idea/testData/stubs/AnnotationValues.expected | 8 ++++++++ idea/testData/stubs/DynamicType.expected | 6 ++++++ idea/testData/stubs/TypeAnnotation.expected | 6 ++++++ 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDotQualifiedExpression.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDotQualifiedExpression.kt index 12ab54198fb..30d9947971e 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDotQualifiedExpression.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDotQualifiedExpression.kt @@ -57,9 +57,11 @@ class KtDotQualifiedExpression : KtExpressionImplStub): Array? { if (stub.getParentStubOfType(KtImportDirective::class.java) == null && - stub.getParentStubOfType(KtPackageDirective::class.java) == null) { + stub.getParentStubOfType(KtPackageDirective::class.java) == null && + stub.getParentStubOfType(KtValueArgument::class.java) == null + ) { LOG.error( - "KtDotQualifiedExpression should only have stubs inside import or package directives.\n" + + "KtDotQualifiedExpression should only have stubs inside import, argument or package directives.\n" + "Stubs were created for:\n$text\nFile text:\n${containingFile.text}" ) return null diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java index 472584b9a13..1c80f36c625 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java @@ -54,6 +54,7 @@ public class KtValueArgument extends KtElementImplStub { public KtDotQualifiedExpressionElementType(@NotNull @NonNls String debugName) { @@ -31,6 +29,18 @@ public class KtDotQualifiedExpressionElementType extends KtPlaceHolderStubElemen @Override public boolean shouldCreateStub(ASTNode node) { - return PsiTreeUtil.getParentOfType(node.getPsi(), KtImportDirective.class, KtPackageDirective.class) != null; + ASTNode treeParent = node.getTreeParent(); + if (treeParent == null) return false; + + IElementType parentElementType = treeParent.getElementType(); + if (parentElementType == KtStubElementTypes.IMPORT_DIRECTIVE || + parentElementType == KtStubElementTypes.PACKAGE_DIRECTIVE || + parentElementType == KtStubElementTypes.VALUE_ARGUMENT || + parentElementType == KtStubElementTypes.DOT_QUALIFIED_EXPRESSION + ) { + return super.shouldCreateStub(node); + } + + return false; } } diff --git a/idea/testData/stubs/AnnotationValues.expected b/idea/testData/stubs/AnnotationValues.expected index 07a75d448d0..3396509354e 100644 --- a/idea/testData/stubs/AnnotationValues.expected +++ b/idea/testData/stubs/AnnotationValues.expected @@ -150,9 +150,17 @@ PsiJetFileStubImpl[package=test] VALUE_ARGUMENT REFERENCE_EXPRESSION[referencedName=E1] VALUE_ARGUMENT + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=E] + REFERENCE_EXPRESSION[referencedName=E2] VALUE_ARGUMENT VALUE_ARGUMENT_NAME REFERENCE_EXPRESSION[referencedName=e3] + DOT_QUALIFIED_EXPRESSION + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=E] + REFERENCE_EXPRESSION[referencedName=E2] CLASS[fqName=test.VarArg, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=VarArg, superNames=[]] MODIFIER_LIST[annotation] PRIMARY_CONSTRUCTOR diff --git a/idea/testData/stubs/DynamicType.expected b/idea/testData/stubs/DynamicType.expected index 388612f7a75..7c2af95b4de 100644 --- a/idea/testData/stubs/DynamicType.expected +++ b/idea/testData/stubs/DynamicType.expected @@ -36,4 +36,10 @@ PsiJetFileStubImpl[package=] REFERENCE_EXPRESSION[referencedName=Target] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=AnnotationTarget] + REFERENCE_EXPRESSION[referencedName=TYPE] VALUE_ARGUMENT + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=AnnotationTarget] + REFERENCE_EXPRESSION[referencedName=TYPE_PARAMETER] diff --git a/idea/testData/stubs/TypeAnnotation.expected b/idea/testData/stubs/TypeAnnotation.expected index 659504dd8e6..c461d742ec4 100644 --- a/idea/testData/stubs/TypeAnnotation.expected +++ b/idea/testData/stubs/TypeAnnotation.expected @@ -35,6 +35,9 @@ PsiJetFileStubImpl[package=] REFERENCE_EXPRESSION[referencedName=b] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=E] + REFERENCE_EXPRESSION[referencedName=E1] USER_TYPE REFERENCE_EXPRESSION[referencedName=DoubleRange] TYPE_REFERENCE @@ -53,5 +56,8 @@ PsiJetFileStubImpl[package=] REFERENCE_EXPRESSION[referencedName=b] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION[referencedName=E] + REFERENCE_EXPRESSION[referencedName=E2] USER_TYPE REFERENCE_EXPRESSION[referencedName=Unit]