diff --git a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java index 28053ceb342..c89f242b20d 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java +++ b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java @@ -92,7 +92,7 @@ public interface KtNodeTypes { IElementType CHARACTER_CONSTANT = KtStubElementTypes.CHARACTER_CONSTANT; IElementType INTEGER_CONSTANT = KtStubElementTypes.INTEGER_CONSTANT; - KtNodeType STRING_TEMPLATE = new KtNodeType("STRING_TEMPLATE", KtStringTemplateExpression.class); + 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); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtStringTemplateExpression.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtStringTemplateExpression.java index 0b01e457b6d..d49a8552a08 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtStringTemplateExpression.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtStringTemplateExpression.java @@ -22,16 +22,28 @@ import com.intellij.psi.LiteralTextEscaper; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.tree.TokenSet; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.lexer.KtTokens; +import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; +import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; -public class KtStringTemplateExpression extends KtExpressionImpl implements PsiLanguageInjectionHost { +public class KtStringTemplateExpression extends KtElementImplStub> implements KtExpression, PsiLanguageInjectionHost { private static final TokenSet CLOSE_QUOTE_TOKEN_SET = TokenSet.create(KtTokens.CLOSING_QUOTE); public KtStringTemplateExpression(@NotNull ASTNode node) { super(node); } + public KtStringTemplateExpression(@NotNull KotlinPlaceHolderStub stub) { + super(stub, KtStubElementTypes.STRING_TEMPLATE); + } + + @Override + public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException { + return KtExpressionImpl.Companion.replaceExpression(this, newElement, true, super::replace); + } + @Override public R accept(@NotNull KtVisitor visitor, D data) { return visitor.visitStringTemplateExpression(this, data); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 0036d1fe51f..dbdfac02c8f 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -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 = 131 + const val SOURCE_STUB_VERSION = 132 // 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). diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStringTemplateExpressionElementType.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStringTemplateExpressionElementType.kt new file mode 100644 index 00000000000..3713f936143 --- /dev/null +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStringTemplateExpressionElementType.kt @@ -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.elements + +import com.intellij.lang.ASTNode +import org.jetbrains.annotations.NonNls +import org.jetbrains.kotlin.psi.KtStringTemplateExpression + +class KtStringTemplateExpressionElementType(@NonNls debugName: String) : + KtPlaceHolderStubElementType(debugName, KtStringTemplateExpression::class.java) { + + override fun shouldCreateStub(node: ASTNode): Boolean { + if (node.treeParent?.elementType != KtStubElementTypes.VALUE_ARGUMENT) return false + return super.shouldCreateStub(node) + } +} diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java index 9337b85874b..a34fd57874e 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java @@ -135,6 +135,9 @@ public interface KtStubElementTypes { KtConstantExpressionElementType CHARACTER_CONSTANT = new KtConstantExpressionElementType("CHARACTER_CONSTANT"); KtConstantExpressionElementType INTEGER_CONSTANT = new KtConstantExpressionElementType("INTEGER_CONSTANT"); + KtPlaceHolderStubElementType STRING_TEMPLATE = + new KtStringTemplateExpressionElementType("STRING_TEMPLATE"); + KtScriptElementType SCRIPT = new KtScriptElementType("SCRIPT"); TokenSet DECLARATION_TYPES = diff --git a/idea/testData/stubs/AnnotationValues.expected b/idea/testData/stubs/AnnotationValues.expected index 9bdb548f2a1..cd6176bfdcb 100644 --- a/idea/testData/stubs/AnnotationValues.expected +++ b/idea/testData/stubs/AnnotationValues.expected @@ -109,8 +109,11 @@ PsiJetFileStubImpl[package=test] REFERENCE_EXPRESSION[referencedName=StringLiteral] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + STRING_TEMPLATE VALUE_ARGUMENT + STRING_TEMPLATE VALUE_ARGUMENT + STRING_TEMPLATE CLASS[fqName=test.E, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=E, superNames=[]] MODIFIER_LIST[enum] CLASS_BODY @@ -279,6 +282,7 @@ PsiJetFileStubImpl[package=test] REFERENCE_EXPRESSION[referencedName=Outer] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + STRING_TEMPLATE VALUE_ARGUMENT VALUE_ARGUMENT_NAME REFERENCE_EXPRESSION[referencedName=nested] diff --git a/idea/testData/stubs/AnnotationWithValue.expected b/idea/testData/stubs/AnnotationWithValue.expected index bdab44940a3..9736b6b08e4 100644 --- a/idea/testData/stubs/AnnotationWithValue.expected +++ b/idea/testData/stubs/AnnotationWithValue.expected @@ -22,6 +22,8 @@ PsiJetFileStubImpl[package=] REFERENCE_EXPRESSION[referencedName=Test] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + STRING_TEMPLATE VALUE_ARGUMENT VALUE_ARGUMENT_NAME REFERENCE_EXPRESSION[referencedName=other] + STRING_TEMPLATE diff --git a/idea/testData/stubs/Contracts.expected b/idea/testData/stubs/Contracts.expected index a0fe0113a20..748762f93b4 100644 --- a/idea/testData/stubs/Contracts.expected +++ b/idea/testData/stubs/Contracts.expected @@ -8,6 +8,7 @@ PsiJetFileStubImpl[package=test] REFERENCE_EXPRESSION[referencedName=Suppress] VALUE_ARGUMENT_LIST VALUE_ARGUMENT + STRING_TEMPLATE PACKAGE_DIRECTIVE REFERENCE_EXPRESSION[referencedName=test] IMPORT_LIST