From 2320d502dbe31fc54b12a63b573b2f4d953ca433 Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Fri, 23 Jan 2026 11:46:05 +0100 Subject: [PATCH] Kotlin: Address detections from kotin internal queries --- .../src/main/kotlin/KotlinFileExtractor.kt | 4 +-- .../src/main/kotlin/utils/GetByFqName.kt | 36 ++++++------------- .../src/main/kotlin/utils/Helpers.kt | 3 ++ 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index f83d887eb56..70819c455fc 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -2978,9 +2978,7 @@ open class KotlinFileExtractor( // For Kotlin < 2.3, s.delegate is not-nullable. Cast to be nullable, // as a workaround to silence warnings for kotlin < 2.3 about the elvis // operator being redundant. - // For Kotlin >= 2.3, the cast is redundant, so we need to silence that warning - @Suppress("USELESS_CAST") - val delegate = s.delegate as IrVariable? + val delegate: IrVariable? = cast(s.delegate) val propId = tw.getFreshIdLabel() if (delegate == null) { diff --git a/java/kotlin-extractor/src/main/kotlin/utils/GetByFqName.kt b/java/kotlin-extractor/src/main/kotlin/utils/GetByFqName.kt index 8fff8747594..8f85ca7ebd3 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/GetByFqName.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/GetByFqName.kt @@ -12,44 +12,28 @@ fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSym return getClassByClassId(pluginContext, id) } +fun getClassByFqName(pluginContext: IrPluginContext, fqName: String): IrClassSymbol? { + return getClassByFqName(pluginContext, FqName(fqName)) +} + fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? { return pluginContext.referenceClass(id) } fun getFunctionsByFqName( pluginContext: IrPluginContext, - pkgName: FqName, - name: Name + pkgName: String, + name: String ): Collection { - val id = CallableId(pkgName, name) + val id = CallableId(FqName(pkgName), Name.identifier(name)) return pluginContext.referenceFunctions(id) } fun getPropertiesByFqName( pluginContext: IrPluginContext, - pkgName: FqName, - name: Name + pkgName: String, + name: String ): Collection { - val id = CallableId(pkgName, name) + val id = CallableId(FqName(pkgName), Name.identifier(name)) return pluginContext.referenceProperties(id) } - -fun getClassByFqName(pluginContext: IrPluginContext, fqName: String): IrClassSymbol? { - return getClassByFqName(pluginContext, FqName(fqName)) -} - -fun getFunctionsByFqName( - pluginContext: IrPluginContext, - pkgName: String, - name: String -): Collection { - return getFunctionsByFqName(pluginContext, FqName(pkgName), Name.identifier(name)) -} - -fun getPropertiesByFqName( - pluginContext: IrPluginContext, - pkgName: String, - name: String -): Collection { - return getPropertiesByFqName(pluginContext, FqName(pkgName), Name.identifier(name)) -} diff --git a/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt b/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt index aee909b1eb4..e3a4af08fbf 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt @@ -11,3 +11,6 @@ fun IrFunction.isLocalFunction(): Boolean { val IrClass.isInterfaceLike get() = kind == ClassKind.INTERFACE || kind == ClassKind.ANNOTATION_CLASS + +@Suppress("UNCHECKED_CAST") +fun cast(value: Any?): T = value as T