Exclude private members from ABI classes

This commit is contained in:
Alexey Tsvetkov
2018-11-29 19:46:16 +03:00
parent 33faa00184
commit 903f6bc79b
17 changed files with 291 additions and 12 deletions
@@ -108,8 +108,8 @@ class DescriptorSerializer private constructor(
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) continue
when (descriptor) {
is PropertyDescriptor -> builder.addProperty(propertyProto(descriptor))
is FunctionDescriptor -> builder.addFunction(functionProto(descriptor))
is PropertyDescriptor -> propertyProto(descriptor)?.let { builder.addProperty(it) }
is FunctionDescriptor -> functionProto(descriptor)?.let { builder.addFunction(it) }
}
}
@@ -178,7 +178,9 @@ class DescriptorSerializer private constructor(
return false
}
fun propertyProto(descriptor: PropertyDescriptor): ProtoBuf.Property.Builder {
fun propertyProto(descriptor: PropertyDescriptor): ProtoBuf.Property.Builder? {
if (!extension.shouldSerializeProperty(descriptor)) return null
val builder = ProtoBuf.Property.newBuilder()
val local = createChildSerializer(descriptor)
@@ -281,7 +283,9 @@ class DescriptorSerializer private constructor(
else
descriptor.visibility
fun functionProto(descriptor: FunctionDescriptor): ProtoBuf.Function.Builder {
fun functionProto(descriptor: FunctionDescriptor): ProtoBuf.Function.Builder? {
if (!extension.shouldSerializeFunction(descriptor)) return null
val builder = ProtoBuf.Function.newBuilder()
val local = createChildSerializer(descriptor)
@@ -638,8 +642,8 @@ class DescriptorSerializer private constructor(
for (declaration in sort(members)) {
when (declaration) {
is PropertyDescriptor -> builder.addProperty(propertyProto(declaration))
is FunctionDescriptor -> builder.addFunction(functionProto(declaration))
is PropertyDescriptor -> propertyProto(declaration)?.let { builder.addProperty(it) }
is FunctionDescriptor -> functionProto(declaration)?.let { builder.addFunction(it) }
is TypeAliasDescriptor -> builder.addTypeAlias(typeAliasProto(declaration))
}
}
@@ -22,6 +22,8 @@ abstract class SerializerExtension {
open fun shouldUseTypeTable(): Boolean = false
open fun shouldUseNormalizedVisibility(): Boolean = false
open fun shouldSerializeFunction(descriptor: FunctionDescriptor): Boolean = true
open fun shouldSerializeProperty(descriptor: PropertyDescriptor): Boolean = true
interface ClassMembersProducer {
fun getCallableMembers(classDescriptor: ClassDescriptor): Collection<CallableMemberDescriptor>