Use a single AnnotatedCallableKind enum item for property

This commit is contained in:
Yan Zhulanow
2015-08-27 18:15:14 +03:00
parent 97e4c097ba
commit e7703df0b6
14 changed files with 130 additions and 118 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.decompiler
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassIdWithTarget
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind
@@ -25,7 +26,7 @@ import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
import org.jetbrains.kotlin.types.JetType
public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndConstantLoader<ClassId, Unit> {
public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget> {
override fun loadClassAnnotations(
classProto: ProtoBuf.Class, nameResolver: NameResolver
@@ -37,9 +38,8 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
proto: ProtoBuf.Callable,
nameResolver: NameResolver,
kind: AnnotatedCallableKind
): List<ClassId> {
if (kind == AnnotatedCallableKind.PROPERTY_FIELD) return emptyList()
return proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty().map { nameResolver.getClassId(it.getId()) }
): List<ClassIdWithTarget> {
return proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty().map { ClassIdWithTarget(nameResolver.getClassId(it.id), null) }
}
override fun loadValueParameterAnnotations(
@@ -102,23 +102,9 @@ private class CallableClsStubBuilder(
val modifierListStubImpl = createModifierListStubForDeclaration(callableStub, callableProto.getFlags(), relevantModifiers)
fun createAnnotationStubs(kind: AnnotatedCallableKind) {
val annotationIds = c.components.annotationLoader.loadCallableAnnotations(protoContainer, callableProto, c.nameResolver, kind)
val target = if (kind == AnnotatedCallableKind.PROPERTY_FIELD) AnnotationUseSiteTarget.FIELD else null
createAnnotationStubs(annotationIds,
modifierListStubImpl,
needWrappingAnnotationEntries = isPrimaryConstructor,
target = target)
}
val kind = callableProto.annotatedCallableKind
if (kind == AnnotatedCallableKind.PROPERTY) {
createAnnotationStubs(AnnotatedCallableKind.PROPERTY_SYNTHETIC_FUNCTION)
createAnnotationStubs(AnnotatedCallableKind.PROPERTY_FIELD)
}
else {
createAnnotationStubs(kind)
}
val annotationIds = c.components.annotationLoader.loadCallableAnnotations(protoContainer, callableProto, c.nameResolver, kind)
createTargetedAnnotationStubs(annotationIds, modifierListStubImpl, needWrappingAnnotationEntries = isPrimaryConstructor)
}
private fun doCreateCallableStub(): StubElement<out PsiElement> {
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.load.kotlin.AbstractBinaryClassAnnotationAndConstantLoader
import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
@@ -31,9 +32,11 @@ import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
import org.jetbrains.kotlin.storage.LockBasedStorageManager
data class ClassIdWithTarget(val classId: ClassId, val target: AnnotationUseSiteTarget?)
class ClsStubBuilderComponents(
val classDataFinder: ClassDataFinder,
val annotationLoader: AnnotationAndConstantLoader<ClassId, Unit>
val annotationLoader: AnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget>
) {
fun createContext(
nameResolver: NameResolver,
@@ -92,7 +95,7 @@ private fun ClsStubBuilderContext.child(nameResolver: NameResolver): ClsStubBuil
class AnnotationLoaderForStubBuilder(
kotlinClassFinder: KotlinClassFinder,
errorReporter: ErrorReporter
) : AbstractBinaryClassAnnotationAndConstantLoader<ClassId, Unit>(
) : AbstractBinaryClassAnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget>(
LockBasedStorageManager.NO_LOCKS, kotlinClassFinder, errorReporter) {
override fun loadClassAnnotations(
@@ -116,4 +119,11 @@ class AnnotationLoaderForStubBuilder(
result.add(annotationClassId)
return null
}
override fun loadPropertyAnnotations(propertyAnnotations: List<ClassId>, fieldAnnotations: List<ClassId>): List<ClassIdWithTarget> {
return propertyAnnotations.map { ClassIdWithTarget(it, null) } +
fieldAnnotations.map { ClassIdWithTarget(it, AnnotationUseSiteTarget.FIELD) }
}
override fun transformAnnotations(annotations: List<ClassId>) = annotations.map { ClassIdWithTarget(it, null) }
}
@@ -171,11 +171,14 @@ fun createModifierListStub(
)
}
fun createAnnotationStubs(
annotationIds: List<ClassId>,
fun createAnnotationStubs(annotationIds: List<ClassId>, parent: KotlinStubBaseImpl<*>, needWrappingAnnotationEntries: Boolean = false) {
return createTargetedAnnotationStubs(annotationIds.map { ClassIdWithTarget(it, null) }, parent, needWrappingAnnotationEntries)
}
fun createTargetedAnnotationStubs(
annotationIds: List<ClassIdWithTarget>,
parent: KotlinStubBaseImpl<*>,
needWrappingAnnotationEntries: Boolean = false,
target: AnnotationUseSiteTarget? = null
needWrappingAnnotationEntries: Boolean = false
) {
if (annotationIds.isEmpty()) return
@@ -183,8 +186,8 @@ fun createAnnotationStubs(
if (needWrappingAnnotationEntries) KotlinPlaceHolderStubImpl<JetAnnotation>(parent, JetStubElementTypes.ANNOTATION)
else parent
annotationIds.forEach {
annotationClassId ->
annotationIds.forEach { annotation ->
val (annotationClassId, target) = annotation
val annotationEntryStubImpl = KotlinAnnotationEntryStubImpl(
entriesParent,
shortName = annotationClassId.getShortClassName().ref(),
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.ModuleParameters
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
import org.jetbrains.kotlin.name.ClassId
@@ -43,7 +44,7 @@ public abstract class DeserializerForDecompilerBase(
protected abstract val classDataFinder: ClassDataFinder
protected abstract val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>>
protected abstract val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget>
protected val storageManager: StorageManager = LockBasedStorageManager.NO_LOCKS