Simplify deserialization components for built-ins and JS

This commit is contained in:
Alexander Udalov
2016-02-17 14:26:38 +03:00
committed by Alexander Udalov
parent f130755972
commit 996c5848c2
9 changed files with 125 additions and 71 deletions
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2016 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.serialization.js
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.serialization.ClassData
import org.jetbrains.kotlin.serialization.ClassDataWithSource
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import java.io.InputStream
class KotlinJavascriptClassDataFinder(
private val nameResolver: NameResolver,
private val loadResource: (path: String) -> InputStream?
) : ClassDataFinder {
override fun findClassData(classId: ClassId): ClassDataWithSource? {
val stream = loadResource(KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classId)) ?: return null
val classProto = ProtoBuf.Class.parseFrom(stream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
return ClassDataWithSource(ClassData(nameResolver, classProto))
}
}
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.serialization.js
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.ProtoBuf
@@ -32,14 +31,15 @@ class KotlinJavascriptPackageFragment(
storageManager: StorageManager,
module: ModuleDescriptor,
loadResource: (path: String) -> InputStream?
) : DeserializedPackageFragment(fqName, storageManager, module, KotlinJavascriptSerializedResourcePaths, loadResource) {
override val nameResolver = NameResolverImpl.read(loadResourceSure(serializedResourcePaths.getStringTableFilePath(fqName)))
) : DeserializedPackageFragment(fqName, storageManager, module, loadResource) {
private val nameResolver =
NameResolverImpl.read(loadResourceSure(KotlinJavascriptSerializedResourcePaths.getStringTableFilePath(fqName)))
override val classIdToProto: Map<ClassId, ProtoBuf.Class>? get() = null
override val classDataFinder = KotlinJavascriptClassDataFinder(nameResolver, loadResource)
override fun computeMemberScope(): DeserializedPackageMemberScope {
val packageStream = loadResourceSure(serializedResourcePaths.getPackageFilePath(fqName))
val packageProto = ProtoBuf.Package.parseFrom(packageStream, serializedResourcePaths.extensionRegistry)
val packageStream = loadResourceSure(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName))
val packageProto = ProtoBuf.Package.parseFrom(packageStream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
return DeserializedPackageMemberScope(
this, packageProto, nameResolver, packagePartSource = null, components = components, classNames = { loadClassNames() }
)
@@ -47,7 +47,7 @@ class KotlinJavascriptPackageFragment(
private fun loadClassNames(): Collection<Name> {
val classesStream = loadResourceSure(KotlinJavascriptSerializedResourcePaths.getClassesInPackageFilePath(fqName))
val classesProto = JsProtoBuf.Classes.parseFrom(classesStream, serializedResourcePaths.extensionRegistry)
val classesProto = JsProtoBuf.Classes.parseFrom(classesStream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
return classesProto.classNameList?.map { id -> nameResolver.getName(id) } ?: listOf()
}
}
@@ -41,7 +41,7 @@ fun createKotlinJavascriptPackageFragmentProvider(
val components = DeserializationComponents(
storageManager,
module,
ResourceLoadingClassDataFinder(provider, KotlinJavascriptSerializedResourcePaths, loadResource),
DeserializedClassDataFinder(provider),
AnnotationAndConstantLoaderImpl(module, JsSerializerProtocol),
provider,
localClassResolver,