mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
Kotlin: Don't convert back and forth between ClassId and FqName
This showed up as a bug in Kotlin 2 mode: We were starting with the Class Id "java/util/Map.Entry", which we then converted to the FqName "java.util.Map.Entry", and then back to a Class Id with ClassId.topLevel. This gave us a Class Id that referenceClass wasn't able to resolve. Now we just stick with the Class Id that we started with, and the class can be resolved by Kotlin 2.
This commit is contained in:
@@ -139,7 +139,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
fun getJavaEquivalentClass(c: IrClass) =
|
||||
getJavaEquivalentClassId(c)?.let { getClassByFqName(pluginContext, it.asSingleFqName()) }?.owner
|
||||
getJavaEquivalentClassId(c)?.let { getClassByClassId(pluginContext, it) }?.owner
|
||||
|
||||
/**
|
||||
* Gets a KotlinFileExtractor based on this one, except it attributes locations to the file that declares the given class.
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.github.codeql.utils
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
@@ -9,6 +10,10 @@ fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSym
|
||||
return pluginContext.referenceClass(fqName)
|
||||
}
|
||||
|
||||
fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? {
|
||||
return getClassByFqName(pluginContext, id.asSingleFqName())
|
||||
}
|
||||
|
||||
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
|
||||
val fqName = pkgName.child(name)
|
||||
return pluginContext.referenceFunctions(fqName)
|
||||
|
||||
@@ -10,6 +10,10 @@ import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
|
||||
val id = ClassId.topLevel(fqName)
|
||||
return getClassByClassId(pluginContext, id)
|
||||
}
|
||||
|
||||
fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? {
|
||||
return pluginContext.referenceClass(id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user