Fix protobuf extension API usages
"getExtension" returns default value when the requested extension is not present, which is 0 for Int, which makes no sense for extensions like methodImplClassName that are storing the number in the string table
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fileClasses
|
||||
|
||||
import com.google.protobuf.MessageLite
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
|
||||
@@ -68,15 +70,24 @@ public object JvmFileClassUtil {
|
||||
|
||||
@JvmStatic
|
||||
public fun getImplClassName(callable: DeserializedCallableMemberDescriptor): Name? =
|
||||
with(callable) {
|
||||
val proto = proto
|
||||
when (proto) {
|
||||
is ProtoBuf.Constructor -> null
|
||||
is ProtoBuf.Function -> proto.getExtension(JvmProtoBuf.methodImplClassName)
|
||||
is ProtoBuf.Property -> proto.getExtension(JvmProtoBuf.propertyImplClassName)
|
||||
else -> error("Unknown message: $proto")
|
||||
}?.let { nameResolver.getName(it) }
|
||||
}
|
||||
getImplClassName(callable.proto, callable.nameResolver)
|
||||
|
||||
@JvmStatic
|
||||
public fun getImplClassName(proto: MessageLite, nameResolver: NameResolver): Name? =
|
||||
when (proto) {
|
||||
is ProtoBuf.Constructor ->
|
||||
null
|
||||
is ProtoBuf.Function ->
|
||||
if (proto.hasExtension(JvmProtoBuf.methodImplClassName))
|
||||
proto.getExtension(JvmProtoBuf.methodImplClassName)
|
||||
else null
|
||||
is ProtoBuf.Property ->
|
||||
if (proto.hasExtension(JvmProtoBuf.propertyImplClassName))
|
||||
proto.getExtension(JvmProtoBuf.propertyImplClassName)
|
||||
else null
|
||||
else ->
|
||||
error("Unknown message: $proto")
|
||||
}?.let { nameResolver.getName(it) }
|
||||
|
||||
@JvmStatic
|
||||
public fun getHiddenPartFqName(file: JetFile, jvmFileClassAnnotations: ParsedJmvFileClassAnnotations): FqName =
|
||||
|
||||
+10
-16
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
@@ -37,7 +38,6 @@ import org.jetbrains.kotlin.serialization.PackageData
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -167,28 +167,22 @@ public class IncrementalPackageFragmentProvider(
|
||||
this@IncrementalPackageFragment, packageData.packageProto, packageData.nameResolver, deserializationComponents,
|
||||
{ listOf() }
|
||||
) {
|
||||
override fun filteredFunctionProtos(protos: Collection<ProtoBuf.Function>): Collection<ProtoBuf.Function> {
|
||||
return filteredMemberProtos(protos) {
|
||||
it.getExtension(JvmProtoBuf.methodImplClassName)?.let { packageData.nameResolver.getName(it) }
|
||||
}
|
||||
}
|
||||
override fun filteredFunctionProtos(protos: Collection<ProtoBuf.Function>): Collection<ProtoBuf.Function> =
|
||||
filteredMemberProtos(protos)
|
||||
|
||||
override fun filteredPropertyProtos(protos: Collection<ProtoBuf.Property>): Collection<ProtoBuf.Property> {
|
||||
return filteredMemberProtos(protos) {
|
||||
it.getExtension(JvmProtoBuf.propertyImplClassName)?.let { packageData.nameResolver.getName(it) }
|
||||
}
|
||||
}
|
||||
override fun filteredPropertyProtos(protos: Collection<ProtoBuf.Property>): Collection<ProtoBuf.Property> =
|
||||
filteredMemberProtos(protos)
|
||||
|
||||
private fun <M : MessageLite> filteredMemberProtos(allMemberProtos: Collection<M>): Collection<M> {
|
||||
fun getPackagePart(callable: MessageLite): Name? =
|
||||
JvmFileClassUtil.getImplClassName(callable, packageData.nameResolver)
|
||||
|
||||
private fun <M : MessageLite> filteredMemberProtos(
|
||||
allMemberProtos: Collection<M>,
|
||||
getPackagePart: (M) -> Name?
|
||||
): Collection<M> {
|
||||
fun shouldSkipPackagePart(name: Name) =
|
||||
JvmClassName.byFqNameWithoutInnerClasses(fqName.child(name)).internalName in obsoletePackageParts
|
||||
|
||||
if (LOG.isDebugEnabled) {
|
||||
val allPackageParts = allMemberProtos
|
||||
.map(getPackagePart)
|
||||
.map(::getPackagePart)
|
||||
.filterNotNull()
|
||||
.toSet()
|
||||
val skippedPackageParts = allPackageParts.filter { shouldSkipPackagePart(it) }
|
||||
|
||||
Reference in New Issue
Block a user