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
@@ -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()
}
@@ -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(
@@ -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)
}
}
@@ -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? {
@@ -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)
}
}
@@ -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(