Repository: JetBrains/kotlin
File: plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/parseParameters.kt (Kotlin)

Code before:

    // First and second parameters in enum constructors are synthetic, we should ignore them
    val isEnumConstructor = (name == "<init>") && containingClass.isEnum()
    val startParameterIndex =
        if (isEnumConstructor) 2 else
            if (isInnerClassMember && name == "<init>") 1 else 0

    val parameterTypes = Type.getArgumentTypes(desc)

    val parameterInfos = ArrayList<ParameterInfo>(parameterTypes.size - startParameterIndex)
    for (index in startParameterIndex..parameterTypes.lastIndex) {
        val type = parameterTypes[index]

        // Use parameters only in case of the abstract methods (it hasn't local variables table)
        var name: String? = if (isAbstract(this.access) && this.name != "<init>")
            parameters.getOrNull(index - startParameterIndex)?.name
        else
            null

        val localVariableIndexOffset = when {
            isStatic -> 0
            isJvmOverloads -> 0
            else -> 1
        }

        // @JvmOverloads constructors and ordinary methods don't have "this" local variable
        name = name ?: localVariables.getOrNull(index + localVariableIndexOffset)?.name

        name = name ?: originalDescriptor.valueParameters.getOrNull(index)?.name?.identifier
                ?: "p${index - startParameterIndex}"

        // Property setters has bad parameter names
        if (name.startsWith("<") && name.endsWith(">")) {
            name = "p${index - startParameterIndex}"
        }

        val indexForAnnotation = index - startParameterIndex
        val visibleAnnotations = visibleParameterAnnotations?.get(indexForAnnotation)
        val invisibleAnnotations = invisibleParameterAnnotations?.get(indexForAnnotation)
        parameterInfos += ParameterInfo(0, name, type, visibleAnnotations, invisibleAnnotations)
    }
    return parameterInfos
}

Review comment (suggestion):
You can avoid additional assignment here:

```
name = name
    ?: localVariables.getOrNull(index + localVariableIndexOffset)?.name
    ?: originalDescriptor.valueParameters.getOrNull(index)?.name?.identifier
    ?: "p${index - startParameterIndex}"

```

Code after:
    // First and second parameters in enum constructors are synthetic, we should ignore them
    val isEnumConstructor = (name == "<init>") && containingClass.isEnum()
    val startParameterIndex =
        if (isEnumConstructor) 2 else
            if (isInnerClassMember && name == "<init>") 1 else 0

    val parameterTypes = Type.getArgumentTypes(desc)

    val parameterInfos = ArrayList<ParameterInfo>(parameterTypes.size - startParameterIndex)
    for (index in startParameterIndex..parameterTypes.lastIndex) {
        val type = parameterTypes[index]

        // Use parameters only in case of the abstract methods (it hasn't local variables table)
        var name: String? = if (isAbstract(this.access) && this.name != "<init>")
            parameters.getOrNull(index - startParameterIndex)?.name
        else
            null

        val localVariableIndexOffset = when {
            isStatic -> 0
            isJvmOverloads -> 0
            else -> 1
        }

        // @JvmOverloads constructors and ordinary methods don't have "this" local variable
        name = name ?: localVariables.getOrNull(index + localVariableIndexOffset)?.name
                ?: originalDescriptor.valueParameters.getOrNull(index)?.name?.identifier
                ?: "p${index - startParameterIndex}"

        // Property setters has bad parameter names
        if (name.startsWith("<") && name.endsWith(">")) {
            name = "p${index - startParameterIndex}"
        }

        val indexForAnnotation = index - startParameterIndex
        val visibleAnnotations = visibleParameterAnnotations?.get(indexForAnnotation)
        val invisibleAnnotations = invisibleParameterAnnotations?.get(indexForAnnotation)
        parameterInfos += ParameterInfo(0, name, type, visibleAnnotations, invisibleAnnotations)
    }
    return parameterInfos
}