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? {
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) {
// 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) {
// Converting '/' to '.' is fine here because the facade class has a top level ClassId
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> {
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
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(
JvmClassName.byClassId(kotlinClass.classId),
kotlinClass.classHeader.multifileClassName?.let {
@@ -52,7 +52,7 @@ class BuiltInsPackageFragment(
override fun computeMemberScope() =
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 } }
)
}
@@ -56,7 +56,7 @@ class ClassDeserializer(private val components: DeserializationComponents) {
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)
@@ -47,7 +47,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
proto,
c.nameResolver,
c.typeTable,
c.packagePartSource
c.containerSource
)
val local = c.childContext(property, proto.typeParameterList)
@@ -147,7 +147,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
else Annotations.EMPTY
val function = DeserializedSimpleFunctionDescriptor(
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)
function.initialize(
@@ -175,7 +175,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
val classDescriptor = c.containingDeclaration as ClassDescriptor
val descriptor = DeserializedConstructorDescriptor(
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())
descriptor.initialize(
@@ -240,7 +240,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
}
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
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.serialization.Flags
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(
val nameResolver: NameResolver,
@@ -45,7 +45,7 @@ sealed class ProtoContainer(
val fqName: FqName,
nameResolver: NameResolver,
typeTable: TypeTable,
val packagePartSource: PackagePartSource?
val source: BinarySource?
) : ProtoContainer(nameResolver, typeTable) {
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.resolve.constants.ConstantValue
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
class DeserializationComponents(
@@ -49,9 +49,9 @@ class DeserializationComponents(
descriptor: PackageFragmentDescriptor,
nameResolver: NameResolver,
typeTable: TypeTable,
packagePartSource: PackagePartSource?
containerSource: BinarySource?
): DeserializationContext =
DeserializationContext(this, nameResolver, descriptor, typeTable, packagePartSource,
DeserializationContext(this, nameResolver, descriptor, typeTable, containerSource,
parentTypeDeserializer = null, typeParameters = listOf())
}
@@ -61,7 +61,7 @@ class DeserializationContext(
val nameResolver: NameResolver,
val containingDeclaration: DeclarationDescriptor,
val typeTable: TypeTable,
val packagePartSource: PackagePartSource?,
val containerSource: BinarySource?,
parentTypeDeserializer: TypeDeserializer?,
typeParameters: List<ProtoBuf.TypeParameter>
) {
@@ -78,7 +78,7 @@ class DeserializationContext(
nameResolver: NameResolver = this.nameResolver,
typeTable: TypeTable = this.typeTable
) = DeserializationContext(
components, nameResolver, descriptor, typeTable, this.packagePartSource,
components, nameResolver, descriptor, typeTable, this.containerSource,
parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
)
}
@@ -35,12 +35,11 @@ interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor {
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.
// On JVM, this is JvmPackagePartSource which contains the internal name of the package part class
val packagePartSource: PackagePartSource?
// Information about the origin of this callable's container (class or package part on JVM) or null if there's no such information.
val containerSource: BinarySource?
}
interface PackagePartSource
interface BinarySource
class DeserializedSimpleFunctionDescriptor(
containingDeclaration: DeclarationDescriptor,
@@ -51,7 +50,7 @@ class DeserializedSimpleFunctionDescriptor(
override val proto: ProtoBuf.Function,
override val nameResolver: NameResolver,
override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor,
SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) {
@@ -64,7 +63,7 @@ class DeserializedSimpleFunctionDescriptor(
): FunctionDescriptorImpl {
return DeserializedSimpleFunctionDescriptor(
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 nameResolver: NameResolver,
override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) {
@@ -97,7 +96,7 @@ class DeserializedPropertyDescriptor(
): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor(
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 nameResolver: NameResolver,
override val typeTable: TypeTable,
override val packagePartSource: PackagePartSource?
override val containerSource: BinarySource?
) : DeserializedCallableMemberDescriptor,
ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE) {
@@ -124,7 +123,7 @@ class DeserializedConstructorDescriptor(
): DeserializedConstructorDescriptor {
return DeserializedConstructorDescriptor(
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,
proto: ProtoBuf.Package,
nameResolver: NameResolver,
packagePartSource: PackagePartSource?,
containerSource: BinarySource?,
components: DeserializationComponents,
classNames: () -> Collection<Name>
) : DeserializedMemberScope(
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), packagePartSource),
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), containerSource),
proto.functionList, proto.propertyList
) {
private val packageFqName = packageDescriptor.fqName
@@ -125,7 +125,7 @@ internal sealed class JvmPropertySignature {
return "$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName)
}
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) {
return "$" + packagePartSource.simpleName.asString()
}
@@ -46,7 +46,7 @@ fun <R> Function<R>.reflect(): KFunction<R>? {
val moduleData = javaClass.getOrCreateModule()
val context = DeserializationContext(
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)
@Suppress("UNCHECKED_CAST")
@@ -59,7 +59,7 @@ class KotlinBuiltInDeserializerForDecompiler(
}
val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(facadeFqName), proto.`package`, nameResolver, packagePartSource = null,
createDummyPackageFragment(facadeFqName), proto.`package`, nameResolver, containerSource = null,
components = deserializationComponents
) { emptyList() }
@@ -53,7 +53,7 @@ class KotlinBuiltInStubBuilder : ClsStubBuilder() {
val fileStub = createFileStub(packageFqName)
createCallableStubs(
fileStub, context,
ProtoContainer.Package(packageFqName, context.nameResolver, context.typeTable, packagePartSource = null),
ProtoContainer.Package(packageFqName, context.nameResolver, context.typeTable, source = null),
packageProto.functionList, packageProto.propertyList
)
for (classProto in file.classesToDecompile) {
@@ -81,7 +81,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
val content = file.contentsToByteArray(false)
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, packagePartSource = null,
createDummyPackageFragment(packageFqName), packageProto, nameResolver, containerSource = null,
components = deserializationComponents
) { emptyList() }
return membersScope.getContributedDescriptors().toList()
@@ -55,7 +55,7 @@ fun createPackageFacadeStub(
): KotlinFileStubImpl {
val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot)
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)
return fileStub
}
@@ -43,7 +43,7 @@ class KotlinJavascriptPackageFragment(
loadResourceSure(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName)).use { packageStream ->
val packageProto = ProtoBuf.Package.parseFrom(packageStream, JsSerializerProtocol.extensionRegistry)
DeserializedPackageMemberScope(
this, packageProto, nameResolver, packagePartSource = null, components = components,
this, packageProto, nameResolver, containerSource = null, components = components,
classNames = { loadClassNames() }
)
}