mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Improve code quality
This commit is contained in:
@@ -314,14 +314,18 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
|
||||
fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>, label: Label<DbMethod>? = null): Label<out DbCallable> {
|
||||
fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>): Label<out DbCallable> {
|
||||
currentFunction = f
|
||||
|
||||
f.typeParameters.map { extractTypeParameter(it) }
|
||||
|
||||
val locId = tw.getLocation(f)
|
||||
|
||||
val id = label ?: useFunction<DbCallable>(f)
|
||||
val id =
|
||||
if (f.isLocalFunction())
|
||||
withSourceFile(f.fileOrNull!!).getLocalFunctionLabels(f).function
|
||||
else
|
||||
useFunction<DbCallable>(f)
|
||||
|
||||
val extReceiver = f.extensionReceiverParameter
|
||||
val idxOffset = if (extReceiver != null) 1 else 0
|
||||
@@ -680,7 +684,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
if (callTarget.isLocalFunction()) {
|
||||
val ids = withSourceFile(callTarget.fileOrNull!!).useGeneratedLocalFunctionClass(callTarget)
|
||||
val ids = withSourceFile(callTarget.fileOrNull!!).getLocalFunctionLabels(callTarget)
|
||||
|
||||
val methodId = ids.function
|
||||
tw.writeCallableBinding(id, methodId)
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.ir.util.packageFqName
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
|
||||
@@ -108,7 +107,7 @@ class KotlinSourceFileExtractor(
|
||||
|
||||
data class LocalFunctionLabels(val type: TypeResults, val constructor: Label<DbConstructor>, val function: Label<DbMethod>)
|
||||
|
||||
fun useGeneratedLocalFunctionClass(f: IrFunction): LocalFunctionLabels {
|
||||
fun getLocalFunctionLabels(f: IrFunction): LocalFunctionLabels {
|
||||
if (!f.isLocalFunction()){
|
||||
logger.warnElement(Severity.ErrorSevere, "Extracting a non-local function as a local one", f)
|
||||
}
|
||||
@@ -129,7 +128,7 @@ class KotlinSourceFileExtractor(
|
||||
}
|
||||
|
||||
fun extractGeneratedClass(localFunction: IrFunction, superTypes: List<IrType>) : Label<out DbClass> {
|
||||
val ids = withSourceFile(localFunction.fileOrNull!!).useGeneratedLocalFunctionClass(localFunction)
|
||||
val ids = getLocalFunctionLabels(localFunction)
|
||||
|
||||
// Write class
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -140,7 +139,7 @@ class KotlinSourceFileExtractor(
|
||||
tw.writeHasLocation(id, locId)
|
||||
|
||||
// Extract local function as a member
|
||||
extractFunction(localFunction, id, ids.function)
|
||||
extractFunction(localFunction, id)
|
||||
|
||||
// Extract constructor
|
||||
tw.writeConstrs(ids.constructor, "", "", ids.type.javaResult.id, ids.type.kotlinResult.id, id, ids.constructor)
|
||||
|
||||
@@ -445,12 +445,13 @@ class X {
|
||||
}
|
||||
|
||||
protected fun IrFunction.isLocalFunction(): Boolean {
|
||||
return this.visibility == DescriptorVisibilities.LOCAL
|
||||
return this.visibility == DescriptorVisibilities.LOCAL &&
|
||||
this.origin != IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||
}
|
||||
|
||||
fun <T: DbCallable> useFunction(f: IrFunction): Label<out T> {
|
||||
if (f.isLocalFunction()) {
|
||||
val ids = withSourceFile(f.fileOrNull!!).useGeneratedLocalFunctionClass(f)
|
||||
val ids = withSourceFile(f.fileOrNull!!).getLocalFunctionLabels(f)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return ids.function as Label<out T>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user