Make stubs for string entries (KT-23738)

This commit is contained in:
Nikolay Krasko
2018-10-17 14:53:54 +03:00
parent 37d7e618da
commit efa59bfc7e
15 changed files with 118 additions and 8 deletions
@@ -92,11 +92,11 @@ public interface KtNodeTypes {
IElementType CHARACTER_CONSTANT = KtStubElementTypes.CHARACTER_CONSTANT;
IElementType INTEGER_CONSTANT = KtStubElementTypes.INTEGER_CONSTANT;
IElementType STRING_TEMPLATE = KtStubElementTypes.STRING_TEMPLATE;
KtNodeType LONG_STRING_TEMPLATE_ENTRY = new KtNodeType("LONG_STRING_TEMPLATE_ENTRY", KtBlockStringTemplateEntry.class);
KtNodeType SHORT_STRING_TEMPLATE_ENTRY = new KtNodeType("SHORT_STRING_TEMPLATE_ENTRY", KtSimpleNameStringTemplateEntry.class);
KtNodeType LITERAL_STRING_TEMPLATE_ENTRY = new KtNodeType("LITERAL_STRING_TEMPLATE_ENTRY", KtLiteralStringTemplateEntry.class);
KtNodeType ESCAPE_STRING_TEMPLATE_ENTRY = new KtNodeType("ESCAPE_STRING_TEMPLATE_ENTRY", KtEscapeStringTemplateEntry.class);
IElementType STRING_TEMPLATE = KtStubElementTypes.STRING_TEMPLATE;
IElementType LONG_STRING_TEMPLATE_ENTRY = KtStubElementTypes.LONG_STRING_TEMPLATE_ENTRY;
IElementType SHORT_STRING_TEMPLATE_ENTRY = KtStubElementTypes.SHORT_STRING_TEMPLATE_ENTRY;
IElementType LITERAL_STRING_TEMPLATE_ENTRY = KtStubElementTypes.LITERAL_STRING_TEMPLATE_ENTRY;
IElementType ESCAPE_STRING_TEMPLATE_ENTRY = KtStubElementTypes.ESCAPE_STRING_TEMPLATE_ENTRY;
KtNodeType PARENTHESIZED = new KtNodeType("PARENTHESIZED", KtParenthesizedExpression.class);
KtNodeType RETURN = new KtNodeType("RETURN", KtReturnExpression.class);
@@ -16,8 +16,8 @@
package org.jetbrains.kotlin.psi
import com.intellij.psi.LiteralTextEscaper
import com.intellij.openapi.util.TextRange
import com.intellij.psi.LiteralTextEscaper
import gnu.trove.TIntArrayList
import org.jetbrains.kotlin.psi.psiUtil.getContentRange
import org.jetbrains.kotlin.psi.psiUtil.isSingleQuoted
@@ -18,12 +18,18 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
public class KtBlockStringTemplateEntry extends KtStringTemplateEntryWithExpression {
public KtBlockStringTemplateEntry(@NotNull ASTNode node) {
super(node);
}
public KtBlockStringTemplateEntry(@NotNull KotlinPlaceHolderWithTextStub<KtBlockStringTemplateEntry> stub) {
super(stub, KtStubElementTypes.LONG_STRING_TEMPLATE_ENTRY);
}
@Override
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
return visitor.visitBlockStringTemplateEntry(this, data);
@@ -19,12 +19,18 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
public class KtEscapeStringTemplateEntry extends KtStringTemplateEntry {
public KtEscapeStringTemplateEntry(@NotNull ASTNode node) {
super(node);
}
public KtEscapeStringTemplateEntry(@NotNull KotlinPlaceHolderWithTextStub<KtEscapeStringTemplateEntry> stub) {
super(stub, KtStubElementTypes.ESCAPE_STRING_TEMPLATE_ENTRY);
}
@Override
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
return visitor.visitEscapeStringTemplateEntry(this, data);
@@ -18,12 +18,18 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
public class KtLiteralStringTemplateEntry extends KtStringTemplateEntry {
public KtLiteralStringTemplateEntry(@NotNull ASTNode node) {
super(node);
}
public KtLiteralStringTemplateEntry(@NotNull KotlinPlaceHolderWithTextStub<KtLiteralStringTemplateEntry> stub) {
super(stub, KtStubElementTypes.LITERAL_STRING_TEMPLATE_ENTRY);
}
@Override
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
return visitor.visitLiteralStringTemplateEntry(this, data);
@@ -18,12 +18,18 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
public class KtSimpleNameStringTemplateEntry extends KtStringTemplateEntryWithExpression {
public KtSimpleNameStringTemplateEntry(@NotNull ASTNode node) {
super(node);
}
public KtSimpleNameStringTemplateEntry(@NotNull KotlinPlaceHolderWithTextStub<KtSimpleNameStringTemplateEntry> stub) {
super(stub, KtStubElementTypes.SHORT_STRING_TEMPLATE_ENTRY);
}
@Override
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
return visitor.visitSimpleNameStringTemplateEntry(this, data);
@@ -17,14 +17,20 @@
package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.stubs.IStubElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
public abstract class KtStringTemplateEntry extends KtElementImpl {
public abstract class KtStringTemplateEntry extends KtElementImplStub<KotlinPlaceHolderWithTextStub<? extends KtStringTemplateEntry>> {
public KtStringTemplateEntry(@NotNull ASTNode node) {
super(node);
}
public KtStringTemplateEntry(@NotNull KotlinPlaceHolderWithTextStub<? extends KtStringTemplateEntry> stub, @NotNull IStubElementType elementType) {
super(stub, elementType);
}
@Nullable
public KtExpression getExpression() {
return findChildByClass(KtExpression.class);
@@ -17,13 +17,21 @@
package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.stubs.IStubElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub;
public abstract class KtStringTemplateEntryWithExpression extends KtStringTemplateEntry {
public KtStringTemplateEntryWithExpression(@NotNull ASTNode node) {
super(node);
}
public KtStringTemplateEntryWithExpression(
@NotNull KotlinPlaceHolderWithTextStub<? extends KtStringTemplateEntryWithExpression> stub,
@NotNull IStubElementType elementType) {
super(stub, elementType);
}
@Override
public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
return visitor.visitStringTemplateEntryWithExpression(this, data);
@@ -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 = 132
const val SOURCE_STUB_VERSION = 133
// 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).
@@ -32,6 +32,10 @@ interface KotlinFileStub : PsiFileStub<KtFile> {
interface KotlinPlaceHolderStub<T : KtElement> : StubElement<T>
interface KotlinPlaceHolderWithTextStub<T : KtElement> : KotlinPlaceHolderStub<T> {
fun text(): String
}
interface KotlinStubWithFqName<T : PsiNamedElement> : NamedStub<T> {
fun getFqName(): FqName?
}
@@ -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.stubs.StubElement
import com.intellij.psi.stubs.StubInputStream
import com.intellij.psi.stubs.StubOutputStream
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.psi.KtElementImplStub
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderWithTextStubImpl
class KtPlaceHolderWithTextStubElementType<T : KtElementImplStub<out StubElement<*>>>(@NonNls debugName: String, psiClass: Class<T>) :
KtStubElementType<KotlinPlaceHolderWithTextStub<T>, T>(debugName, psiClass, KotlinPlaceHolderWithTextStub::class.java) {
override fun createStub(psi: T, parentStub: StubElement<*>): KotlinPlaceHolderWithTextStub<T> {
return KotlinPlaceHolderWithTextStubImpl(parentStub, this, psi.text)
}
override fun serialize(stub: KotlinPlaceHolderWithTextStub<T>, dataStream: StubOutputStream) {
dataStream.writeUTFFast(stub.text())
}
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>): KotlinPlaceHolderWithTextStub<T> {
val text = dataStream.readUTFFast()
return KotlinPlaceHolderWithTextStubImpl(parentStub, this, text)
}
}
@@ -138,6 +138,18 @@ public interface KtStubElementTypes {
KtPlaceHolderStubElementType<KtStringTemplateExpression> STRING_TEMPLATE =
new KtStringTemplateExpressionElementType("STRING_TEMPLATE");
KtPlaceHolderWithTextStubElementType<KtBlockStringTemplateEntry> LONG_STRING_TEMPLATE_ENTRY =
new KtPlaceHolderWithTextStubElementType<>("LONG_STRING_TEMPLATE_ENTRY", KtBlockStringTemplateEntry.class);
KtPlaceHolderWithTextStubElementType<KtSimpleNameStringTemplateEntry> SHORT_STRING_TEMPLATE_ENTRY =
new KtPlaceHolderWithTextStubElementType<>("SHORT_STRING_TEMPLATE_ENTRY", KtSimpleNameStringTemplateEntry.class);
KtPlaceHolderWithTextStubElementType<KtLiteralStringTemplateEntry> LITERAL_STRING_TEMPLATE_ENTRY =
new KtPlaceHolderWithTextStubElementType<>("LITERAL_STRING_TEMPLATE_ENTRY", KtLiteralStringTemplateEntry.class);
KtPlaceHolderWithTextStubElementType<KtEscapeStringTemplateEntry> ESCAPE_STRING_TEMPLATE_ENTRY =
new KtPlaceHolderWithTextStubElementType<>("ESCAPE_STRING_TEMPLATE_ENTRY", KtEscapeStringTemplateEntry.class);
KtScriptElementType SCRIPT = new KtScriptElementType("SCRIPT");
TokenSet DECLARATION_TYPES =
@@ -0,0 +1,19 @@
/*
* 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.stubs.IStubElementType
import com.intellij.psi.stubs.StubElement
import org.jetbrains.kotlin.psi.KtElementImplStub
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderWithTextStub
class KotlinPlaceHolderWithTextStubImpl<T : KtElementImplStub<out StubElement<*>>>(
parent: StubElement<*>,
elementType: IStubElementType<*, *>,
private val text: String
) : KotlinStubBaseImpl<T>(parent, elementType), KotlinPlaceHolderWithTextStub<T> {
override fun text(): String = text
}
+5
View File
@@ -110,10 +110,14 @@ PsiJetFileStubImpl[package=test]
VALUE_ARGUMENT_LIST
VALUE_ARGUMENT
STRING_TEMPLATE
LITERAL_STRING_TEMPLATE_ENTRY[text=some]
VALUE_ARGUMENT
STRING_TEMPLATE
VALUE_ARGUMENT
STRING_TEMPLATE
LITERAL_STRING_TEMPLATE_ENTRY[text=H]
SHORT_STRING_TEMPLATE_ENTRY[text=$CONSTANT]
REFERENCE_EXPRESSION[referencedName=CONSTANT]
CLASS[fqName=test.E, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=E, superNames=[]]
MODIFIER_LIST[enum]
CLASS_BODY
@@ -283,6 +287,7 @@ PsiJetFileStubImpl[package=test]
VALUE_ARGUMENT_LIST
VALUE_ARGUMENT
STRING_TEMPLATE
LITERAL_STRING_TEMPLATE_ENTRY[text=value]
VALUE_ARGUMENT
VALUE_ARGUMENT_NAME
REFERENCE_EXPRESSION[referencedName=nested]
+1
View File
@@ -9,6 +9,7 @@ PsiJetFileStubImpl[package=test]
VALUE_ARGUMENT_LIST
VALUE_ARGUMENT
STRING_TEMPLATE
LITERAL_STRING_TEMPLATE_ENTRY[text=INVISIBLE_MEMBER]
PACKAGE_DIRECTIVE
REFERENCE_EXPRESSION[referencedName=test]
IMPORT_LIST