Revert "Extract KotlinClassInfo to a separate class"
This reverts commit ec3da62672.
This commit is contained in:
@@ -24,44 +24,27 @@ import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.getExtensionOrNull
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMemberSignature
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptorVisibility
|
||||
|
||||
sealed interface InlineFunctionOrAccessor {
|
||||
val jvmMethodSignature: JvmMemberSignature.Method
|
||||
}
|
||||
|
||||
data class InlineFunction(
|
||||
override val jvmMethodSignature: JvmMemberSignature.Method,
|
||||
|
||||
/** The Kotlin name of the function. It may be different from the JVM name of the function if [JvmName] is used. */
|
||||
val kotlinFunctionName: String
|
||||
) : InlineFunctionOrAccessor
|
||||
|
||||
data class InlinePropertyAccessor(
|
||||
override val jvmMethodSignature: JvmMemberSignature.Method,
|
||||
|
||||
/** The name of the property that this property accessor belongs to. */
|
||||
val propertyName: String
|
||||
) : InlineFunctionOrAccessor
|
||||
|
||||
fun inlineFunctionsAndAccessors(header: KotlinClassHeader, excludePrivateMembers: Boolean = false): List<InlineFunctionOrAccessor> {
|
||||
fun inlineFunctionsAndAccessors(header: KotlinClassHeader): List<JvmMemberSignature.Method> {
|
||||
val data = header.data ?: return emptyList()
|
||||
val strings = header.strings ?: return emptyList()
|
||||
|
||||
return when (header.kind) {
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
val (nameResolver, classProto) = JvmProtoBufUtil.readClassDataFrom(data, strings)
|
||||
inlineFunctions(classProto.functionList, nameResolver, classProto.typeTable, excludePrivateMembers) +
|
||||
inlinePropertyAccessors(classProto.propertyList, nameResolver, excludePrivateMembers)
|
||||
inlineFunctions(classProto.functionList, nameResolver, classProto.typeTable) +
|
||||
inlineAccessors(classProto.propertyList, nameResolver)
|
||||
}
|
||||
KotlinClassHeader.Kind.FILE_FACADE,
|
||||
KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
|
||||
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(data, strings)
|
||||
inlineFunctions(packageProto.functionList, nameResolver, packageProto.typeTable, excludePrivateMembers) +
|
||||
inlinePropertyAccessors(packageProto.propertyList, nameResolver, excludePrivateMembers)
|
||||
inlineFunctions(packageProto.functionList, nameResolver, packageProto.typeTable) +
|
||||
inlineAccessors(packageProto.propertyList, nameResolver)
|
||||
}
|
||||
else -> emptyList()
|
||||
}
|
||||
@@ -70,51 +53,40 @@ fun inlineFunctionsAndAccessors(header: KotlinClassHeader, excludePrivateMembers
|
||||
private fun inlineFunctions(
|
||||
functions: List<ProtoBuf.Function>,
|
||||
nameResolver: NameResolver,
|
||||
protoTypeTable: ProtoBuf.TypeTable,
|
||||
excludePrivateFunctions: Boolean = false
|
||||
): List<InlineFunction> {
|
||||
protoTypeTable: ProtoBuf.TypeTable
|
||||
): List<JvmMemberSignature.Method> {
|
||||
val typeTable = TypeTable(protoTypeTable)
|
||||
return functions
|
||||
.filter { Flags.IS_INLINE.get(it.flags) && (!excludePrivateFunctions || !isPrivate(it.flags)) }
|
||||
.mapNotNull { inlineFunction ->
|
||||
JvmProtoBufUtil.getJvmMethodSignature(inlineFunction, nameResolver, typeTable)?.let {
|
||||
InlineFunction(jvmMethodSignature = it, kotlinFunctionName = nameResolver.getString(inlineFunction.name))
|
||||
}
|
||||
}
|
||||
return functions.filter { Flags.IS_INLINE.get(it.flags) }.mapNotNull {
|
||||
JvmProtoBufUtil.getJvmMethodSignature(it, nameResolver, typeTable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun inlinePropertyAccessors(
|
||||
fun inlineAccessors(
|
||||
properties: List<ProtoBuf.Property>,
|
||||
nameResolver: NameResolver,
|
||||
excludePrivateAccessors: Boolean = false
|
||||
): List<InlinePropertyAccessor> {
|
||||
val inlineAccessors = mutableListOf<InlinePropertyAccessor>()
|
||||
): List<JvmMemberSignature.Method> {
|
||||
val inlineAccessors = mutableListOf<JvmMethodSignature>()
|
||||
|
||||
fun isInline(flags: Int) = Flags.IS_INLINE_ACCESSOR.get(flags)
|
||||
fun isPrivate(flags: Int) = DescriptorVisibilities.isPrivate(ProtoEnumFlags.descriptorVisibility(Flags.VISIBILITY.get(flags)))
|
||||
|
||||
properties.forEach { property ->
|
||||
val propertySignature = property.getExtensionOrNull(JvmProtoBuf.propertySignature) ?: return@forEach
|
||||
if (property.hasGetterFlags() && Flags.IS_INLINE_ACCESSOR.get(property.getterFlags)
|
||||
&& (!excludePrivateAccessors || !isPrivate(property.getterFlags))
|
||||
) {
|
||||
val getter = propertySignature.getter
|
||||
inlineAccessors.add(
|
||||
InlinePropertyAccessor(
|
||||
JvmMemberSignature.Method(name = nameResolver.getString(getter.name), desc = nameResolver.getString(getter.desc)),
|
||||
propertyName = nameResolver.getString(property.name)
|
||||
)
|
||||
)
|
||||
|
||||
if (property.hasGetterFlags() && isInline(property.getterFlags)) {
|
||||
if (!(excludePrivateAccessors && isPrivate(property.getterFlags))) {
|
||||
inlineAccessors.add(propertySignature.getter)
|
||||
}
|
||||
}
|
||||
if (property.hasSetterFlags() && Flags.IS_INLINE_ACCESSOR.get(property.setterFlags)
|
||||
&& (!excludePrivateAccessors || !isPrivate(property.setterFlags))
|
||||
) {
|
||||
val setter = propertySignature.setter
|
||||
inlineAccessors.add(
|
||||
InlinePropertyAccessor(
|
||||
JvmMemberSignature.Method(name = nameResolver.getString(setter.name), desc = nameResolver.getString(setter.desc)),
|
||||
propertyName = nameResolver.getString(property.name)
|
||||
)
|
||||
)
|
||||
if (property.hasSetterFlags() && isInline(property.setterFlags)) {
|
||||
if (!(excludePrivateAccessors && isPrivate(property.setterFlags))) {
|
||||
inlineAccessors.add(propertySignature.setter)
|
||||
}
|
||||
}
|
||||
}
|
||||
return inlineAccessors
|
||||
}
|
||||
|
||||
private fun isPrivate(flags: Int) = DescriptorVisibilities.isPrivate(ProtoEnumFlags.descriptorVisibility(Flags.VISIBILITY.get(flags)))
|
||||
return inlineAccessors.map {
|
||||
JvmMemberSignature.Method(name = nameResolver.getString(it.name), desc = nameResolver.getString(it.desc))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user