Simplify deserialization components for built-ins and JS
This commit is contained in:
committed by
Alexander Udalov
parent
f130755972
commit
996c5848c2
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.ClassDataWithSource
|
||||
|
||||
class DeserializedClassDataFinder(private val packageFragmentProvider: PackageFragmentProvider) : ClassDataFinder {
|
||||
override fun findClassData(classId: ClassId): ClassDataWithSource? {
|
||||
val packageFragment =
|
||||
packageFragmentProvider.getPackageFragments(classId.packageFqName).singleOrNull()
|
||||
as? DeserializedPackageFragment ?: return null
|
||||
return packageFragment.classDataFinder.findClassData(classId)
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -18,11 +18,8 @@ package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.SerializedResourcePaths
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
@@ -33,14 +30,8 @@ abstract class DeserializedPackageFragment(
|
||||
fqName: FqName,
|
||||
protected val storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
protected val serializedResourcePaths: SerializedResourcePaths,
|
||||
private val loadResource: (path: String) -> InputStream?
|
||||
protected val loadResource: (path: String) -> InputStream?
|
||||
) : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
|
||||
abstract val nameResolver: NameResolver
|
||||
|
||||
abstract val classIdToProto: Map<ClassId, ProtoBuf.Class>?
|
||||
|
||||
// component dependency cycle
|
||||
@set:Inject
|
||||
lateinit var components: DeserializationComponents
|
||||
@@ -49,6 +40,8 @@ abstract class DeserializedPackageFragment(
|
||||
computeMemberScope()
|
||||
}
|
||||
|
||||
abstract val classDataFinder: ClassDataFinder
|
||||
|
||||
protected abstract fun computeMemberScope(): DeserializedPackageMemberScope
|
||||
|
||||
override fun getMemberScope() = deserializedMemberScope
|
||||
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
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.SerializedResourcePaths
|
||||
import java.io.InputStream
|
||||
|
||||
class ResourceLoadingClassDataFinder(
|
||||
private val packageFragmentProvider: PackageFragmentProvider,
|
||||
private val serializedResourcePaths: SerializedResourcePaths,
|
||||
private val loadResource: (path: String) -> InputStream?
|
||||
) : ClassDataFinder {
|
||||
override fun findClassData(classId: ClassId): ClassDataWithSource? {
|
||||
val packageFragment = packageFragmentProvider.getPackageFragments(classId.packageFqName).singleOrNull()
|
||||
as? DeserializedPackageFragment ?: return null
|
||||
|
||||
val classProto = packageFragment.classIdToProto?.get(classId) ?: run {
|
||||
val stream = loadResource(serializedResourcePaths.getClassMetadataPath(classId)) ?: return null
|
||||
ProtoBuf.Class.parseFrom(stream, serializedResourcePaths.extensionRegistry)
|
||||
}
|
||||
|
||||
return ClassDataWithSource(ClassData(packageFragment.nameResolver, classProto))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user