Minor, rename PackagePartSource -> BinarySource

This commit is contained in:
Alexander Udalov
2016-04-06 15:45:58 +03:00
parent ac92be12c6
commit 7620d66019
17 changed files with 36 additions and 37 deletions
@@ -67,5 +67,5 @@ fun ClassDescriptor.getParentJavaStaticClassScope(): LazyJavaStaticClassScope? {
} }
fun DeserializedCallableMemberDescriptor.getImplClassNameForDeserialized(): Name? { fun DeserializedCallableMemberDescriptor.getImplClassNameForDeserialized(): Name? {
return (packagePartSource as? JvmPackagePartSource)?.simpleName return (containerSource as? JvmPackagePartSource)?.simpleName
} }
@@ -233,14 +233,14 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
} }
if (isConst!! && container is ProtoContainer.Package) { if (isConst!! && container is ProtoContainer.Package) {
// Const properties in multifile classes are generated into the facade class // Const properties in multifile classes are generated into the facade class
val facadeClassName = (container.packagePartSource as? JvmPackagePartSource)?.facadeClassName val facadeClassName = (container.source as? JvmPackagePartSource)?.facadeClassName
if (facadeClassName != null) { if (facadeClassName != null) {
// Converting '/' to '.' is fine here because the facade class has a top level ClassId // Converting '/' to '.' is fine here because the facade class has a top level ClassId
return ClassId.topLevel(FqName(facadeClassName.internalName.replace('/', '.'))) return ClassId.topLevel(FqName(facadeClassName.internalName.replace('/', '.')))
} }
} }
} }
return ((container as? ProtoContainer.Package)?.packagePartSource as? JvmPackagePartSource)?.classId return ((container as? ProtoContainer.Package)?.source as? JvmPackagePartSource)?.classId
} }
private fun loadAnnotationsAndInitializers(kotlinClass: KotlinJvmBinaryClass): Storage<A, C> { private fun loadAnnotationsAndInitializers(kotlinClass: KotlinJvmBinaryClass): Storage<A, C> {
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource import org.jetbrains.kotlin.serialization.deserialization.descriptors.BinarySource
class JvmPackagePartSource(val className: JvmClassName, val facadeClassName: JvmClassName?) : PackagePartSource { class JvmPackagePartSource(val className: JvmClassName, val facadeClassName: JvmClassName?) : BinarySource {
constructor(kotlinClass: KotlinJvmBinaryClass) : this( constructor(kotlinClass: KotlinJvmBinaryClass) : this(
JvmClassName.byClassId(kotlinClass.classId), JvmClassName.byClassId(kotlinClass.classId),
kotlinClass.classHeader.multifileClassName?.let { kotlinClass.classHeader.multifileClassName?.let {
@@ -52,7 +52,7 @@ class BuiltInsPackageFragment(
override fun computeMemberScope() = override fun computeMemberScope() =
DeserializedPackageMemberScope( DeserializedPackageMemberScope(
this, proto.`package`, nameResolver, packagePartSource = null, components = components, this, proto.`package`, nameResolver, containerSource = null, components = components,
classNames = { classDataFinder.allClassIds.filter { classId -> !classId.isNestedClass }.map { it.shortClassName } } classNames = { classDataFinder.allClassIds.filter { classId -> !classId.isNestedClass }.map { it.shortClassName } }
) )
} }
@@ -56,7 +56,7 @@ class ClassDeserializer(private val components: DeserializationComponents) {
if (!fragment.hasTopLevelClass(classId.shortClassName)) return null if (!fragment.hasTopLevelClass(classId.shortClassName)) return null
} }
components.createContext(fragment, nameResolver, TypeTable(classProto.typeTable), packagePartSource = null) components.createContext(fragment, nameResolver, TypeTable(classProto.typeTable), containerSource = null)
} }
return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement) return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement)
@@ -47,7 +47,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
proto, proto,
c.nameResolver, c.nameResolver,
c.typeTable, c.typeTable,
c.packagePartSource c.containerSource
) )
val local = c.childContext(property, proto.typeParameterList) val local = c.childContext(property, proto.typeParameterList)
@@ -147,7 +147,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
else Annotations.EMPTY else Annotations.EMPTY
val function = DeserializedSimpleFunctionDescriptor( val function = DeserializedSimpleFunctionDescriptor(
c.containingDeclaration, /* original = */ null, annotations, c.nameResolver.getName(proto.name), c.containingDeclaration, /* original = */ null, annotations, c.nameResolver.getName(proto.name),
Deserialization.memberKind(Flags.MEMBER_KIND.get(flags)), proto, c.nameResolver, c.typeTable, c.packagePartSource Deserialization.memberKind(Flags.MEMBER_KIND.get(flags)), proto, c.nameResolver, c.typeTable, c.containerSource
) )
val local = c.childContext(function, proto.typeParameterList) val local = c.childContext(function, proto.typeParameterList)
function.initialize( function.initialize(
@@ -175,7 +175,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
val classDescriptor = c.containingDeclaration as ClassDescriptor val classDescriptor = c.containingDeclaration as ClassDescriptor
val descriptor = DeserializedConstructorDescriptor( val descriptor = DeserializedConstructorDescriptor(
classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION), classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION),
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable, c.packagePartSource isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable, c.containerSource
) )
val local = c.childContext(descriptor, listOf()) val local = c.childContext(descriptor, listOf())
descriptor.initialize( descriptor.initialize(
@@ -240,7 +240,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
} }
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) { private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) {
is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.packagePartSource) is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.containerSource)
is DeserializedClassDescriptor -> thisAsProtoContainer is DeserializedClassDescriptor -> thisAsProtoContainer
else -> null // TODO: support annotations on lambdas and their parameters else -> null // TODO: support annotations on lambdas and their parameters
} }
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.Flags import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource import org.jetbrains.kotlin.serialization.deserialization.descriptors.BinarySource
sealed class ProtoContainer( sealed class ProtoContainer(
val nameResolver: NameResolver, val nameResolver: NameResolver,
@@ -45,7 +45,7 @@ sealed class ProtoContainer(
val fqName: FqName, val fqName: FqName,
nameResolver: NameResolver, nameResolver: NameResolver,
typeTable: TypeTable, typeTable: TypeTable,
val packagePartSource: PackagePartSource? val source: BinarySource?
) : ProtoContainer(nameResolver, typeTable) { ) : ProtoContainer(nameResolver, typeTable) {
override fun debugFqName(): FqName = fqName override fun debugFqName(): FqName = fqName
} }
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.PackagePartSource import org.jetbrains.kotlin.serialization.deserialization.descriptors.BinarySource
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
class DeserializationComponents( class DeserializationComponents(
@@ -49,9 +49,9 @@ class DeserializationComponents(
descriptor: PackageFragmentDescriptor, descriptor: PackageFragmentDescriptor,
nameResolver: NameResolver, nameResolver: NameResolver,
typeTable: TypeTable, typeTable: TypeTable,
packagePartSource: PackagePartSource? containerSource: BinarySource?
): DeserializationContext = ): DeserializationContext =
DeserializationContext(this, nameResolver, descriptor, typeTable, packagePartSource, DeserializationContext(this, nameResolver, descriptor, typeTable, containerSource,
parentTypeDeserializer = null, typeParameters = listOf()) parentTypeDeserializer = null, typeParameters = listOf())
} }
@@ -61,7 +61,7 @@ class DeserializationContext(
val nameResolver: NameResolver, val nameResolver: NameResolver,
val containingDeclaration: DeclarationDescriptor, val containingDeclaration: DeclarationDescriptor,
val typeTable: TypeTable, val typeTable: TypeTable,
val packagePartSource: PackagePartSource?, val containerSource: BinarySource?,
parentTypeDeserializer: TypeDeserializer?, parentTypeDeserializer: TypeDeserializer?,
typeParameters: List<ProtoBuf.TypeParameter> typeParameters: List<ProtoBuf.TypeParameter>
) { ) {
@@ -78,7 +78,7 @@ class DeserializationContext(
nameResolver: NameResolver = this.nameResolver, nameResolver: NameResolver = this.nameResolver,
typeTable: TypeTable = this.typeTable typeTable: TypeTable = this.typeTable
) = DeserializationContext( ) = DeserializationContext(
components, nameResolver, descriptor, typeTable, this.packagePartSource, components, nameResolver, descriptor, typeTable, this.containerSource,
parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
) )
} }
@@ -35,12 +35,11 @@ interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor {
val typeTable: TypeTable val typeTable: TypeTable
// Information about the origin of this top-level callable or null, if it's not top-level or there's no such information. // Information about the origin of this callable's container (class or package part on JVM) or null if there's no such information.
// On JVM, this is JvmPackagePartSource which contains the internal name of the package part class val containerSource: BinarySource?
val packagePartSource: PackagePartSource?
} }
interface PackagePartSource interface BinarySource
class DeserializedSimpleFunctionDescriptor( class DeserializedSimpleFunctionDescriptor(
containingDeclaration: DeclarationDescriptor, containingDeclaration: DeclarationDescriptor,
@@ -51,7 +50,7 @@ class DeserializedSimpleFunctionDescriptor(
override val proto: ProtoBuf.Function, override val proto: ProtoBuf.Function,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable, override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource? override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) { SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) {
@@ -64,7 +63,7 @@ class DeserializedSimpleFunctionDescriptor(
): FunctionDescriptorImpl { ): FunctionDescriptorImpl {
return DeserializedSimpleFunctionDescriptor( return DeserializedSimpleFunctionDescriptor(
newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind,
proto, nameResolver, typeTable, packagePartSource proto, nameResolver, typeTable, containerSource
) )
} }
} }
@@ -83,7 +82,7 @@ class DeserializedPropertyDescriptor(
override val proto: ProtoBuf.Property, override val proto: ProtoBuf.Property,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable, override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource? override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations, PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) { modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) {
@@ -97,7 +96,7 @@ class DeserializedPropertyDescriptor(
): PropertyDescriptorImpl { ): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor( return DeserializedPropertyDescriptor(
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst, newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst,
proto, nameResolver, typeTable, packagePartSource proto, nameResolver, typeTable, containerSource
) )
} }
} }
@@ -111,7 +110,7 @@ class DeserializedConstructorDescriptor(
override val proto: ProtoBuf.Constructor, override val proto: ProtoBuf.Constructor,
override val nameResolver: NameResolver, override val nameResolver: NameResolver,
override val typeTable: TypeTable, override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource? override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) { ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) {
@@ -124,7 +123,7 @@ class DeserializedConstructorDescriptor(
): DeserializedConstructorDescriptor { ): DeserializedConstructorDescriptor {
return DeserializedConstructorDescriptor( return DeserializedConstructorDescriptor(
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
proto, nameResolver, typeTable, packagePartSource proto, nameResolver, typeTable, containerSource
) )
} }
@@ -36,11 +36,11 @@ open class DeserializedPackageMemberScope(
packageDescriptor: PackageFragmentDescriptor, packageDescriptor: PackageFragmentDescriptor,
proto: ProtoBuf.Package, proto: ProtoBuf.Package,
nameResolver: NameResolver, nameResolver: NameResolver,
packagePartSource: PackagePartSource?, containerSource: BinarySource?,
components: DeserializationComponents, components: DeserializationComponents,
classNames: () -> Collection<Name> classNames: () -> Collection<Name>
) : DeserializedMemberScope( ) : DeserializedMemberScope(
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), packagePartSource), components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), containerSource),
proto.functionList, proto.propertyList proto.functionList, proto.propertyList
) { ) {
private val packageFqName = packageDescriptor.fqName private val packageFqName = packageDescriptor.fqName
@@ -125,7 +125,7 @@ internal sealed class JvmPropertySignature {
return "$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName) return "$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName)
} }
if (descriptor.visibility == Visibilities.PRIVATE && containingDeclaration is PackageFragmentDescriptor) { if (descriptor.visibility == Visibilities.PRIVATE && containingDeclaration is PackageFragmentDescriptor) {
val packagePartSource = (descriptor as DeserializedPropertyDescriptor).packagePartSource val packagePartSource = (descriptor as DeserializedPropertyDescriptor).containerSource
if (packagePartSource is JvmPackagePartSource && packagePartSource.facadeClassName != null) { if (packagePartSource is JvmPackagePartSource && packagePartSource.facadeClassName != null) {
return "$" + packagePartSource.simpleName.asString() return "$" + packagePartSource.simpleName.asString()
} }
@@ -46,7 +46,7 @@ fun <R> Function<R>.reflect(): KFunction<R>? {
val moduleData = javaClass.getOrCreateModule() val moduleData = javaClass.getOrCreateModule()
val context = DeserializationContext( val context = DeserializationContext(
moduleData.deserialization, nameResolver, moduleData.module, moduleData.deserialization, nameResolver, moduleData.module,
typeTable = TypeTable(proto.typeTable), packagePartSource = null, parentTypeDeserializer = null, typeParameters = listOf() typeTable = TypeTable(proto.typeTable), containerSource = null, parentTypeDeserializer = null, typeParameters = listOf()
) )
val descriptor = MemberDeserializer(context).loadFunction(proto) val descriptor = MemberDeserializer(context).loadFunction(proto)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -59,7 +59,7 @@ class KotlinBuiltInDeserializerForDecompiler(
} }
val membersScope = DeserializedPackageMemberScope( val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(facadeFqName), proto.`package`, nameResolver, packagePartSource = null, createDummyPackageFragment(facadeFqName), proto.`package`, nameResolver, containerSource = null,
components = deserializationComponents components = deserializationComponents
) { emptyList() } ) { emptyList() }
@@ -53,7 +53,7 @@ class KotlinBuiltInStubBuilder : ClsStubBuilder() {
val fileStub = createFileStub(packageFqName) val fileStub = createFileStub(packageFqName)
createCallableStubs( createCallableStubs(
fileStub, context, fileStub, context,
ProtoContainer.Package(packageFqName, context.nameResolver, context.typeTable, packagePartSource = null), ProtoContainer.Package(packageFqName, context.nameResolver, context.typeTable, source = null),
packageProto.functionList, packageProto.propertyList packageProto.functionList, packageProto.propertyList
) )
for (classProto in file.classesToDecompile) { for (classProto in file.classesToDecompile) {
@@ -81,7 +81,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
val content = file.contentsToByteArray(false) val content = file.contentsToByteArray(false)
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry) val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
val membersScope = DeserializedPackageMemberScope( val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, packagePartSource = null, createDummyPackageFragment(packageFqName), packageProto, nameResolver, containerSource = null,
components = deserializationComponents components = deserializationComponents
) { emptyList() } ) { emptyList() }
return membersScope.getContributedDescriptors().toList() return membersScope.getContributedDescriptors().toList()
@@ -55,7 +55,7 @@ fun createPackageFacadeStub(
): KotlinFileStubImpl { ): KotlinFileStubImpl {
val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot) val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot)
setupFileStub(fileStub, packageFqName) setupFileStub(fileStub, packageFqName)
createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable, packagePartSource = null), createCallableStubs(fileStub, c, ProtoContainer.Package(packageFqName, c.nameResolver, c.typeTable, source = null),
packageProto.functionList, packageProto.propertyList) packageProto.functionList, packageProto.propertyList)
return fileStub return fileStub
} }
@@ -43,7 +43,7 @@ class KotlinJavascriptPackageFragment(
loadResourceSure(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName)).use { packageStream -> loadResourceSure(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName)).use { packageStream ->
val packageProto = ProtoBuf.Package.parseFrom(packageStream, JsSerializerProtocol.extensionRegistry) val packageProto = ProtoBuf.Package.parseFrom(packageStream, JsSerializerProtocol.extensionRegistry)
DeserializedPackageMemberScope( DeserializedPackageMemberScope(
this, packageProto, nameResolver, packagePartSource = null, components = components, this, packageProto, nameResolver, containerSource = null, components = components,
classNames = { loadClassNames() } classNames = { loadClassNames() }
) )
} }