Move TokenSet from KtStubElementTypes

KtStubElementTypes has to have only KtStubElementType fields to provide
ability to initialize stub element types lazily.

#KT-53781
This commit is contained in:
Vladimir Dolzhenko
2022-09-13 12:21:27 +02:00
committed by Space
parent f643cdf90b
commit 584eb9dfa9
12 changed files with 44 additions and 23 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.psi.KtParameter.VAL_VAR_TOKEN_SET
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets
import org.jetbrains.kotlin.utils.addToStdlib.runUnless import org.jetbrains.kotlin.utils.addToStdlib.runUnless
object LightTreePositioningStrategies { object LightTreePositioningStrategies {
@@ -596,7 +597,7 @@ object LightTreePositioningStrategies {
return super.mark(node, startOffset, endOffset, tree) return super.mark(node, startOffset, endOffset, tree)
} }
if (node.tokenType == KtNodeTypes.TYPE_REFERENCE) { if (node.tokenType == KtNodeTypes.TYPE_REFERENCE) {
val typeElement = tree.findChildByType(node, KtStubElementTypes.TYPE_ELEMENT_TYPES) val typeElement = tree.findChildByType(node, KtTokenSets.TYPE_ELEMENT_TYPES)
if (typeElement != null) { if (typeElement != null) {
val referencedTypeExpression = tree.referencedTypeExpression(typeElement) val referencedTypeExpression = tree.referencedTypeExpression(typeElement)
if (referencedTypeExpression != null) { if (referencedTypeExpression != null) {
@@ -612,7 +613,7 @@ object LightTreePositioningStrategies {
return when (node.tokenType) { return when (node.tokenType) {
KtNodeTypes.USER_TYPE -> findChildByType(node, KtNodeTypes.REFERENCE_EXPRESSION) KtNodeTypes.USER_TYPE -> findChildByType(node, KtNodeTypes.REFERENCE_EXPRESSION)
?: findChildByType(node, KtNodeTypes.ENUM_ENTRY_SUPERCLASS_REFERENCE_EXPRESSION) ?: findChildByType(node, KtNodeTypes.ENUM_ENTRY_SUPERCLASS_REFERENCE_EXPRESSION)
KtNodeTypes.NULLABLE_TYPE -> findChildByType(node, KtStubElementTypes.TYPE_ELEMENT_TYPES) KtNodeTypes.NULLABLE_TYPE -> findChildByType(node, KtTokenSets.TYPE_ELEMENT_TYPES)
?.let { referencedTypeExpression(it) } ?.let { referencedTypeExpression(it) }
else -> null else -> null
} }
@@ -687,7 +688,7 @@ object LightTreePositioningStrategies {
return markElement(nodeToMark, startOffset, endOffset, tree, node) return markElement(nodeToMark, startOffset, endOffset, tree, node)
} }
node.tokenType == KtNodeTypes.IMPORT_DIRECTIVE -> { node.tokenType == KtNodeTypes.IMPORT_DIRECTIVE -> {
val nodeToMark = tree.findChildByType(node, KtStubElementTypes.INSIDE_DIRECTIVE_EXPRESSIONS) ?: node val nodeToMark = tree.findChildByType(node, KtTokenSets.INSIDE_DIRECTIVE_EXPRESSIONS) ?: node
return markElement(nodeToMark, startOffset, endOffset, tree, node) return markElement(nodeToMark, startOffset, endOffset, tree, node)
} }
node.tokenType != KtNodeTypes.DOT_QUALIFIED_EXPRESSION && node.tokenType != KtNodeTypes.DOT_QUALIFIED_EXPRESSION &&
@@ -23,8 +23,9 @@ import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.* import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.CLASS_BODY
import java.util.* import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.MODIFIER_LIST
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets.DECLARATION_TYPES
class KtClassBody : KtElementImplStub<KotlinPlaceHolderStub<KtClassBody>>, KtDeclarationContainer { class KtClassBody : KtElementImplStub<KotlinPlaceHolderStub<KtClassBody>>, KtDeclarationContainer {
private val lBraceTokenSet = TokenSet.create(KtTokens.LBRACE) private val lBraceTokenSet = TokenSet.create(KtTokens.LBRACE)
@@ -20,7 +20,7 @@ import com.intellij.lang.ASTNode
import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.Logger
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.INSIDE_DIRECTIVE_EXPRESSIONS import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets.INSIDE_DIRECTIVE_EXPRESSIONS
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
class KtDotQualifiedExpression : KtExpressionImplStub<KotlinPlaceHolderStub<KtDotQualifiedExpression>>, KtQualifiedExpression { class KtDotQualifiedExpression : KtExpressionImplStub<KotlinPlaceHolderStub<KtDotQualifiedExpression>>, KtQualifiedExpression {
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
import org.jetbrains.kotlin.psi.stubs.elements.KtPlaceHolderStubElementType import org.jetbrains.kotlin.psi.stubs.elements.KtPlaceHolderStubElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets
open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) : open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
PsiFileBase(viewProvider, KotlinLanguage.INSTANCE), PsiFileBase(viewProvider, KotlinLanguage.INSTANCE),
@@ -273,6 +274,6 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
} }
companion object { companion object {
val FILE_DECLARATION_TYPES = TokenSet.orSet(KtStubElementTypes.DECLARATION_TYPES, TokenSet.create(KtStubElementTypes.SCRIPT)) val FILE_DECLARATION_TYPES = TokenSet.orSet(KtTokenSets.DECLARATION_TYPES, TokenSet.create(KtStubElementTypes.SCRIPT))
} }
} }
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.stubs.KotlinImportDirectiveStub; import org.jetbrains.kotlin.psi.stubs.KotlinImportDirectiveStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets;
import org.jetbrains.kotlin.resolve.ImportPath; import org.jetbrains.kotlin.resolve.ImportPath;
public class KtImportDirective extends KtElementImplStub<KotlinImportDirectiveStub> implements KtImportInfo { public class KtImportDirective extends KtElementImplStub<KotlinImportDirectiveStub> implements KtImportInfo {
@@ -47,7 +48,7 @@ public class KtImportDirective extends KtElementImplStub<KotlinImportDirectiveSt
@Nullable @Nullable
@IfNotParsed @IfNotParsed
public KtExpression getImportedReference() { public KtExpression getImportedReference() {
KtExpression[] references = getStubOrPsiChildren(KtStubElementTypes.INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY); KtExpression[] references = getStubOrPsiChildren(KtTokenSets.INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY);
if (references.length > 0) { if (references.length > 0) {
return references[0]; return references[0];
} }
@@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -40,6 +41,6 @@ public class KtInitializerList extends KtElementImplStub<KotlinPlaceHolderStub<K
@NotNull @NotNull
public List<KtSuperTypeListEntry> getInitializers() { public List<KtSuperTypeListEntry> getInitializers() {
return Arrays.asList(getStubOrPsiChildren(KtStubElementTypes.SUPER_TYPE_LIST_ENTRIES, KtSuperTypeListEntry.ARRAY_FACTORY)); return Arrays.asList(getStubOrPsiChildren(KtTokenSets.SUPER_TYPE_LIST_ENTRIES, KtSuperTypeListEntry.ARRAY_FACTORY));
} }
} }
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -55,7 +56,7 @@ public class KtNullableType extends KtElementImplStub<KotlinPlaceHolderStub<KtNu
@Nullable @Nullable
@IfNotParsed @IfNotParsed
public KtTypeElement getInnerType() { public KtTypeElement getInnerType() {
return KtStubbedPsiUtil.getStubOrPsiChild(this, KtStubElementTypes.TYPE_ELEMENT_TYPES, KtTypeElement.ARRAY_FACTORY); return KtStubbedPsiUtil.getStubOrPsiChild(this, KtTokenSets.TYPE_ELEMENT_TYPES, KtTypeElement.ARRAY_FACTORY);
} }
@Nullable @Nullable
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt; import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -46,7 +47,7 @@ public class KtPackageDirective extends KtModifierListOwnerStub<KotlinPlaceHolde
// This should be either JetSimpleNameExpression, or JetDotQualifiedExpression // This should be either JetSimpleNameExpression, or JetDotQualifiedExpression
@Nullable @Nullable
public KtExpression getPackageNameExpression() { public KtExpression getPackageNameExpression() {
return KtStubbedPsiUtil.getStubOrPsiChild(this, KtStubElementTypes.INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY); return KtStubbedPsiUtil.getStubOrPsiChild(this, KtTokenSets.INSIDE_DIRECTIVE_EXPRESSIONS, KtExpression.ARRAY_FACTORY);
} }
@NotNull @NotNull
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -67,7 +68,7 @@ public class KtSuperTypeList extends KtElementImplStub<KotlinPlaceHolderStub<KtS
} }
public List<KtSuperTypeListEntry> getEntries() { public List<KtSuperTypeListEntry> getEntries() {
return Arrays.asList(getStubOrPsiChildren(KtStubElementTypes.SUPER_TYPE_LIST_ENTRIES, KtSuperTypeListEntry.ARRAY_FACTORY)); return Arrays.asList(getStubOrPsiChildren(KtTokenSets.SUPER_TYPE_LIST_ENTRIES, KtSuperTypeListEntry.ARRAY_FACTORY));
} }
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets
/** /**
* Type reference element. * Type reference element.
@@ -42,7 +42,7 @@ class KtTypeReference : KtModifierListOwnerStub<KotlinPlaceHolderStub<KtTypeRefe
get() = ((typeElement as? KtUserType)?.referenceExpression as? KtNameReferenceExpression)?.isPlaceholder == true get() = ((typeElement as? KtUserType)?.referenceExpression as? KtNameReferenceExpression)?.isPlaceholder == true
val typeElement: KtTypeElement? val typeElement: KtTypeElement?
get() = KtStubbedPsiUtil.getStubOrPsiChild(this, KtStubElementTypes.TYPE_ELEMENT_TYPES, KtTypeElement.ARRAY_FACTORY) get() = KtStubbedPsiUtil.getStubOrPsiChild(this, KtTokenSets.TYPE_ELEMENT_TYPES, KtTypeElement.ARRAY_FACTORY)
override fun getAnnotations(): List<KtAnnotation> { override fun getAnnotations(): List<KtAnnotation> {
return modifierList?.annotations.orEmpty() return modifierList?.annotations.orEmpty()
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.psi.stubs.elements; package org.jetbrains.kotlin.psi.stubs.elements;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
public interface KtStubElementTypes { public interface KtStubElementTypes {
@@ -171,12 +170,4 @@ public interface KtStubElementTypes {
KtScriptElementType SCRIPT = new KtScriptElementType("SCRIPT"); KtScriptElementType SCRIPT = new KtScriptElementType("SCRIPT");
TokenSet DECLARATION_TYPES =
TokenSet.create(CLASS, OBJECT_DECLARATION, FUNCTION, PROPERTY, TYPEALIAS, CLASS_INITIALIZER, SECONDARY_CONSTRUCTOR, ENUM_ENTRY);
TokenSet SUPER_TYPE_LIST_ENTRIES = TokenSet.create(DELEGATED_SUPER_TYPE_ENTRY, SUPER_TYPE_CALL_ENTRY, SUPER_TYPE_ENTRY);
TokenSet TYPE_ELEMENT_TYPES = TokenSet.create(USER_TYPE, NULLABLE_TYPE, FUNCTION_TYPE, DYNAMIC_TYPE, INTERSECTION_TYPE);
TokenSet INSIDE_DIRECTIVE_EXPRESSIONS = TokenSet.create(REFERENCE_EXPRESSION, DOT_QUALIFIED_EXPRESSION);
} }
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.psi.stubs.elements;
import com.intellij.psi.tree.TokenSet;
import static org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.*;
public interface KtTokenSets {
TokenSet DECLARATION_TYPES =
TokenSet.create(CLASS, OBJECT_DECLARATION, FUNCTION, PROPERTY, TYPEALIAS, CLASS_INITIALIZER, SECONDARY_CONSTRUCTOR, ENUM_ENTRY);
TokenSet SUPER_TYPE_LIST_ENTRIES = TokenSet.create(DELEGATED_SUPER_TYPE_ENTRY, SUPER_TYPE_CALL_ENTRY, SUPER_TYPE_ENTRY);
TokenSet TYPE_ELEMENT_TYPES = TokenSet.create(USER_TYPE, NULLABLE_TYPE, FUNCTION_TYPE, DYNAMIC_TYPE, INTERSECTION_TYPE);
TokenSet INSIDE_DIRECTIVE_EXPRESSIONS = TokenSet.create(REFERENCE_EXPRESSION, DOT_QUALIFIED_EXPRESSION);
}