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:
Ilya Gorbunov
2017-03-17 16:06:28 +03:00
parent e599688733
commit dce0da68c6
24 changed files with 43 additions and 48 deletions
@@ -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() =
@@ -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))
@@ -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
@@ -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) {