Code cleanup: several inspections applied
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fdca96634e
commit
840847e47c
@@ -158,7 +158,7 @@ object CodegenUtil {
|
||||
@JvmStatic
|
||||
fun constructFakeFunctionCall(project: Project, referencedFunction: FunctionDescriptor): KtCallExpression {
|
||||
val fakeFunctionCall = StringBuilder("callableReferenceFakeCall(")
|
||||
fakeFunctionCall.append(referencedFunction.valueParameters.map { "p${it.index}" }.joinToString(", "))
|
||||
fakeFunctionCall.append(referencedFunction.valueParameters.joinToString(", ") { "p${it.index}" })
|
||||
fakeFunctionCall.append(")")
|
||||
return KtPsiFactory(project, markGenerated = false).createExpression(fakeFunctionCall.toString()) as KtCallExpression
|
||||
}
|
||||
|
||||
@@ -243,8 +243,9 @@ fun reportTarget6InheritanceErrorIfNeeded(
|
||||
state.diagnostics.report(
|
||||
ErrorsJvm.TARGET6_INTERFACE_INHERITANCE.on(
|
||||
classElement, classDescriptor, key,
|
||||
value.map { Renderers.COMPACT.render(JvmCodegenUtil.getDirectMember(it), RenderingContext.Empty) }.
|
||||
joinToString(separator = "\n", prefix = "\n")
|
||||
value.joinToString(separator = "\n", prefix = "\n") {
|
||||
Renderers.COMPACT.render(JvmCodegenUtil.getDirectMember(it), RenderingContext.Empty)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class CoroutineCodegenForLambda private constructor(
|
||||
if (allFunctionParameters().size <= 1) {
|
||||
val delegate = typeMapper.mapSignatureSkipGeneric(createCoroutineDescriptor).asmMethod
|
||||
|
||||
val bridgeParameters = (1..delegate.argumentTypes.size - 1).map { AsmTypes.OBJECT_TYPE } + delegate.argumentTypes.last()
|
||||
val bridgeParameters = (1 until delegate.argumentTypes.size).map { AsmTypes.OBJECT_TYPE } + delegate.argumentTypes.last()
|
||||
val bridge = Method(delegate.name, delegate.returnType, bridgeParameters.toTypedArray())
|
||||
|
||||
generateBridge(bridge, delegate)
|
||||
@@ -288,7 +288,7 @@ class CoroutineCodegenForLambda private constructor(
|
||||
|
||||
private fun allFunctionParameters() =
|
||||
originalSuspendFunctionDescriptor.extensionReceiverParameter.let(::listOfNotNull) +
|
||||
originalSuspendFunctionDescriptor.valueParameters.orEmpty()
|
||||
originalSuspendFunctionDescriptor.valueParameters
|
||||
|
||||
private fun ParameterDescriptor.getFieldInfoForCoroutineLambdaParameter() =
|
||||
createHiddenFieldInfo(type, COROUTINE_LAMBDA_PARAMETER_PREFIX + (this.safeAs<ValueParameterDescriptor>()?.index ?: ""))
|
||||
|
||||
@@ -51,7 +51,7 @@ internal fun ClassLoader.listAllUrlsAsFiles(): List<File> {
|
||||
}
|
||||
|
||||
internal fun URLClassLoader.listLocalUrlsAsFiles(): List<File> {
|
||||
return this.urLs.map { it.toString().removePrefix("file:") }.filterNotNull().map(::File)
|
||||
return this.urLs.mapNotNull { it.toString().removePrefix("file:") }.map(::File)
|
||||
}
|
||||
|
||||
internal fun <T : Any> List<T>.ensureNotEmpty(error: String): List<T> {
|
||||
|
||||
@@ -74,7 +74,7 @@ private fun inlineAccessorsJvmNames(properties: List<ProtoBuf.Property>, nameRes
|
||||
}
|
||||
}
|
||||
|
||||
return inlineAccessors.mapNotNull {
|
||||
return inlineAccessors.map {
|
||||
nameResolver.getString(it.name) + nameResolver.getString(it.desc)
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class NondeterministicJumpInstruction(
|
||||
|
||||
override fun toString(): String {
|
||||
val inVal = if (inputValue != null) "|$inputValue" else ""
|
||||
val labels = targetLabels.map { it.name }.joinToString(", ")
|
||||
val labels = targetLabels.joinToString(", ") { it.name }
|
||||
return "jmp?($labels$inVal)"
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
|
||||
|
||||
fun render(element: KtElementImplStub<*>, vararg relevantChildren: KtElement?): String? {
|
||||
if (element.stub == null) return element.text
|
||||
return relevantChildren.filterNotNull().map { it.getDebugText() }.joinToString("", "", "")
|
||||
return relevantChildren.filterNotNull().joinToString("", "", "") { it.getDebugText() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ private val SUPPORTED_ARGUMENT_TYPES = listOf(
|
||||
fun <TElement : KtElement> createByPattern(pattern: String, vararg args: Any, reformat: Boolean = true, factory: (String) -> TElement): TElement {
|
||||
val argumentTypes = args.map { arg ->
|
||||
SUPPORTED_ARGUMENT_TYPES.firstOrNull { it.klass.isInstance(arg) }
|
||||
?: throw IllegalArgumentException("Unsupported argument type: ${arg::class.java}, should be one of: ${SUPPORTED_ARGUMENT_TYPES.map { it.klass.simpleName }.joinToString()}")
|
||||
?: throw IllegalArgumentException("Unsupported argument type: ${arg::class.java}, should be one of: ${SUPPORTED_ARGUMENT_TYPES.joinToString { it.klass.simpleName }}")
|
||||
}
|
||||
|
||||
// convert arguments that can be converted into plain text
|
||||
|
||||
@@ -33,7 +33,7 @@ val STUB_TO_STRING_PREFIX = "KotlinStub$"
|
||||
open class KotlinStubBaseImpl<T : KtElementImplStub<*>>(parent: StubElement<*>?, elementType: IStubElementType<*, *>) : StubBase<T>(parent, elementType) {
|
||||
|
||||
override fun toString(): String {
|
||||
val stubInterface = this::class.java.interfaces.filter { it.name.contains("Stub") }.single()
|
||||
val stubInterface = this::class.java.interfaces.single { it.name.contains("Stub") }
|
||||
val propertiesValues = renderPropertyValues(stubInterface)
|
||||
if (propertiesValues.isEmpty()) {
|
||||
return "$STUB_TO_STRING_PREFIX$stubType"
|
||||
|
||||
@@ -377,7 +377,7 @@ class CallCompleter(
|
||||
expression = deparenthesizeOrGetSelector(expression)
|
||||
}
|
||||
|
||||
var shouldBeMadeNullable: Boolean = false
|
||||
var shouldBeMadeNullable = false
|
||||
expressions.asReversed().forEach { expression ->
|
||||
if (!(expression is KtParenthesizedExpression || expression is KtLabeledExpression || expression is KtAnnotatedExpression)) {
|
||||
shouldBeMadeNullable = hasNecessarySafeCall(expression, trace)
|
||||
|
||||
+3
-3
@@ -198,12 +198,12 @@ class NewResolutionOldInference(
|
||||
tracing: TracingStrategy,
|
||||
candidates: Collection<ResolutionCandidate<D>>
|
||||
): OverloadResolutionResultsImpl<D> {
|
||||
val resolvedCandidates = candidates.mapNotNull { candidate ->
|
||||
val resolvedCandidates = candidates.map { candidate ->
|
||||
val candidateTrace = TemporaryBindingTrace.create(basicCallContext.trace, "Context for resolve candidate")
|
||||
val resolvedCall = ResolvedCallImpl.create(candidate, candidateTrace, tracing, basicCallContext.dataFlowInfoForArguments)
|
||||
|
||||
if (candidate.descriptor.isHiddenInResolution(languageVersionSettings, basicCallContext.isSuperCall)) {
|
||||
return@mapNotNull MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), resolvedCall)
|
||||
return@map MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), resolvedCall)
|
||||
}
|
||||
|
||||
val callCandidateResolutionContext = CallCandidateResolutionContext.create(
|
||||
@@ -238,7 +238,7 @@ class NewResolutionOldInference(
|
||||
basicCallContext: BasicCallResolutionContext,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): OverloadResolutionResultsImpl<D> {
|
||||
val resolvedCalls = candidates.mapNotNull {
|
||||
val resolvedCalls = candidates.map {
|
||||
val (status, resolvedCall) = it
|
||||
if (resolvedCall is VariableAsFunctionResolvedCallImpl) {
|
||||
// todo hacks
|
||||
|
||||
+1
-1
@@ -295,7 +295,7 @@ class IncrementalJvmCompilerRunner(
|
||||
// todo: more optimal to save only last iteration, but it will require adding standalone-ic specific logs
|
||||
// (because jps rebuilds all files from last build if it failed and gradle rebuilds everything)
|
||||
allSourcesToCompile.addAll(sourcesToCompile)
|
||||
val text = allSourcesToCompile.map { it.canonicalPath }.joinToString(separator = System.getProperty("line.separator"))
|
||||
val text = allSourcesToCompile.joinToString(separator = System.getProperty("line.separator")) { it.canonicalPath }
|
||||
dirtySourcesSinceLastTimeFile.writeText(text)
|
||||
|
||||
val compilerOutput = compileChanged(listOf(targetId), sourcesToCompile.toSet(), args, { caches.incrementalCache }, lookupTracker, messageCollector)
|
||||
|
||||
+1
-2
@@ -239,8 +239,7 @@ class LocalFunctionsLowering(val context: BackendContext): DeclarationContainerL
|
||||
functionDescriptor.parentsWithSelf
|
||||
.takeWhile { it is FunctionDescriptor }
|
||||
.toList().reversed()
|
||||
.map { suggestLocalName(it) }
|
||||
.joinToString(separator = "$")
|
||||
.joinToString(separator = "$") { suggestLocalName(it) }
|
||||
)
|
||||
|
||||
private fun createTransformedDescriptor(localFunctionContext: LocalFunctionContext): FunctionDescriptor {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ abstract class ClassLowerWithContext : FileLoweringPass, IrElementTransformer<Ir
|
||||
private val irClass2Context = hashMapOf<IrClass, IrClassContext>()
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
val packageIr = irFile.declarations.filter { it.descriptor is FileClassDescriptor }.singleOrNull()
|
||||
val packageIr = irFile.declarations.singleOrNull { it.descriptor is FileClassDescriptor }
|
||||
if (packageIr != null) {
|
||||
visitClass(packageIr as IrClass, null)
|
||||
irFile.declarations.filterNot { it == packageIr }.forEach { it.accept(this, irClass2Context[packageIr]!!) }
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
|
||||
|
||||
val members = defaultImplsIrClass.declarations
|
||||
|
||||
irClass.declarations.filterIsInstance<IrFunction>().mapNotNull {
|
||||
irClass.declarations.filterIsInstance<IrFunction>().forEach {
|
||||
val descriptor = it.descriptor
|
||||
if (descriptor.modality != Modality.ABSTRACT) {
|
||||
val functionDescriptorImpl = createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper)
|
||||
|
||||
@@ -80,7 +80,7 @@ class MockKotlinClassifier(override val fqName: FqName,
|
||||
|
||||
override val supertypes: Collection<JavaClassifierType>
|
||||
get() = classOrObject.superTypeListEntries
|
||||
.mapNotNull { superTypeListEntry ->
|
||||
.map { superTypeListEntry ->
|
||||
val userType = superTypeListEntry.typeAsUserType
|
||||
arrayListOf<String>().apply {
|
||||
userType?.referencedName?.let { add(it) }
|
||||
|
||||
+2
-2
@@ -45,12 +45,12 @@ class TreeBasedTypeParameter(
|
||||
get() = false
|
||||
|
||||
override val upperBounds: Collection<JavaClassifierType>
|
||||
get() = tree.bounds.map {
|
||||
get() = tree.bounds.mapNotNull {
|
||||
when (it) {
|
||||
is JCTree.JCTypeApply -> TreeBasedGenericClassifierType(it, TreePath(treePath, it), javac)
|
||||
is JCTree.JCIdent -> TreeBasedNonGenericClassifierType(it, TreePath(treePath, it), javac)
|
||||
else -> null
|
||||
}
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
}
|
||||
+3
-4
@@ -147,12 +147,11 @@ class OverloadingConflictResolver<C : Any>(
|
||||
candidates.firstOrNull()
|
||||
else when (checkArgumentsMode) {
|
||||
CheckArgumentTypesMode.CHECK_CALLABLE_TYPE ->
|
||||
uniquifyCandidatesSet(candidates).filter {
|
||||
isDefinitelyMostSpecific(it, candidates) {
|
||||
call1, call2 ->
|
||||
uniquifyCandidatesSet(candidates).singleOrNull {
|
||||
isDefinitelyMostSpecific(it, candidates) { call1, call2 ->
|
||||
isNotLessSpecificCallableReference(call1.resultingDescriptor, call2.resultingDescriptor)
|
||||
}
|
||||
}.singleOrNull()
|
||||
}
|
||||
|
||||
CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS ->
|
||||
findMaximallySpecificCall(candidates, discriminateGenerics, isDebuggerContext)
|
||||
|
||||
Reference in New Issue
Block a user