[psi] make class literal stub based
^ KT-57033
This commit is contained in:
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.parsing.KotlinExpressionParsing
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtClassLiteralExpressionElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType
|
||||
|
||||
@@ -60,6 +61,7 @@ object ElementTypeUtils {
|
||||
is KtNodeType,
|
||||
is KtConstantExpressionElementType,
|
||||
is KtStringTemplateExpressionElementType,
|
||||
is KtClassLiteralExpressionElementType,
|
||||
in expressionSet -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public interface KtNodeTypes {
|
||||
IElementType INDICES = new KtNodeType("INDICES", KtContainerNode.class);
|
||||
IElementType DOT_QUALIFIED_EXPRESSION = KtStubElementTypes.DOT_QUALIFIED_EXPRESSION;
|
||||
IElementType CALLABLE_REFERENCE_EXPRESSION = new KtNodeType("CALLABLE_REFERENCE_EXPRESSION", KtCallableReferenceExpression.class);
|
||||
IElementType CLASS_LITERAL_EXPRESSION = new KtNodeType("CLASS_LITERAL_EXPRESSION", KtClassLiteralExpression.class);
|
||||
IElementType CLASS_LITERAL_EXPRESSION = KtStubElementTypes.CLASS_LITERAL_EXPRESSION;
|
||||
IElementType SAFE_ACCESS_EXPRESSION = new KtNodeType("SAFE_ACCESS_EXPRESSION", KtSafeQualifiedExpression.class);
|
||||
|
||||
IElementType OBJECT_LITERAL = new KtNodeType("OBJECT_LITERAL", KtObjectLiteralExpression.class);
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.jetbrains.kotlin.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
|
||||
public class KtCallableReferenceExpression extends KtDoubleColonExpression {
|
||||
public class KtCallableReferenceExpression extends KtExpressionImpl implements KtDoubleColonExpression {
|
||||
public KtCallableReferenceExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@@ -38,6 +40,12 @@ public class KtCallableReferenceExpression extends KtDoubleColonExpression {
|
||||
throw new IllegalStateException("Callable reference simple name shouldn't be parsed to null");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement findColonColon() {
|
||||
return findChildByType(KtTokens.COLONCOLON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitCallableReferenceExpression(this, data);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassLiteralExpressionStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
||||
|
||||
public class KtClassLiteralExpression extends KtElementImplStub<KotlinClassLiteralExpressionStub> implements KtDoubleColonExpression {
|
||||
public KtClassLiteralExpression(KotlinClassLiteralExpressionStub stub) {
|
||||
super(stub, KtStubElementTypes.CLASS_LITERAL_EXPRESSION);
|
||||
}
|
||||
|
||||
public KtClassLiteralExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
|
||||
private static final TokenSet CLASS_REFS = TokenSet.create(
|
||||
KtStubElementTypes.REFERENCE_EXPRESSION,
|
||||
KtStubElementTypes.DOT_QUALIFIED_EXPRESSION
|
||||
);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtExpression getReceiverExpression() {
|
||||
KotlinClassLiteralExpressionStub stub = getStub();
|
||||
if (stub != null) {
|
||||
KtExpression[] expressions = stub.getChildrenByType(CLASS_REFS, KtExpression.EMPTY_ARRAY);
|
||||
if (expressions.length == 1) {
|
||||
return expressions[0];
|
||||
}
|
||||
}
|
||||
return KtDoubleColonExpression.super.getReceiverExpression();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassLiteralExpression(this, data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement findColonColon() {
|
||||
ASTNode child = getNode().findChildByType(KtTokens.COLONCOLON);
|
||||
return child != null ? child.getPsi() : null;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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
|
||||
|
||||
class KtClassLiteralExpression(node: ASTNode) : KtDoubleColonExpression(node) {
|
||||
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
||||
return visitor.visitClassLiteralExpression(this, data)
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import com.intellij.lang.ASTNode
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
||||
interface KtDoubleColonExpression : KtExpression {
|
||||
val receiverExpression: KtExpression?
|
||||
get() = node.firstChildNode.psi as? KtExpression
|
||||
|
||||
@@ -35,8 +35,10 @@ abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
||||
error("Double colon expression must have '::': $text")
|
||||
}
|
||||
|
||||
fun findColonColon(): PsiElement?
|
||||
|
||||
val doubleColonTokenReference: PsiElement
|
||||
get() = findChildByType(KtTokens.COLONCOLON)!!
|
||||
get() = findColonColon()!!
|
||||
|
||||
val lhs: PsiElement?
|
||||
get() = doubleColonTokenReference.prevSibling
|
||||
|
||||
@@ -56,7 +56,9 @@ public class KtValueArgument extends KtElementImplStub<KotlinValueArgumentStub<?
|
||||
KtStubElementTypes.REFERENCE_EXPRESSION,
|
||||
KtStubElementTypes.DOT_QUALIFIED_EXPRESSION,
|
||||
|
||||
KtStubElementTypes.STRING_TEMPLATE
|
||||
KtStubElementTypes.STRING_TEMPLATE,
|
||||
|
||||
KtStubElementTypes.CLASS_LITERAL_EXPRESSION
|
||||
);
|
||||
|
||||
private static final TokenSet STRING_TEMPLATE_EXPRESSIONS_TYPES = TokenSet.create(
|
||||
|
||||
@@ -23,12 +23,12 @@ object KotlinStubVersions {
|
||||
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
|
||||
// if you are not 100% sure it can be avoided.
|
||||
// Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version.
|
||||
const val SOURCE_STUB_VERSION = 146
|
||||
const val SOURCE_STUB_VERSION = 147
|
||||
|
||||
// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
|
||||
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
|
||||
// Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files).
|
||||
private const val BINARY_STUB_VERSION = 82
|
||||
private const val BINARY_STUB_VERSION = 83
|
||||
|
||||
// Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile)
|
||||
// Increasing this version will lead to reindexing of all classfiles.
|
||||
|
||||
@@ -162,6 +162,8 @@ interface KotlinConstantExpressionStub : StubElement<KtConstantExpression> {
|
||||
fun value(): String
|
||||
}
|
||||
|
||||
interface KotlinClassLiteralExpressionStub : StubElement<KtClassLiteralExpression>
|
||||
|
||||
interface KotlinTypeProjectionStub : StubElement<KtTypeProjection> {
|
||||
fun getProjectionKind(): KtProjectionKind
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.stubs.KotlinClassLiteralExpressionStub
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassLiteralExpressionStubImpl
|
||||
|
||||
class KtClassLiteralExpressionElementType(@NonNls debugName: String) :
|
||||
KtStubElementType<KotlinClassLiteralExpressionStub, KtClassLiteralExpression>(
|
||||
debugName,
|
||||
KtClassLiteralExpression::class.java,
|
||||
KotlinClassLiteralExpressionStub::class.java
|
||||
) {
|
||||
|
||||
override fun createStub(psi: KtClassLiteralExpression, parentStub: StubElement<*>?): KotlinClassLiteralExpressionStub {
|
||||
return KotlinClassLiteralExpressionStubImpl(
|
||||
parentStub)
|
||||
}
|
||||
|
||||
override fun serialize(stub: KotlinClassLiteralExpressionStub, dataStream: StubOutputStream) {
|
||||
}
|
||||
|
||||
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): KotlinClassLiteralExpressionStub {
|
||||
return KotlinClassLiteralExpressionStubImpl(parentStub)
|
||||
}
|
||||
}
|
||||
+1
@@ -57,6 +57,7 @@ public class KtDotQualifiedExpressionElementType extends KtPlaceHolderStubElemen
|
||||
if (parentElementType == KtStubElementTypes.IMPORT_DIRECTIVE ||
|
||||
parentElementType == KtStubElementTypes.PACKAGE_DIRECTIVE ||
|
||||
parentElementType == KtStubElementTypes.VALUE_ARGUMENT ||
|
||||
parentElementType == KtStubElementTypes.CLASS_LITERAL_EXPRESSION ||
|
||||
parentElementType == KtStubElementTypes.DOT_QUALIFIED_EXPRESSION
|
||||
) {
|
||||
return checkNodeTypesTraversal(node) && super.shouldCreateStub(node);
|
||||
|
||||
@@ -159,6 +159,7 @@ public interface KtStubElementTypes {
|
||||
KtConstantExpressionElementType FLOAT_CONSTANT = new KtConstantExpressionElementType("FLOAT_CONSTANT");
|
||||
KtConstantExpressionElementType CHARACTER_CONSTANT = new KtConstantExpressionElementType("CHARACTER_CONSTANT");
|
||||
KtConstantExpressionElementType INTEGER_CONSTANT = new KtConstantExpressionElementType("INTEGER_CONSTANT");
|
||||
KtClassLiteralExpressionElementType CLASS_LITERAL_EXPRESSION = new KtClassLiteralExpressionElementType("CLASS_LITERAL_EXPRESSION");
|
||||
|
||||
KtPlaceHolderStubElementType<KtStringTemplateExpression> STRING_TEMPLATE =
|
||||
new KtStringTemplateExpressionElementType("STRING_TEMPLATE");
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.KtClassLiteralExpression
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassLiteralExpressionStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
|
||||
class KotlinClassLiteralExpressionStubImpl(
|
||||
parent: StubElement<out PsiElement>?
|
||||
) : KotlinStubBaseImpl<KtClassLiteralExpression>(parent, KtStubElementTypes.CLASS_LITERAL_EXPRESSION), KotlinClassLiteralExpressionStub
|
||||
Reference in New Issue
Block a user