Store presence of spread operator for value argument in stubs

This commit is contained in:
Nikolay Krasko
2018-11-12 13:36:05 +03:00
parent 4c64db66dc
commit 2d1c76344c
13 changed files with 147 additions and 48 deletions
@@ -6,13 +6,13 @@
package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
import org.jetbrains.kotlin.psi.stubs.KotlinValueArgumentStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
class KtLambdaArgument : KtValueArgument, LambdaArgument {
constructor(node: ASTNode) : super(node) {}
constructor(node: ASTNode) : super(node)
constructor(stub: KotlinPlaceHolderStub<KtLambdaArgument>) : super(stub, KtStubElementTypes.LAMBDA_ARGUMENT) {}
constructor(stub: KotlinValueArgumentStub<KtLambdaArgument>) : super(stub, KtStubElementTypes.LAMBDA_ARGUMENT) {}
override fun getLambdaExpression(): KtLambdaExpression? = getArgumentExpression()?.unpackFunctionLiteral()
}
@@ -19,24 +19,25 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.stubs.IStubElementType;
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.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtPlaceHolderStubElementType;
import org.jetbrains.kotlin.psi.stubs.KotlinValueArgumentStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
public class KtValueArgument extends KtElementImplStub<KotlinPlaceHolderStub<? extends KtValueArgument>> implements ValueArgument {
public class KtValueArgument extends KtElementImplStub<KotlinValueArgumentStub<? extends KtValueArgument>> implements ValueArgument {
public KtValueArgument(@NotNull ASTNode node) {
super(node);
}
public KtValueArgument(@NotNull KotlinPlaceHolderStub<KtValueArgument> stub) {
public KtValueArgument(@NotNull KotlinValueArgumentStub<KtValueArgument> stub) {
super(stub, KtStubElementTypes.VALUE_ARGUMENT);
}
protected KtValueArgument(KotlinPlaceHolderStub<? extends KtValueArgument> stub, KtPlaceHolderStubElementType<?> nodeType) {
protected KtValueArgument(KotlinValueArgumentStub<? extends KtValueArgument> stub, IStubElementType nodeType) {
super(stub, nodeType);
}
@@ -96,10 +97,24 @@ public class KtValueArgument extends KtElementImplStub<KotlinPlaceHolderStub<? e
@Override
public LeafPsiElement getSpreadElement() {
KotlinValueArgumentStub stub = getStub();
if (stub != null && !stub.isSpread()) {
return null;
}
ASTNode node = getNode().findChildByType(KtTokens.MUL);
return node == null ? null : (LeafPsiElement) node.getPsi();
}
public boolean isSpread() {
KotlinValueArgumentStub stub = getStub();
if (stub != null) {
return stub.isSpread();
}
return getSpreadElement() != null;
}
@Override
public boolean isExternal() {
return false;
@@ -23,7 +23,7 @@ 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 = 134
const val SOURCE_STUB_VERSION = 135
// 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).
@@ -60,6 +60,10 @@ interface KotlinObjectStub : KotlinClassOrObjectStub<KtObjectDeclaration> {
fun isObjectLiteral(): Boolean
}
interface KotlinValueArgumentStub<T : KtValueArgument> : KotlinPlaceHolderStub<T> {
fun isSpread(): Boolean
}
interface KotlinAnnotationEntryStub : StubElement<KtAnnotationEntry> {
fun getShortName(): String?
fun hasValueArguments(): Boolean
@@ -104,11 +104,11 @@ public interface KtStubElementTypes {
KtPlaceHolderStubElementType<KtValueArgumentList> VALUE_ARGUMENT_LIST =
new KtValueArgumentListElementType("VALUE_ARGUMENT_LIST");
KtPlaceHolderStubElementType<KtValueArgument> VALUE_ARGUMENT =
new KtPlaceHolderStubElementType<>("VALUE_ARGUMENT", KtValueArgument.class);
KtValueArgumentElementType<KtValueArgument> VALUE_ARGUMENT =
new KtValueArgumentElementType<>("VALUE_ARGUMENT", KtValueArgument.class);
KtPlaceHolderStubElementType<KtLambdaArgument> LAMBDA_ARGUMENT =
new KtPlaceHolderStubElementType<>("LAMBDA_ARGUMENT", KtLambdaArgument.class);
KtValueArgumentElementType<KtLambdaArgument> LAMBDA_ARGUMENT =
new KtValueArgumentElementType<>("LAMBDA_ARGUMENT", KtLambdaArgument.class);
KtPlaceHolderStubElementType<KtValueArgumentName> VALUE_ARGUMENT_NAME =
new KtPlaceHolderStubElementType<>("VALUE_ARGUMENT_NAME", KtValueArgumentName.class);
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. 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.PsiElement
import com.intellij.psi.stubs.StubElement
import com.intellij.psi.stubs.StubInputStream
import com.intellij.psi.stubs.StubOutputStream
import org.jetbrains.kotlin.psi.KtValueArgument
import org.jetbrains.kotlin.psi.stubs.KotlinValueArgumentStub
import org.jetbrains.kotlin.psi.stubs.impl.KotlinValueArgumentStubImpl
class KtValueArgumentElementType<T : KtValueArgument>(debugName: String, psiClass: Class<T>) :
KtStubElementType<KotlinValueArgumentStub<T>, T>(debugName, psiClass, KotlinValueArgumentStub::class.java) {
override fun createStub(psi: T, parentStub: StubElement<PsiElement>?): KotlinValueArgumentStub<T> {
return KotlinValueArgumentStubImpl(parentStub, this, psi.isSpread)
}
override fun serialize(stub: KotlinValueArgumentStub<T>, dataStream: StubOutputStream) {
dataStream.writeBoolean(stub.isSpread())
}
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<PsiElement>?): KotlinValueArgumentStub<T> {
val isSpread = dataStream.readBoolean()
return KotlinValueArgumentStubImpl(parentStub, this, isSpread)
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. 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.KtValueArgument
import org.jetbrains.kotlin.psi.stubs.KotlinValueArgumentStub
import org.jetbrains.kotlin.psi.stubs.elements.KtValueArgumentElementType
class KotlinValueArgumentStubImpl<T : KtValueArgument>(
parent: StubElement<out PsiElement>?,
elementType: KtValueArgumentElementType<T>,
private val isSpread: Boolean
) : KotlinPlaceHolderStubImpl<T>(parent, elementType), KotlinValueArgumentStub<T> {
override fun isSpread(): Boolean = isSpread
}