From 4b3999bf6cb86cffc99c3293563fc953c8629561 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 14 Aug 2015 20:03:44 +0300 Subject: [PATCH] Serialize annotation target psi element --- .../kotlin/psi/JetAnnotationUseSiteTarget.kt | 14 +++++- .../kotlin/psi/stubs/StubInterfaces.kt | 4 ++ .../JetAnnotationUseSiteTargetElementType.kt | 45 +++++++++++++++++++ .../stubs/elements/JetStubElementTypes.java | 3 +- .../impl/KotlinAnnotationUseSiteStubImpl.kt | 33 ++++++++++++++ 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetAnnotationUseSiteTargetElementType.kt create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinAnnotationUseSiteStubImpl.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotationUseSiteTarget.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotationUseSiteTarget.kt index 93057fa3b76..3ee0d7ce1a3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotationUseSiteTarget.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetAnnotationUseSiteTarget.kt @@ -22,18 +22,28 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.lexer.JetKeywordToken import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub +import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationUseSiteTargetStub import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes -public class JetAnnotationUseSiteTarget : JetElementImplStub> { +public class JetAnnotationUseSiteTarget : JetElementImplStub { constructor(node: ASTNode) : super(node) - constructor(stub: KotlinPlaceHolderStub) : super(stub, JetStubElementTypes.ANNOTATION_TARGET) + constructor(stub: KotlinAnnotationUseSiteTargetStub) : super(stub, JetStubElementTypes.ANNOTATION_TARGET) override fun accept(visitor: JetVisitor, data: D) = visitor.visitAnnotationUseSiteTarget(this, data) public fun getAnnotationUseSiteTarget(): AnnotationUseSiteTarget { + val targetString = stub?.getUseSiteTarget() + if (targetString != null) { + try { + return AnnotationUseSiteTarget.valueOf(targetString) + } catch (e: IllegalArgumentException) { + // Ok, resolve via node tree + } + } + val node = getFirstChild().getNode() return when (node.getElementType()) { JetTokens.FIELD_KEYWORD -> AnnotationUseSiteTarget.FIELD diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt index 2e6e65c9894..4840377a248 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt @@ -57,6 +57,10 @@ public interface KotlinAnnotationEntryStub : StubElement { public fun hasValueArguments(): Boolean } +public interface KotlinAnnotationUseSiteTargetStub : StubElement { + public fun getUseSiteTarget(): String +} + public interface KotlinFunctionStub : KotlinCallableStubBase { public fun hasBlockBody(): Boolean public fun hasBody(): Boolean diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetAnnotationUseSiteTargetElementType.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetAnnotationUseSiteTargetElementType.kt new file mode 100644 index 00000000000..fb4606383f6 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetAnnotationUseSiteTargetElementType.kt @@ -0,0 +1,45 @@ +/* + * 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.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 com.intellij.util.io.StringRef +import org.jetbrains.kotlin.psi.JetAnnotationUseSiteTarget +import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationUseSiteTargetStub +import org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationUseSiteTargetStubImpl + +public class JetAnnotationUseSiteTargetElementType(debugName: String) : JetStubElementType( + debugName, javaClass(), javaClass() +) { + + override fun createStub(psi: JetAnnotationUseSiteTarget, parentStub: StubElement): KotlinAnnotationUseSiteTargetStub { + val useSiteTarget = psi.getAnnotationUseSiteTarget().name() + return KotlinAnnotationUseSiteTargetStubImpl(parentStub, StringRef.fromString(useSiteTarget)!!) + } + + override fun serialize(stub: KotlinAnnotationUseSiteTargetStub, dataStream: StubOutputStream) { + dataStream.writeName(stub.getUseSiteTarget()) + } + + override fun deserialize(dataStream: StubInputStream, parentStub: StubElement): KotlinAnnotationUseSiteTargetStub { + val useSiteTarget = dataStream.readName() + return KotlinAnnotationUseSiteTargetStubImpl(parentStub, useSiteTarget) + } +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetStubElementTypes.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetStubElementTypes.java index aa2bdf5575f..637cddd8d1d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetStubElementTypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetStubElementTypes.java @@ -50,8 +50,7 @@ public interface JetStubElementTypes { JetPlaceHolderStubElementType ANNOTATION = new JetPlaceHolderStubElementType("ANNOTATION", JetAnnotation.class); - JetPlaceHolderStubElementType ANNOTATION_TARGET = - new JetPlaceHolderStubElementType("ANNOTATION_TARGET", JetAnnotationUseSiteTarget.class); + JetAnnotationUseSiteTargetElementType ANNOTATION_TARGET = new JetAnnotationUseSiteTargetElementType("ANNOTATION_TARGET"); JetPlaceHolderStubElementType CLASS_BODY = new JetPlaceHolderStubElementType("CLASS_BODY", JetClassBody.class); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinAnnotationUseSiteStubImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinAnnotationUseSiteStubImpl.kt new file mode 100644 index 00000000000..2c8ccd9bbc8 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/impl/KotlinAnnotationUseSiteStubImpl.kt @@ -0,0 +1,33 @@ +/* + * 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.stubs.impl + +import com.intellij.psi.PsiElement +import com.intellij.psi.stubs.StubElement +import com.intellij.util.io.StringRef +import org.jetbrains.kotlin.psi.JetAnnotationUseSiteTarget +import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationUseSiteTargetStub +import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes + +public class KotlinAnnotationUseSiteTargetStubImpl( + parent: StubElement?, + private val target: StringRef +) : KotlinStubBaseImpl(parent, JetStubElementTypes.ANNOTATION_TARGET), KotlinAnnotationUseSiteTargetStub { + + override fun getUseSiteTarget() = target.string + +}