Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 387e8db

Browse files
tamasvajkigfoo
authored andcommitted
Minor code quality improvements
1 parent 6154c2b commit 387e8db

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
2323
import org.jetbrains.kotlin.ir.symbols.IrSymbol
2424
import org.jetbrains.kotlin.ir.types.*
2525
import org.jetbrains.kotlin.ir.util.*
26-
import org.jetbrains.kotlin.metadata.ProtoBuf
2726
import org.jetbrains.kotlin.name.FqName
2827
import org.jetbrains.kotlin.util.OperatorNameConventions
2928
import org.jetbrains.kotlin.types.Variance
@@ -539,15 +538,15 @@ open class KotlinFileExtractor(
539538
}
540539
}
541540

542-
fun extractFunctionIfReal(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, memberName: String? = null) {
541+
fun extractFunctionIfReal(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) {
543542
with("function if real", f) {
544543
if (f.origin == IrDeclarationOrigin.FAKE_OVERRIDE)
545544
return
546-
extractFunction(f, parentId, extractBody, typeSubstitution, classTypeArgsIncludingOuterClasses, memberName)
545+
extractFunction(f, parentId, extractBody, typeSubstitution, classTypeArgsIncludingOuterClasses)
547546
}
548547
}
549548

550-
fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, memberName: String? = null, idOverride: Label<DbMethod>? = null): Label<out DbCallable> {
549+
fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, idOverride: Label<DbMethod>? = null): Label<out DbCallable> {
551550
with("function", f) {
552551
DeclarationStackAdjuster(f).use {
553552

@@ -602,7 +601,7 @@ open class KotlinFileExtractor(
602601
tw.writeConstrsKotlinType(constrId, unitType.kotlinResult.id)
603602
} else {
604603
val returnType = useType(substReturnType, TypeContext.RETURN)
605-
val shortName = memberName ?: getFunctionShortName(f)
604+
val shortName = getFunctionShortName(f)
606605
@Suppress("UNCHECKED_CAST")
607606
val methodId = id as Label<DbMethod>
608607
tw.writeMethods(methodId, shortName, "$shortName$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration as Label<DbMethod>)
@@ -2253,8 +2252,7 @@ open class KotlinFileExtractor(
22532252
val fnInterfaceType = getFunctionalInterfaceType(types)
22542253
val id = extractGeneratedClass(
22552254
e.function, // We're adding this function as a member, and changing its name to `invoke` to implement `kotlin.FunctionX<,,,>.invoke(,,)`
2256-
listOf(pluginContext.irBuiltIns.anyType, fnInterfaceType),
2257-
OperatorNameConventions.INVOKE.asString())
2255+
listOf(pluginContext.irBuiltIns.anyType, fnInterfaceType))
22582256

22592257
if (types.size > BuiltInFunctionArity.BIG_ARITY) {
22602258
implementFunctionNInvoke(e.function, ids, locId, parameters)
@@ -2358,7 +2356,7 @@ open class KotlinFileExtractor(
23582356
functionReferenceExpr: IrFunctionReference,
23592357
parent: StmtExprParent,
23602358
callable: Label<out DbCallable>
2361-
) : Label<out DbClassinstancexpr> {
2359+
) {
23622360
with("function reference", functionReferenceExpr) {
23632361
val target = functionReferenceExpr.reflectionTarget ?: run {
23642362
logger.errorElement("Expected to find reflection target for function reference. Using underlying symbol instead.", functionReferenceExpr)
@@ -2571,8 +2569,6 @@ open class KotlinFileExtractor(
25712569
}
25722570

25732571
tw.writeIsAnonymClass(id, idMemberRef)
2574-
2575-
return idMemberRef
25762572
}
25772573
}
25782574

@@ -2977,7 +2973,7 @@ open class KotlinFileExtractor(
29772973

29782974
// add implementation function
29792975
val functionId = tw.getFreshIdLabel<DbMethod>()
2980-
extractFunction(samMember, classId, false, null, null, null, functionId)
2976+
extractFunction(samMember, classId, false, null, null, functionId)
29812977

29822978
//body
29832979
val blockId = tw.getFreshIdLabel<DbBlock>()
@@ -3204,14 +3200,14 @@ open class KotlinFileExtractor(
32043200
/**
32053201
* Extracts the class around a local function or a lambda.
32063202
*/
3207-
private fun extractGeneratedClass(localFunction: IrFunction, superTypes: List<IrType>, memberName: String? = null) : Label<out DbClass> {
3203+
private fun extractGeneratedClass(localFunction: IrFunction, superTypes: List<IrType>) : Label<out DbClass> {
32083204
with("generated class", localFunction) {
32093205
val ids = getLocallyVisibleFunctionLabels(localFunction)
32103206

32113207
val id = extractGeneratedClass(ids, superTypes, tw.getLocation(localFunction), localFunction)
32123208

32133209
// Extract local function as a member
3214-
extractFunctionIfReal(localFunction, id, true, null, listOf(), memberName)
3210+
extractFunctionIfReal(localFunction, id, true, null, listOf())
32153211

32163212
return id
32173213
}

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ open class KotlinUsesExtractor(
562562
private val IrDeclaration.isAnonymousFunction get() = this is IrSimpleFunction && name == SpecialNames.NO_NAME_PROVIDED
563563

564564
fun getFunctionShortName(f: IrFunction) : String {
565+
if (f.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA || f.isAnonymousFunction)
566+
return OperatorNameConventions.INVOKE.asString()
565567
(f as? IrSimpleFunction)?.correspondingPropertySymbol?.let {
566568
val propName = it.owner.name.asString()
567569
when(f) {

0 commit comments

Comments
 (0)