[psi] make collection literal stub based
^ KT-57035
This commit is contained in:
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.parsing.KotlinExpressionParsing
|
import org.jetbrains.kotlin.parsing.KotlinExpressionParsing
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtClassLiteralExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtClassLiteralExpressionElementType
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.elements.KtCollectionLiteralExpressionElementType
|
||||||
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
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ object ElementTypeUtils {
|
|||||||
is KtConstantExpressionElementType,
|
is KtConstantExpressionElementType,
|
||||||
is KtStringTemplateExpressionElementType,
|
is KtStringTemplateExpressionElementType,
|
||||||
is KtClassLiteralExpressionElementType,
|
is KtClassLiteralExpressionElementType,
|
||||||
|
is KtCollectionLiteralExpressionElementType,
|
||||||
in expressionSet -> true
|
in expressionSet -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ public interface KtNodeTypes {
|
|||||||
IElementType WHEN_CONDITION_IS_PATTERN = new KtNodeType("WHEN_CONDITION_IS_PATTERN", KtWhenConditionIsPattern.class);
|
IElementType WHEN_CONDITION_IS_PATTERN = new KtNodeType("WHEN_CONDITION_IS_PATTERN", KtWhenConditionIsPattern.class);
|
||||||
IElementType WHEN_CONDITION_EXPRESSION = new KtNodeType("WHEN_CONDITION_WITH_EXPRESSION", KtWhenConditionWithExpression.class);
|
IElementType WHEN_CONDITION_EXPRESSION = new KtNodeType("WHEN_CONDITION_WITH_EXPRESSION", KtWhenConditionWithExpression.class);
|
||||||
|
|
||||||
IElementType COLLECTION_LITERAL_EXPRESSION = new KtNodeType("COLLECTION_LITERAL_EXPRESSION", KtCollectionLiteralExpression.class);
|
IElementType COLLECTION_LITERAL_EXPRESSION = KtStubElementTypes.COLLECTION_LITERAL_EXPRESSION;
|
||||||
|
|
||||||
IElementType PACKAGE_DIRECTIVE = KtStubElementTypes.PACKAGE_DIRECTIVE;
|
IElementType PACKAGE_DIRECTIVE = KtStubElementTypes.PACKAGE_DIRECTIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.KotlinCollectionLiteralExpressionStub;
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt.getTrailingCommaByClosingElement;
|
||||||
|
|
||||||
|
public class KtCollectionLiteralExpression extends KtElementImplStub<KotlinCollectionLiteralExpressionStub> implements KtReferenceExpression {
|
||||||
|
public KtCollectionLiteralExpression(@NotNull KotlinCollectionLiteralExpressionStub stub) {
|
||||||
|
super(stub, KtStubElementTypes.COLLECTION_LITERAL_EXPRESSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KtCollectionLiteralExpression(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
|
||||||
|
return visitor.visitCollectionLiteralExpression(this, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PsiElement getLeftBracket() {
|
||||||
|
ASTNode astNode = getNode().findChildByType(KtTokens.LBRACKET);
|
||||||
|
return astNode != null ? astNode.getPsi() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PsiElement getRightBracket() {
|
||||||
|
ASTNode astNode = getNode().findChildByType(KtTokens.RBRACKET);
|
||||||
|
return astNode != null ? astNode.getPsi() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PsiElement getTrailingComma() {
|
||||||
|
PsiElement rightBracket = getRightBracket();
|
||||||
|
return getTrailingCommaByClosingElement(rightBracket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<KtExpression> getInnerExpressions() {
|
||||||
|
KotlinCollectionLiteralExpressionStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
return Arrays.asList(stub.getChildrenByType(KtValueArgument.CONSTANT_EXPRESSIONS_TYPES, KtExpression.EMPTY_ARRAY));
|
||||||
|
}
|
||||||
|
return PsiTreeUtil.getChildrenOfTypeAsList(this, KtExpression.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.psi
|
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getTrailingCommaByClosingElement
|
|
||||||
|
|
||||||
class KtCollectionLiteralExpression(node: ASTNode) : KtExpressionImpl(node), KtReferenceExpression {
|
|
||||||
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
|
||||||
return visitor.visitCollectionLiteralExpression(this, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
val leftBracket: PsiElement?
|
|
||||||
get() = findChildByType(KtTokens.LBRACKET)
|
|
||||||
|
|
||||||
val rightBracket: PsiElement?
|
|
||||||
get() = findChildByType(KtTokens.RBRACKET)
|
|
||||||
|
|
||||||
val trailingComma: PsiElement?
|
|
||||||
get() = getTrailingCommaByClosingElement(rightBracket)
|
|
||||||
|
|
||||||
fun getInnerExpressions(): List<KtExpression> {
|
|
||||||
return PsiTreeUtil.getChildrenOfTypeAsList(this, KtExpression::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,7 +46,7 @@ public class KtValueArgument extends KtElementImplStub<KotlinValueArgumentStub<?
|
|||||||
return visitor.visitArgument(this, data);
|
return visitor.visitArgument(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final TokenSet CONSTANT_EXPRESSIONS_TYPES = TokenSet.create(
|
public static final TokenSet CONSTANT_EXPRESSIONS_TYPES = TokenSet.create(
|
||||||
KtStubElementTypes.NULL,
|
KtStubElementTypes.NULL,
|
||||||
KtStubElementTypes.BOOLEAN_CONSTANT,
|
KtStubElementTypes.BOOLEAN_CONSTANT,
|
||||||
KtStubElementTypes.FLOAT_CONSTANT,
|
KtStubElementTypes.FLOAT_CONSTANT,
|
||||||
@@ -58,7 +58,9 @@ public class KtValueArgument extends KtElementImplStub<KotlinValueArgumentStub<?
|
|||||||
|
|
||||||
KtStubElementTypes.STRING_TEMPLATE,
|
KtStubElementTypes.STRING_TEMPLATE,
|
||||||
|
|
||||||
KtStubElementTypes.CLASS_LITERAL_EXPRESSION
|
KtStubElementTypes.CLASS_LITERAL_EXPRESSION,
|
||||||
|
|
||||||
|
KtStubElementTypes.COLLECTION_LITERAL_EXPRESSION
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final TokenSet STRING_TEMPLATE_EXPRESSIONS_TYPES = TokenSet.create(
|
private static final TokenSet STRING_TEMPLATE_EXPRESSIONS_TYPES = TokenSet.create(
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ interface KotlinConstantExpressionStub : StubElement<KtConstantExpression> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinClassLiteralExpressionStub : StubElement<KtClassLiteralExpression>
|
interface KotlinClassLiteralExpressionStub : StubElement<KtClassLiteralExpression>
|
||||||
|
interface KotlinCollectionLiteralExpressionStub : StubElement<KtCollectionLiteralExpression>
|
||||||
|
|
||||||
interface KotlinTypeProjectionStub : StubElement<KtTypeProjection> {
|
interface KotlinTypeProjectionStub : StubElement<KtTypeProjection> {
|
||||||
fun getProjectionKind(): KtProjectionKind
|
fun getProjectionKind(): KtProjectionKind
|
||||||
|
|||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.stubs.StubElement
|
||||||
|
import com.intellij.psi.stubs.StubInputStream
|
||||||
|
import com.intellij.psi.stubs.StubOutputStream
|
||||||
|
import org.jetbrains.annotations.NonNls
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.KotlinClassLiteralExpressionStub
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.KotlinCollectionLiteralExpressionStub
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassLiteralExpressionStubImpl
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.impl.KotlinCollectionLiteralExpressionStubImpl
|
||||||
|
|
||||||
|
class KtCollectionLiteralExpressionElementType(@NonNls debugName: String) :
|
||||||
|
KtStubElementType<KotlinCollectionLiteralExpressionStub, KtCollectionLiteralExpression>(
|
||||||
|
debugName,
|
||||||
|
KtCollectionLiteralExpression::class.java,
|
||||||
|
KotlinCollectionLiteralExpressionStub::class.java
|
||||||
|
) {
|
||||||
|
override fun serialize(stub: KotlinCollectionLiteralExpressionStub, dataStream: StubOutputStream) {}
|
||||||
|
|
||||||
|
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): KotlinCollectionLiteralExpressionStub {
|
||||||
|
return KotlinCollectionLiteralExpressionStubImpl(parentStub)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createStub(psi: KtCollectionLiteralExpression, parentStub: StubElement<*>?): KotlinCollectionLiteralExpressionStub {
|
||||||
|
return KotlinCollectionLiteralExpressionStubImpl(parentStub)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -160,6 +160,7 @@ public interface KtStubElementTypes {
|
|||||||
KtConstantExpressionElementType CHARACTER_CONSTANT = new KtConstantExpressionElementType("CHARACTER_CONSTANT");
|
KtConstantExpressionElementType CHARACTER_CONSTANT = new KtConstantExpressionElementType("CHARACTER_CONSTANT");
|
||||||
KtConstantExpressionElementType INTEGER_CONSTANT = new KtConstantExpressionElementType("INTEGER_CONSTANT");
|
KtConstantExpressionElementType INTEGER_CONSTANT = new KtConstantExpressionElementType("INTEGER_CONSTANT");
|
||||||
KtClassLiteralExpressionElementType CLASS_LITERAL_EXPRESSION = new KtClassLiteralExpressionElementType("CLASS_LITERAL_EXPRESSION");
|
KtClassLiteralExpressionElementType CLASS_LITERAL_EXPRESSION = new KtClassLiteralExpressionElementType("CLASS_LITERAL_EXPRESSION");
|
||||||
|
KtCollectionLiteralExpressionElementType COLLECTION_LITERAL_EXPRESSION = new KtCollectionLiteralExpressionElementType("COLLECTION_LITERAL_EXPRESSION");
|
||||||
|
|
||||||
KtPlaceHolderStubElementType<KtStringTemplateExpression> STRING_TEMPLATE =
|
KtPlaceHolderStubElementType<KtStringTemplateExpression> STRING_TEMPLATE =
|
||||||
new KtStringTemplateExpressionElementType("STRING_TEMPLATE");
|
new KtStringTemplateExpressionElementType("STRING_TEMPLATE");
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.impl
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.stubs.StubElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.KotlinCollectionLiteralExpressionStub
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||||
|
|
||||||
|
class KotlinCollectionLiteralExpressionStubImpl(
|
||||||
|
parent: StubElement<out PsiElement>?
|
||||||
|
) : KotlinStubBaseImpl<KtCollectionLiteralExpression>(parent, KtStubElementTypes.COLLECTION_LITERAL_EXPRESSION),
|
||||||
|
KotlinCollectionLiteralExpressionStub
|
||||||
Reference in New Issue
Block a user