Minor, get rid of ClassSerializationUtil
This commit is contained in:
@@ -111,7 +111,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
if (dependOnOldBuiltIns) ModuleInfo.DependenciesOnBuiltins.LAST else ModuleInfo.DependenciesOnBuiltins.NONE
|
if (dependOnOldBuiltIns) ModuleInfo.DependenciesOnBuiltins.LAST else ModuleInfo.DependenciesOnBuiltins.NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serialize(disposable: Disposable, destDir: File, srcDirs: Collection<File>, extraClassPath: Collection<File>) {
|
private fun serialize(disposable: Disposable, destDir: File, srcDirs: Collection<File>, extraClassPath: Collection<File>) {
|
||||||
val configuration = CompilerConfiguration()
|
val configuration = CompilerConfiguration()
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serializePackage(module: ModuleDescriptor, fqName: FqName, destDir: File) {
|
private fun serializePackage(module: ModuleDescriptor, fqName: FqName, destDir: File) {
|
||||||
val packageView = module.getPackage(fqName) ?: error("No package resolved in $module")
|
val packageView = module.getPackage(fqName) ?: error("No package resolved in $module")
|
||||||
|
|
||||||
// TODO: perform some kind of validation? At the moment not possible because DescriptorValidator is in compiler-tests
|
// TODO: perform some kind of validation? At the moment not possible because DescriptorValidator is in compiler-tests
|
||||||
@@ -159,13 +159,12 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
|
|
||||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS))
|
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS))
|
||||||
|
|
||||||
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
|
serializeClasses(classifierDescriptors, serializer) {
|
||||||
override fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class) {
|
(classDescriptor, classProto) ->
|
||||||
val stream = ByteArrayOutputStream()
|
val stream = ByteArrayOutputStream()
|
||||||
classProto.writeTo(stream)
|
classProto.writeTo(stream)
|
||||||
write(destDir, getFileName(classDescriptor), stream)
|
write(destDir, getFileName(classDescriptor), stream)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
val packageStream = ByteArrayOutputStream()
|
val packageStream = ByteArrayOutputStream()
|
||||||
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
||||||
@@ -178,7 +177,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
write(destDir, BuiltInsSerializationUtil.getStringTableFilePath(fqName), nameStream)
|
write(destDir, BuiltInsSerializationUtil.getStringTableFilePath(fqName), nameStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun write(destDir: File, fileName: String, stream: ByteArrayOutputStream) {
|
private fun write(destDir: File, fileName: String, stream: ByteArrayOutputStream) {
|
||||||
totalSize += stream.size()
|
totalSize += stream.size()
|
||||||
totalFiles++
|
totalFiles++
|
||||||
val file = File(destDir, fileName)
|
val file = File(destDir, fileName)
|
||||||
@@ -186,7 +185,35 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
file.writeBytes(stream.toByteArray())
|
file.writeBytes(stream.toByteArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFileName(classDescriptor: ClassDescriptor): String {
|
private fun serializeClass(
|
||||||
|
classDescriptor: ClassDescriptor,
|
||||||
|
serializer: DescriptorSerializer,
|
||||||
|
writeClass: (ClassDescriptor, ProtoBuf.Class) -> Unit
|
||||||
|
) {
|
||||||
|
val classProto = serializer.classProto(classDescriptor).build() ?: error("Class not serialized: $classDescriptor")
|
||||||
|
writeClass(classDescriptor, classProto)
|
||||||
|
|
||||||
|
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getDescriptors(), serializer, writeClass)
|
||||||
|
|
||||||
|
val classObjectDescriptor = classDescriptor.getClassObjectDescriptor()
|
||||||
|
if (classObjectDescriptor != null) {
|
||||||
|
serializeClass(classObjectDescriptor, serializer, writeClass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun serializeClasses(
|
||||||
|
descriptors: Collection<DeclarationDescriptor>,
|
||||||
|
serializer: DescriptorSerializer,
|
||||||
|
writeClass: (ClassDescriptor, ProtoBuf.Class) -> Unit
|
||||||
|
) {
|
||||||
|
for (descriptor in descriptors) {
|
||||||
|
if (descriptor is ClassDescriptor) {
|
||||||
|
serializeClass(descriptor, serializer, writeClass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getFileName(classDescriptor: ClassDescriptor): String {
|
||||||
return BuiltInsSerializationUtil.getClassMetadataPath(DeserializedResolverUtils.getClassId(classDescriptor))!!
|
return BuiltInsSerializationUtil.getClassMetadataPath(DeserializedResolverUtils.getClassId(classDescriptor))!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +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.builtins
|
|
||||||
|
|
||||||
import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer
|
|
||||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
|
||||||
|
|
||||||
public object ClassSerializationUtil {
|
|
||||||
public trait Sink {
|
|
||||||
fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun serializeClass(classDescriptor: ClassDescriptor, serializer: DescriptorSerializer, sink: Sink) {
|
|
||||||
val classProto = serializer.classProto(classDescriptor).build() ?: error("Class not serialized: $classDescriptor")
|
|
||||||
sink.writeClass(classDescriptor, classProto)
|
|
||||||
|
|
||||||
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getDescriptors(), serializer, sink)
|
|
||||||
|
|
||||||
val classObjectDescriptor = classDescriptor.getClassObjectDescriptor()
|
|
||||||
if (classObjectDescriptor != null) {
|
|
||||||
serializeClass(classObjectDescriptor, serializer, sink)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun serializeClasses(descriptors: Collection<DeclarationDescriptor>, serializer: DescriptorSerializer, sink: Sink) {
|
|
||||||
for (descriptor in descriptors) {
|
|
||||||
if (descriptor is ClassDescriptor) {
|
|
||||||
serializeClass(descriptor, serializer, sink)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user