Cleanup: post-cleanup after deprecation cleanup in compiler
Replace `takeIf { !expr }` with `takeUnless { expr }`.
Cleanup redundant parethesis as in `listOf((expr))`.
Replace `listOf(expr)` with `expr.let(::listOf)` where the former caused significant indentation change.
This commit is contained in:
@@ -63,8 +63,7 @@ object BuiltinSpecialBridgesUtil {
|
||||
|
||||
val specialBridgeExists = function.getSpecialBridgeSignatureIfExists(signatureByDescriptor) != null
|
||||
val specialBridgesSignaturesInSuperClass = function.overriddenTreeAsSequence(useOriginal = true).mapNotNull {
|
||||
if (it === function) return@mapNotNull null
|
||||
it.getSpecialBridgeSignatureIfExists(signatureByDescriptor)
|
||||
it.takeUnless { it === function }?.getSpecialBridgeSignatureIfExists(signatureByDescriptor)
|
||||
}
|
||||
val isTherePossibleClashWithSpecialBridge =
|
||||
specialBridgeSignature in specialBridgesSignaturesInSuperClass
|
||||
|
||||
@@ -288,7 +288,7 @@ class CoroutineCodegen private constructor(
|
||||
}
|
||||
|
||||
private fun allFunctionParameters() =
|
||||
listOfNotNull(originalSuspendFunctionDescriptor.extensionReceiverParameter) +
|
||||
originalSuspendFunctionDescriptor.extensionReceiverParameter.let(::listOfNotNull) +
|
||||
originalSuspendFunctionDescriptor.valueParameters.orEmpty()
|
||||
|
||||
private fun ParameterDescriptor.getFieldInfoForCoroutineLambdaParameter() =
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ object KotlinCompilerClient {
|
||||
): CompileService? {
|
||||
val flagFile = System.getProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY)
|
||||
?.let(String::trimQuotes)
|
||||
?.takeIf { !it.isBlank() }
|
||||
?.takeUnless(String::isBlank)
|
||||
?.let(::File)
|
||||
?.takeIf(File::exists)
|
||||
?: makeAutodeletingFlagFile(baseDir = File(daemonOptions.runFilesPathOrDefault))
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ internal fun nonProjectionParametrization(samType: SimpleType): SimpleType? {
|
||||
projection.projectionKind == Variance.INVARIANT -> projection
|
||||
|
||||
projection.isStarProjection ->
|
||||
parameter.upperBounds.first().takeIf {
|
||||
t -> !t.contains { it.constructor.declarationDescriptor in parametersSet }
|
||||
parameter.upperBounds.first().takeUnless {
|
||||
t -> t.contains { it.constructor.declarationDescriptor in parametersSet }
|
||||
}?.asTypeProjection() ?: return@nonProjectionParametrization null
|
||||
|
||||
else -> projection.type.asTypeProjection()
|
||||
|
||||
@@ -417,12 +417,12 @@ class QualifiedExpressionResolver {
|
||||
val qualifierDescriptor = when (receiver) {
|
||||
is PackageQualifier -> {
|
||||
val childPackageFQN = receiver.descriptor.fqName.child(name)
|
||||
receiver.descriptor.module.getPackage(childPackageFQN).takeIf { !it.isEmpty() } ?:
|
||||
receiver.descriptor.module.getPackage(childPackageFQN).takeUnless { it.isEmpty() } ?:
|
||||
receiver.descriptor.memberScope.getContributedClassifier(name, location)
|
||||
}
|
||||
is ClassQualifier -> receiver.staticScope.getContributedClassifier(name, location)
|
||||
null -> context.scope.findClassifier(name, location) ?:
|
||||
context.scope.ownerDescriptor.module.getPackage(FqName.ROOT.child(name)).takeIf { !it.isEmpty() }
|
||||
context.scope.ownerDescriptor.module.getPackage(FqName.ROOT.child(name)).takeUnless { it.isEmpty() }
|
||||
is ReceiverValue -> receiver.type.memberScope.memberScopeAsImportingScope().findClassifier(name, location)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class DefaultImportProvider(
|
||||
defaultImports
|
||||
.filter { it.isAllUnder }
|
||||
.mapNotNull {
|
||||
it.fqName.takeIf { !it.isSubpackageOf(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) }
|
||||
it.fqName.takeUnless { it.isSubpackageOf(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) }
|
||||
}
|
||||
val nonKotlinAliasedTypeFqNames =
|
||||
builtinTypeAliases
|
||||
|
||||
+2
-2
@@ -167,8 +167,8 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass {
|
||||
private fun lowerEnumEntries() {
|
||||
irClass.declarations.transformFlat { declaration ->
|
||||
if (declaration is IrEnumEntry) {
|
||||
listOf(createFieldForEnumEntry(declaration)) +
|
||||
listOfNotNull(lowerEnumEntryClass(declaration.correspondingClass))
|
||||
listOfNotNull(createFieldForEnumEntry(declaration),
|
||||
lowerEnumEntryClass(declaration.correspondingClass))
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -50,12 +50,10 @@ fun KtElement.toLightElements(): List<PsiNamedElement> =
|
||||
is KtSecondaryConstructor -> LightClassUtil.getLightClassMethods(this as KtFunction)
|
||||
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this).allDeclarations
|
||||
is KtPropertyAccessor -> listOfNotNull(LightClassUtil.getLightClassAccessorMethod(this))
|
||||
is KtParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
||||
is KtParameter -> mutableListOf<PsiNamedElement>().also { elements ->
|
||||
toPsiParameters().toCollection(elements)
|
||||
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
|
||||
toAnnotationLightMethod()?.let { elements.add(it) }
|
||||
|
||||
elements
|
||||
toAnnotationLightMethod()?.let(elements::add)
|
||||
}
|
||||
is KtTypeParameter -> toPsiTypeParameters()
|
||||
is KtFile -> listOfNotNull(findFacadeClass())
|
||||
|
||||
@@ -334,12 +334,10 @@ class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesRe
|
||||
when (it) {
|
||||
is DependsOn -> if (it.path == "@{runtime}") listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath) else listOf(File(it.path))
|
||||
is DependsOnTwo -> listOf(it.path1, it.path2).flatMap {
|
||||
it.let {
|
||||
when {
|
||||
it.isBlank() -> emptyList()
|
||||
it == "@{runtime}" -> listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
|
||||
else -> listOf(File(it))
|
||||
}
|
||||
when {
|
||||
it.isBlank() -> emptyList()
|
||||
it == "@{runtime}" -> listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
|
||||
else -> listOf(File(it))
|
||||
}
|
||||
}
|
||||
is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error)
|
||||
|
||||
@@ -183,7 +183,7 @@ private class StringArgsConverter : ArgsConverter<String> {
|
||||
DoubleArray::class -> args.map { it?.toDoubleOrNull() }
|
||||
BooleanArray::class -> args.map { it?.toBoolean() }
|
||||
else -> null
|
||||
}?.toList()?.takeIf { list -> list.none { it == null } }?.toTypedArray()
|
||||
}?.toList()?.takeUnless { null in it }?.toTypedArray()
|
||||
|
||||
val parameterType = parameter.type
|
||||
if (parameterType.jvmErasure.java.isArray) {
|
||||
|
||||
@@ -166,7 +166,7 @@ fun getFunctionTypeArgumentProjections(
|
||||
arguments.addIfNotNull(receiverType?.asTypeProjection())
|
||||
|
||||
parameterTypes.mapIndexedTo(arguments) { index, type ->
|
||||
val name = parameterNames?.get(index)?.takeIf { !it.isSpecial }
|
||||
val name = parameterNames?.get(index)?.takeUnless { it.isSpecial }
|
||||
val typeToUse = if (name != null) {
|
||||
val annotationClass = builtIns.getBuiltInClassByName(KotlinBuiltIns.FQ_NAMES.parameterName.shortName())
|
||||
val nameValue = ConstantValueFactory(builtIns).createStringValue(name.asString())
|
||||
|
||||
+1
-1
@@ -33,4 +33,4 @@ interface VariableDescriptorWithAccessors : VariableDescriptor {
|
||||
}
|
||||
|
||||
val VariableDescriptorWithAccessors.accessors: List<VariableAccessorDescriptor>
|
||||
get() = listOfNotNull(getter) + listOfNotNull(setter)
|
||||
get() = listOfNotNull(getter, setter)
|
||||
|
||||
@@ -181,7 +181,7 @@ class FuzzyType(
|
||||
valueTransform = {
|
||||
val typeProjection = TypeProjectionImpl(Variance.INVARIANT, it.defaultType)
|
||||
val substitutedProjection = substitutorToKeepCapturedTypes.substitute(typeProjection)
|
||||
substitutedProjection?.takeIf { !ErrorUtils.containsUninferredParameter(it.type) } ?: typeProjection
|
||||
substitutedProjection?.takeUnless { ErrorUtils.containsUninferredParameter(it.type) } ?: typeProjection
|
||||
})
|
||||
return TypeConstructorSubstitution.createByConstructorsMap(substitutionMap, approximateCapturedTypes = true).buildSubstitutor()
|
||||
}
|
||||
|
||||
+5
-5
@@ -51,11 +51,11 @@ class StaticMembersCompletion(
|
||||
return object : AbstractLookupElementFactory {
|
||||
override fun createStandardLookupElementsForDescriptor(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean): Collection<LookupElement> {
|
||||
if (!useReceiverTypes) return emptyList()
|
||||
return listOfNotNull(lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false)
|
||||
.decorateAsStaticMember(descriptor, classNameAsLookupString = false)
|
||||
?.assignPriority(itemPriority)
|
||||
?.suppressAutoInsertion()
|
||||
)
|
||||
return lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false)
|
||||
.decorateAsStaticMember(descriptor, classNameAsLookupString = false)
|
||||
?.assignPriority(itemPriority)
|
||||
?.suppressAutoInsertion()
|
||||
.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
override fun createLookupElement(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean,
|
||||
|
||||
@@ -588,7 +588,7 @@ class ExpectedInfos(
|
||||
|
||||
val loopVar = forExpression.loopParameter
|
||||
val loopVarType = if (loopVar != null && loopVar.typeReference != null)
|
||||
(bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, loopVar] as VariableDescriptor).type.takeIf { !it.isError }
|
||||
(bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, loopVar] as VariableDescriptor).type.takeUnless { it.isError }
|
||||
else
|
||||
null
|
||||
|
||||
|
||||
@@ -478,7 +478,7 @@ class KotlinIndicesHelper(
|
||||
val translatedDeclaration = declarationTranslator(this) ?: return emptyList()
|
||||
if (!psiFilter(translatedDeclaration)) return emptyList()
|
||||
|
||||
return listOfNotNull((resolutionFacade.resolveToDescriptor(translatedDeclaration)))
|
||||
return listOfNotNull(resolutionFacade.resolveToDescriptor(translatedDeclaration))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
||||
return containingFile
|
||||
}
|
||||
|
||||
private fun KtElement?.check(): Boolean = this != null && this.takeIf { KotlinEditorTextProvider.isAcceptedAsCodeFragmentContext(it) } != null
|
||||
private fun KtElement?.check(): Boolean = this != null && KotlinEditorTextProvider.isAcceptedAsCodeFragmentContext(this)
|
||||
|
||||
//internal for tests
|
||||
fun createCodeFragmentForLabeledObjects(project: Project, markupMap: Map<*, ValueMarkup>): Pair<String, Map<String, Value>> {
|
||||
@@ -397,7 +397,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
javaFile?.packageName?.takeIf { !it.isBlank() }?.let {
|
||||
javaFile?.packageName?.takeUnless { it.isBlank() }?.let {
|
||||
sb.append("package ").append(it.quoteIfNeeded()).append("\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ abstract class ChangeCallableReturnTypeFix(
|
||||
val name = element.name
|
||||
if (name != null) {
|
||||
val container = element.resolveToDescriptor().containingDeclaration as? ClassDescriptor
|
||||
val containerName = container?.name?.takeIf { !it.isSpecial }?.asString()
|
||||
val containerName = container?.name?.takeUnless { it.isSpecial }?.asString()
|
||||
val fullName = if (containerName != null) "'$containerName.$name'" else "'$name'"
|
||||
if (element is KtParameter) {
|
||||
return "property $fullName"
|
||||
|
||||
@@ -50,7 +50,7 @@ open class ChangeVariableTypeFix(element: KtVariableDeclaration, type: KotlinTyp
|
||||
val name = element.name
|
||||
if (name != null) {
|
||||
val container = element.resolveToDescriptor().containingDeclaration as? ClassDescriptor
|
||||
val containerName = container?.name?.takeIf { !it.isSpecial }?.asString()
|
||||
val containerName = container?.name?.takeUnless { it.isSpecial }?.asString()
|
||||
return if (containerName != null) "'$containerName.$name'" else "'$name'"
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -488,8 +488,8 @@ internal class ImportForMismatchingArgumentsFix(
|
||||
return callExpression.valueArguments +
|
||||
callExpression.valueArguments.mapNotNull { it.getArgumentExpression() } +
|
||||
callExpression.valueArguments.mapNotNull { it.getArgumentName()?.referenceExpression } +
|
||||
listOfNotNull(callExpression.valueArgumentList) +
|
||||
listOfNotNull(callExpression.referenceExpression())
|
||||
listOfNotNull(callExpression.valueArgumentList,
|
||||
callExpression.referenceExpression())
|
||||
}
|
||||
|
||||
override fun fillCandidates(
|
||||
|
||||
+2
-2
@@ -37,11 +37,11 @@ abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : KtElement, D :
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> D?
|
||||
): List<QuickFixWithDelegateFactory> {
|
||||
return listOf(QuickFixWithDelegateFactory(actionPriority) factory@ {
|
||||
return QuickFixWithDelegateFactory(actionPriority) factory@ {
|
||||
val originalElement = originalElementPointer.element ?: return@factory null
|
||||
val data = quickFixDataFactory() ?: return@factory null
|
||||
createFix(originalElement, data)
|
||||
})
|
||||
}.let(::listOf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClassFromUs
|
||||
}
|
||||
|
||||
override fun getPossibleClassKinds(element: KtCallElement, diagnostic: Diagnostic): List<ClassKind> {
|
||||
return listOf((if (element is KtAnnotationEntry) ClassKind.ANNOTATION_CLASS else ClassKind.PLAIN_CLASS))
|
||||
return listOf(if (element is KtAnnotationEntry) ClassKind.ANNOTATION_CLASS else ClassKind.PLAIN_CLASS)
|
||||
}
|
||||
|
||||
override fun extractFixData(element: KtCallElement, diagnostic: Diagnostic): ClassInfo? {
|
||||
|
||||
+2
-2
@@ -76,10 +76,10 @@ object CreateTypeParameterUnmatchedTypeArgumentActionFactory : KotlinIntentionAc
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> CreateTypeParameterData?
|
||||
): List<QuickFixWithDelegateFactory> {
|
||||
return listOf(QuickFixWithDelegateFactory factory@ {
|
||||
return QuickFixWithDelegateFactory factory@ {
|
||||
val originalElement = originalElementPointer.element ?: return@factory null
|
||||
val data = quickFixDataFactory() ?: return@factory null
|
||||
CreateTypeParameterFromUsageFix(originalElement, data, false)
|
||||
})
|
||||
}.let(::listOf)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -561,11 +561,11 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
||||
componentFunctions.map { suggestNamesForComponent(it, project, collectingValidator) }
|
||||
}
|
||||
else {
|
||||
listOf(KotlinNameSuggester.suggestNamesByExpressionAndType(expression,
|
||||
substringInfo?.type,
|
||||
bindingContext,
|
||||
validator,
|
||||
"value"))
|
||||
KotlinNameSuggester.suggestNamesByExpressionAndType(expression,
|
||||
substringInfo?.type,
|
||||
bindingContext,
|
||||
validator,
|
||||
"value").let(::listOf)
|
||||
}
|
||||
|
||||
val introduceVariableContext = IntroduceVariableContext(
|
||||
|
||||
Reference in New Issue
Block a user