Allow storing dot qualified expression in annotations arguments (KT-23738)

This commit is contained in:
Nikolay Krasko
2018-10-24 15:12:33 +03:00
parent a794d26493
commit 3f53f9d9fb
6 changed files with 39 additions and 6 deletions
@@ -57,9 +57,11 @@ class KtDotQualifiedExpression : KtExpressionImplStub<KotlinPlaceHolderStub<KtDo
private fun getChildExpressionsByStub(stub: KotlinPlaceHolderStub<KtDotQualifiedExpression>): Array<KtExpression>? {
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
@@ -54,6 +54,7 @@ public class KtValueArgument extends KtElementImplStub<KotlinPlaceHolderStub<? e
KtStubElementTypes.INTEGER_CONSTANT,
KtStubElementTypes.REFERENCE_EXPRESSION,
KtStubElementTypes.DOT_QUALIFIED_EXPRESSION,
KtStubElementTypes.STRING_TEMPLATE
);
@@ -17,12 +17,10 @@
package org.jetbrains.kotlin.psi.stubs.elements;
import com.intellij.lang.ASTNode;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression;
import org.jetbrains.kotlin.psi.KtImportDirective;
import org.jetbrains.kotlin.psi.KtPackageDirective;
public class KtDotQualifiedExpressionElementType extends KtPlaceHolderStubElementType<KtDotQualifiedExpression> {
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;
}
}