diff --git a/compiler/psi/src/org/jetbrains/kotlin/ElementTypeUtils.kt b/compiler/psi/src/org/jetbrains/kotlin/ElementTypeUtils.kt index 8c71076b724..9962944a2d6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/ElementTypeUtils.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/ElementTypeUtils.kt @@ -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 } diff --git a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java index 3705c99c883..bb87b10dded 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java +++ b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java @@ -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); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCallableReferenceExpression.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCallableReferenceExpression.java index b1546719e34..eff9f6331cb 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCallableReferenceExpression.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCallableReferenceExpression.java @@ -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 accept(@NotNull KtVisitor visitor, D data) { return visitor.visitCallableReferenceExpression(this, data); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.java new file mode 100644 index 00000000000..5b374b99e83 --- /dev/null +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.java @@ -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 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 accept(@NotNull KtVisitor 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; + } +} diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.kt deleted file mode 100644 index b12f2019753..00000000000 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassLiteralExpression.kt +++ /dev/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 accept(visitor: KtVisitor, data: D): R { - return visitor.visitClassLiteralExpression(this, data) - } -} diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt index c9c3f96e930..ccd637f471a 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDoubleColonExpression.kt @@ -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 diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java index 5a69d5a1ec6..ecfb0f19b22 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtValueArgument.java @@ -56,7 +56,9 @@ public class KtValueArgument extends KtElementImplStub { fun value(): String } +interface KotlinClassLiteralExpressionStub : StubElement + interface KotlinTypeProjectionStub : StubElement { fun getProjectionKind(): KtProjectionKind } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtClassLiteralExpressionElementType.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtClassLiteralExpressionElementType.kt new file mode 100644 index 00000000000..5751bf9efae --- /dev/null +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtClassLiteralExpressionElementType.kt @@ -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( + 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) + } +} \ No newline at end of file diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtDotQualifiedExpressionElementType.java b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtDotQualifiedExpressionElementType.java index 4b11ce7ecd7..2f370e4ade2 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtDotQualifiedExpressionElementType.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtDotQualifiedExpressionElementType.java @@ -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); 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 8e558e60c92..bfdeb87504a 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 @@ -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 STRING_TEMPLATE = new KtStringTemplateExpressionElementType("STRING_TEMPLATE"); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassLiteralExpressionStubImpl.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassLiteralExpressionStubImpl.kt new file mode 100644 index 00000000000..a199b4fcfe4 --- /dev/null +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinClassLiteralExpressionStubImpl.kt @@ -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? +) : KotlinStubBaseImpl(parent, KtStubElementTypes.CLASS_LITERAL_EXPRESSION), KotlinClassLiteralExpressionStub \ No newline at end of file