Replace map { ... }.filterNotNull() with mapNotNull { ... }

This commit is contained in:
Ilya Gorbunov
2015-11-13 23:43:05 +03:00
parent 5b02a59cb7
commit 32151c077e
112 changed files with 197 additions and 269 deletions
@@ -500,8 +500,7 @@ class BasicCompletionSession(
val classOrObject = position.parents.firstIsInstanceOrNull<KtClassOrObject>() ?: return
val classDescriptor = resolutionFacade.resolveToDescriptor(classOrObject) as ClassDescriptor
var superClasses = classDescriptor.defaultType.constructor.supertypesWithAny()
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
.filterNotNull()
.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor }
if (callTypeAndReceiver.receiver != null) {
val referenceVariantsSet = referenceVariants!!.imported.toSet()
@@ -281,16 +281,14 @@ abstract class CompletionSession(
if (expectedInfos.isEmpty()) return null
var context = expectedInfos
.map { it.fuzzyType?.type?.constructor?.declarationDescriptor?.importableFqName }
.filterNotNull()
.mapNotNull { it.fuzzyType?.type?.constructor?.declarationDescriptor?.importableFqName }
.distinct()
.singleOrNull()
?.let { "expectedType=$it" }
if (context == null) {
context = expectedInfos
.map { it.expectedName }
.filterNotNull()
.mapNotNull { it.expectedName }
.distinct()
.singleOrNull()
?.let { "expectedName=$it" }
@@ -211,8 +211,7 @@ class ExpectedInfos(
val callExpression = (call.callElement as? KtExpression)?.getQualifiedExpressionForSelectorOrThis() ?: return results
val expectedFuzzyTypes = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures, useOuterCallsExpectedTypeCount - 1)
.calculate(callExpression)
.map { it.fuzzyType }
.filterNotNull()
.mapNotNull { it.fuzzyType }
if (expectedFuzzyTypes.isEmpty() || expectedFuzzyTypes.any { it.freeParameters.isNotEmpty() }) return results
return expectedFuzzyTypes
@@ -469,8 +468,7 @@ class ExpectedInfos(
if (functionLiteral != null) {
val literalExpression = functionLiteral.parent as KtFunctionLiteralExpression
return calculate(literalExpression)
.map { it.fuzzyType }
.filterNotNull()
.mapNotNull { it.fuzzyType }
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.type) }
.map {
val returnType = KotlinBuiltIns.getReturnTypeFromFunctionType(it.type)
@@ -68,13 +68,12 @@ class StaticMembersCompletion(
fun membersFromImports(file: KtFile): Collection<DeclarationDescriptor> {
val containers = file.importDirectives
.filter { !it.isAllUnder }
.map {
.mapNotNull {
it.targetDescriptors(resolutionFacade)
.map { it.containingDeclaration }
.distinct()
.singleOrNull() as? ClassDescriptor
}
.filterNotNull()
.toSet()
val result = ArrayList<DeclarationDescriptor>()
@@ -82,8 +82,7 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures = false).calculate(expression)
val functionTypes = expectedInfos
.map { it.fuzzyType?.type }
.filterNotNull()
.mapNotNull { it.fuzzyType?.type }
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it) }
.toSet()
if (functionTypes.size() <= 1) return false
@@ -39,8 +39,7 @@ object LambdaItems {
if (functionExpectedInfos.isEmpty()) return
val distinctTypes = functionExpectedInfos
.map { it.fuzzyType?.type }
.filterNotNull()
.mapNotNull { it.fuzzyType?.type }
.toSet()
val singleType = if (distinctTypes.size() == 1) distinctTypes.single() else null
@@ -32,8 +32,7 @@ object NameSimilarityWeigher : LookupElementWeigher("kotlin.nameSimilarity") {
fun calcNameSimilarity(name: String, expectedInfos: Collection<ExpectedInfo>): Int {
return expectedInfos
.map { it.expectedName }
.filterNotNull()
.mapNotNull { it.expectedName }
.map { calcNameSimilarity(name, it) }
.max() ?: 0
}
@@ -363,8 +363,7 @@ class SmartCompletion(
if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) {
descriptor.constructors
.filter(visibilityFilter)
.map { toLookupElement(it) }
.filterNotNullTo(this)
.mapNotNullTo(this) { toLookupElement(it) }
}
}
}