move BuiltInsSerializerExtension from builtins-serializer to serialization module
This commit is contained in:
@@ -45,53 +45,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||||
|
|
||||||
private object BuiltInsSerializerExtension : SerializerExtension() {
|
|
||||||
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder, stringTable: StringTable) {
|
|
||||||
for (annotation in descriptor.getAnnotations()) {
|
|
||||||
proto.addExtension(BuiltInsProtoBuf.classAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun serializePackage(
|
|
||||||
packageFragments: Collection<PackageFragmentDescriptor>,
|
|
||||||
proto: ProtoBuf.Package.Builder,
|
|
||||||
stringTable: StringTable
|
|
||||||
) {
|
|
||||||
val classes = packageFragments.flatMap {
|
|
||||||
it.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance<ClassDescriptor>()
|
|
||||||
}
|
|
||||||
|
|
||||||
for (descriptor in DescriptorSerializer.sort(classes)) {
|
|
||||||
proto.addExtension(BuiltInsProtoBuf.className, stringTable.getSimpleNameIndex(descriptor.getName()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun serializeCallable(
|
|
||||||
callable: CallableMemberDescriptor,
|
|
||||||
proto: ProtoBuf.Callable.Builder,
|
|
||||||
stringTable: StringTable
|
|
||||||
) {
|
|
||||||
for (annotation in callable.getAnnotations()) {
|
|
||||||
proto.addExtension(BuiltInsProtoBuf.callableAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
|
||||||
}
|
|
||||||
val compileTimeConstant = (callable as? PropertyDescriptor)?.getCompileTimeInitializer()
|
|
||||||
if (compileTimeConstant != null && compileTimeConstant !is NullValue) {
|
|
||||||
val type = compileTimeConstant.getType(KotlinBuiltIns.getInstance())
|
|
||||||
proto.setExtension(BuiltInsProtoBuf.compileTimeValue, AnnotationSerializer.valueProto(compileTimeConstant, type, stringTable).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun serializeValueParameter(
|
|
||||||
descriptor: ValueParameterDescriptor,
|
|
||||||
proto: ProtoBuf.Callable.ValueParameter.Builder,
|
|
||||||
stringTable: StringTable
|
|
||||||
) {
|
|
||||||
for (annotation in descriptor.getAnnotations()) {
|
|
||||||
proto.addExtension(BuiltInsProtoBuf.parameterAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||||
private var totalSize = 0
|
private var totalSize = 0
|
||||||
private var totalFiles = 0
|
private var totalFiles = 0
|
||||||
|
|||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
|
import org.jetbrains.kotlin.serialization.AnnotationSerializer
|
||||||
|
import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
||||||
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
|
import org.jetbrains.kotlin.serialization.SerializerExtension
|
||||||
|
import org.jetbrains.kotlin.serialization.StringTable
|
||||||
|
|
||||||
|
public object BuiltInsSerializerExtension : SerializerExtension() {
|
||||||
|
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder, stringTable: StringTable) {
|
||||||
|
for (annotation in descriptor.getAnnotations()) {
|
||||||
|
proto.addExtension(BuiltInsProtoBuf.classAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serializePackage(
|
||||||
|
packageFragments: Collection<PackageFragmentDescriptor>,
|
||||||
|
proto: ProtoBuf.Package.Builder,
|
||||||
|
stringTable: StringTable
|
||||||
|
) {
|
||||||
|
val classes = packageFragments.flatMap {
|
||||||
|
it.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance<ClassDescriptor>()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (descriptor in DescriptorSerializer.sort(classes)) {
|
||||||
|
proto.addExtension(BuiltInsProtoBuf.className, stringTable.getSimpleNameIndex(descriptor.getName()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serializeCallable(
|
||||||
|
callable: CallableMemberDescriptor,
|
||||||
|
proto: ProtoBuf.Callable.Builder,
|
||||||
|
stringTable: StringTable
|
||||||
|
) {
|
||||||
|
for (annotation in callable.getAnnotations()) {
|
||||||
|
proto.addExtension(BuiltInsProtoBuf.callableAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
||||||
|
}
|
||||||
|
val compileTimeConstant = (callable as? PropertyDescriptor)?.getCompileTimeInitializer()
|
||||||
|
if (compileTimeConstant != null && compileTimeConstant !is NullValue) {
|
||||||
|
val type = compileTimeConstant.getType(KotlinBuiltIns.getInstance())
|
||||||
|
proto.setExtension(BuiltInsProtoBuf.compileTimeValue, AnnotationSerializer.valueProto(compileTimeConstant, type, stringTable).build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serializeValueParameter(
|
||||||
|
descriptor: ValueParameterDescriptor,
|
||||||
|
proto: ProtoBuf.Callable.ValueParameter.Builder,
|
||||||
|
stringTable: StringTable
|
||||||
|
) {
|
||||||
|
for (annotation in descriptor.getAnnotations()) {
|
||||||
|
proto.addExtension(BuiltInsProtoBuf.parameterAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user