Replace map + filterNotNull -> mapNotNull in project

This commit is contained in:
Alexander Udalov
2016-02-20 17:33:39 +03:00
parent 61f5e2f9cf
commit 1a5a077bd6
19 changed files with 52 additions and 54 deletions
@@ -16,7 +16,9 @@
package org.jetbrains.kotlin.preprocessor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.KtAnnotated
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtUserType
interface Conditional {
@@ -52,10 +54,10 @@ interface Conditional {
}
fun KtAnnotated.parseConditionalAnnotations(): List<Conditional> =
annotationEntries.map {
annotationEntries.mapNotNull {
val parser = Conditional.ANNOTATIONS.get(it.typeReferenceName)
parser?.parse?.invoke(it.valueArguments.splitToPositionalAndNamed())
}.filterNotNull()
}
val KtAnnotationEntry.typeReferenceName: String? get() =
@@ -31,9 +31,9 @@ import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
@@ -99,8 +99,7 @@ object JvmAnalyzerFacade : AnalyzerFacade<JvmPlatformParameters>() {
javaDescriptorResolver.packageFragmentProvider)
providersForModule += PackageFragmentProviderExtension.getInstances(project)
.map { it.getPackageFragmentProvider(project, moduleDescriptor, moduleContext.storageManager, trace, moduleInfo) }
.filterNotNull()
.mapNotNull { it.getPackageFragmentProvider(project, moduleDescriptor, moduleContext.storageManager, trace, moduleInfo) }
return ResolverForModule(CompositePackageFragmentProvider(providersForModule), container)
}
@@ -22,6 +22,7 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SmartFMap
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.cfg.ControlFlowBuilder.PredefinedOperation.*
import org.jetbrains.kotlin.cfg.pseudocode.ControlFlowInstructionsGenerator
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
@@ -31,30 +32,30 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithValu
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.MagicKind
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.lexer.KtToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.*
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import java.util.*
import org.jetbrains.kotlin.cfg.ControlFlowBuilder.PredefinedOperation.*
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.lexer.KtTokens.*
class ControlFlowProcessor(private val trace: BindingTrace) {
private val builder: ControlFlowBuilder = ControlFlowInstructionsGenerator()
@@ -202,7 +203,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
}
private fun elementsToValues(from: List<KtElement?>): List<PseudoValue> {
return from.map { element -> getBoundOrUnreachableValue(element) }.filterNotNull()
return from.mapNotNull { element -> getBoundOrUnreachableValue(element) }
}
private fun generateInitializer(declaration: KtDeclaration, initValue: PseudoValue) {
@@ -1268,7 +1269,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
private fun generateCallOrMarkUnresolved(call: KtCallElement) {
if (!generateCall(call)) {
val arguments = call.valueArguments.map { valueArgument -> valueArgument.getArgumentExpression() }.filterNotNull()
val arguments = call.valueArguments.mapNotNull { valueArgument -> valueArgument.getArgumentExpression() }
for (argument in arguments) {
generateInstructions(argument)
@@ -105,7 +105,7 @@ class ConstraintSystemBuilderImpl : ConstraintSystem.Builder {
}
internal fun getNestedTypeVariables(type: KotlinType): List<TypeVariable> =
type.getNestedTypeParameters().map { getMyTypeVariable(it) }.filterNotNull()
type.getNestedTypeParameters().mapNotNull { getMyTypeVariable(it) }
override fun addSubtypeConstraint(constrainingType: KotlinType?, subjectType: KotlinType?, constraintPosition: ConstraintPosition) {
addConstraint(SUB_TYPE, constrainingType, subjectType, ConstraintContext(constraintPosition, initial = true))
@@ -57,7 +57,7 @@ internal fun KotlinType.getNestedArguments(): List<TypeProjection> {
}
internal fun KotlinType.getNestedTypeParameters(): List<TypeParameterDescriptor> {
return getNestedArguments().map { typeProjection ->
return getNestedArguments().mapNotNull { typeProjection ->
typeProjection.type.constructor.declarationDescriptor as? TypeParameterDescriptor
}.filterNotNull()
}
}
@@ -268,7 +268,7 @@ class BindingContextSuppressCache(val context: BindingContext) : KotlinSuppressC
return descriptor.annotations.toList()
}
else {
return annotated.annotationEntries.map { context.get(BindingContext.ANNOTATION, it) }.filterNotNull()
return annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) }
}
}
}
}
@@ -470,9 +470,9 @@ class LazyJavaClassMemberScope(
simpleFunctionDescriptor: SimpleFunctionDescriptor
): Boolean {
val candidatesToOverride =
getFunctionsFromSupertypes(simpleFunctionDescriptor.name).map {
getFunctionsFromSupertypes(simpleFunctionDescriptor.name).mapNotNull {
BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(it)
}.filterNotNull()
}
return candidatesToOverride.any {
candidate ->
@@ -40,11 +40,10 @@ class LazyJavaPackageFragment(
}
internal val kotlinBinaryClasses by c.storageManager.createLazyValue {
val simpleNames = c.components.packageMapper.findPackageParts(fqName.asString())
simpleNames.map {
c.components.packageMapper.findPackageParts(fqName.asString()).mapNotNull {
val classId = ClassId(fqName, Name.identifier(it))
c.components.kotlinClassFinder.findKotlinClass(classId)
}.filterNotNull()
}
}
internal fun resolveTopLevelClass(javaClass: JavaClass) = topLevelClasses(javaClass)
@@ -132,7 +132,7 @@ fun KotlinType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<Ko
assert(isHeadTypeConstructor || !onlyHeadTypeConstructor) { "Only head type constructors should be computed" }
val qualifiers = indexedThisType[index]
val verticalSlice = indexedFromSupertypes.map { it.getOrElse(index, { null }) }.filterNotNull()
val verticalSlice = indexedFromSupertypes.mapNotNull { it.getOrNull(index) }
// Only the head type constructor is safely co-variant
qualifiers.computeQualifiersForOverride(verticalSlice, isCovariant && isHeadTypeConstructor)
@@ -142,8 +142,8 @@ fun KotlinType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<Ko
}
private fun KotlinType.computeQualifiersForOverride(fromSupertypes: Collection<KotlinType>, isCovariant: Boolean): JavaTypeQualifiers {
val nullabilityFromSupertypes = fromSupertypes.map { it.extractQualifiers().nullability }.filterNotNull().toSet()
val mutabilityFromSupertypes = fromSupertypes.map { it.extractQualifiers().mutability }.filterNotNull().toSet()
val nullabilityFromSupertypes = fromSupertypes.mapNotNull { it.extractQualifiers().nullability }.toSet()
val mutabilityFromSupertypes = fromSupertypes.mapNotNull { it.extractQualifiers().mutability }.toSet()
val own = extractQualifiersFromAnnotations()
@@ -122,13 +122,13 @@ class CompositeAnnotations(
override fun hasAnnotation(fqName: FqName) = delegates.asSequence().any { it.hasAnnotation(fqName) }
override fun findAnnotation(fqName: FqName) = delegates.asSequence().map { it.findAnnotation(fqName) }.filterNotNull().firstOrNull()
override fun findAnnotation(fqName: FqName) = delegates.asSequence().mapNotNull { it.findAnnotation(fqName) }.firstOrNull()
override fun findExternalAnnotation(fqName: FqName) = delegates.asSequence().map { it.findExternalAnnotation(fqName) }.filterNotNull().firstOrNull()
override fun findExternalAnnotation(fqName: FqName) = delegates.asSequence().mapNotNull { it.findExternalAnnotation(fqName) }.firstOrNull()
override fun getUseSiteTargetedAnnotations() = delegates.flatMap { it.getUseSiteTargetedAnnotations() }
override fun getAllAnnotations() = delegates.flatMap { it.getAllAnnotations() }
override fun iterator() = delegates.asSequence().flatMap { it.asSequence() }.iterator()
}
}
@@ -95,8 +95,7 @@ class DescriptorKindFilter(
override fun toString(): String {
val predefinedFilterName = DEBUG_PREDEFINED_FILTERS_MASK_NAMES.firstOrNull { it.mask == kindMask } ?.name
val kindString = predefinedFilterName ?: DEBUG_MASK_BIT_NAMES
.map { if (acceptsKinds(it.mask)) it.name else null }
.filterNotNull()
.mapNotNull { if (acceptsKinds(it.mask)) it.name else null }
.joinToString(separator = " | ")
return "DescriptorKindFilter($kindString, $excludes)"
@@ -138,21 +137,19 @@ class DescriptorKindFilter(
private class MaskToName(val mask: Int, val name: String)
private val DEBUG_PREDEFINED_FILTERS_MASK_NAMES = staticFields<DescriptorKindFilter>()
.map { field ->
.mapNotNull { field ->
val filter = field.get(null) as? DescriptorKindFilter
if (filter != null) MaskToName(filter.kindMask, field.name) else null
}
.filterNotNull()
.toReadOnlyList()
private val DEBUG_MASK_BIT_NAMES = staticFields<DescriptorKindFilter>()
.filter { it.type == Integer.TYPE }
.map { field ->
.mapNotNull { field ->
val mask = field.get(null) as Int
val isOneBitMask = mask == (mask and (-mask))
if (isOneBitMask) MaskToName(mask, field.name) else null
}
.filterNotNull()
.toReadOnlyList()
private inline fun <reified T : Any> staticFields() = T::class.java.fields.filter { Modifier.isStatic(it.modifiers) }
@@ -50,7 +50,7 @@ class AnnotationDeserializer(private val module: ModuleDescriptor) {
val constructor = annotationClass.constructors.singleOrNull()
if (constructor != null) {
val parameterByName = constructor.valueParameters.associateBy { it.name }
arguments = proto.argumentList.map { resolveArgument(it, parameterByName, nameResolver) }.filterNotNull().toMap()
arguments = proto.argumentList.mapNotNull { resolveArgument(it, parameterByName, nameResolver) }.toMap()
}
}
@@ -120,7 +120,7 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
}
override val nestedClasses: Collection<KClass<*>>
get() = descriptor.unsubstitutedInnerClassesScope.getContributedDescriptors().filterNot(DescriptorUtils::isEnumEntry).map {
get() = descriptor.unsubstitutedInnerClassesScope.getContributedDescriptors().filterNot(DescriptorUtils::isEnumEntry).mapNotNull {
nestedClass ->
val source = (nestedClass as DeclarationDescriptorWithSource).source
when (source) {
@@ -139,7 +139,7 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
}
else -> throw KotlinReflectionInternalError("Unsupported class: $nestedClass (source = $source)")
}
}.filterNotNull().map { KClassImpl(it) }
}.map { KClassImpl(it) }
@Suppress("UNCHECKED_CAST")
private val objectInstance_ = ReflectProperties.lazy {
@@ -75,10 +75,9 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
.filter { descriptor ->
descriptor !is MemberDescriptor || descriptor.visibility != Visibilities.INVISIBLE_FAKE
}
.map { descriptor ->
.mapNotNull { descriptor ->
descriptor.accept(visitor, Unit)
}
.filterNotNull()
}
private fun createProperty(descriptor: PropertyDescriptor): KPropertyImpl<*> {
@@ -171,7 +171,7 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
return annotatedDescriptor.annotations.toList()
}
else {
return annotated.annotationEntries.map { context.get(BindingContext.ANNOTATION, it) }.filterNotNull()
return annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) }
}
}
}, LibraryModificationTracker.getInstance(project), PsiModificationTracker.MODIFICATION_COUNT)
@@ -319,7 +319,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
private fun KtExpression.findOccurrences(occurrenceContainer: PsiElement): List<KtExpression> {
return toRange()
.match(occurrenceContainer, KotlinPsiUnifier.DEFAULT)
.map {
.mapNotNull {
val candidate = it.range.elements.first()
when (candidate) {
is KtExpression -> candidate
@@ -327,7 +327,6 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
else -> throw AssertionError("Unexpected candidate element: " + candidate.text)
} as? KtExpression
}
.filterNotNull()
}
private fun KtExpression.shouldReplaceOccurrence(bindingContext: BindingContext, container: PsiElement?): Boolean {
@@ -611,11 +611,11 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
val args = expression.operands.map {
codeConverter.convertExpression(it, expression.type).assignPrototype(it, commentsAndSpacesInheritance)
}
val operators = expression.operands.map {
val operators = expression.operands.mapNotNull {
expression.getTokenBeforeOperand(it)?.let {
Operator(it.tokenType).assignPrototype(it, commentsAndSpacesInheritance)
}
}.filterNotNull()
}
result = PolyadicExpression(args, operators).assignPrototype(expression)
}
@@ -22,7 +22,10 @@ import org.jetbrains.kotlin.android.synthetic.codegen.AndroidExpressionCodegenEx
import org.jetbrains.kotlin.android.synthetic.codegen.AndroidOnDestroyClassBuilderInterceptorExtension
import org.jetbrains.kotlin.android.synthetic.diagnostic.AndroidExtensionPropertiesCallChecker
import org.jetbrains.kotlin.android.synthetic.diagnostic.DefaultErrorMessagesAndroid
import org.jetbrains.kotlin.android.synthetic.res.*
import org.jetbrains.kotlin.android.synthetic.res.AndroidLayoutXmlFileManager
import org.jetbrains.kotlin.android.synthetic.res.AndroidVariant
import org.jetbrains.kotlin.android.synthetic.res.CliAndroidLayoutXmlFileManager
import org.jetbrains.kotlin.android.synthetic.res.CliAndroidPackageFragmentProviderExtension
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
import org.jetbrains.kotlin.compiler.plugin.CliOption
@@ -73,7 +76,7 @@ class AndroidComponentRegistrar : ComponentRegistrar {
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
val applicationPackage = configuration.get(AndroidConfigurationKeys.PACKAGE)
val variants = configuration.get(AndroidConfigurationKeys.VARIANT)?.map { parseVariant(it) }?.filterNotNull() ?: emptyList()
val variants = configuration.get(AndroidConfigurationKeys.VARIANT)?.mapNotNull { parseVariant(it) } ?: emptyList()
if (variants.isNotEmpty() && !applicationPackage.isNullOrBlank()) {
val layoutXmlFileManager = CliAndroidLayoutXmlFileManager(project, applicationPackage!!, variants)
@@ -41,7 +41,7 @@ class AndroidGotoDeclarationHandler : GotoDeclarationHandler {
val propertyDescriptor = resolvePropertyDescriptor(simpleNameExpression) ?: return null
val psiElements = layoutManager.propertyToXmlAttributes(propertyDescriptor)
val valueElements = psiElements.map { (it as? XmlAttribute)?.valueElement as? PsiElement }.filterNotNull()
val valueElements = psiElements.mapNotNull { (it as? XmlAttribute)?.valueElement as? PsiElement }
if (valueElements.isNotEmpty()) return valueElements.toTypedArray()
}
@@ -64,5 +64,4 @@ class AndroidGotoDeclarationHandler : GotoDeclarationHandler {
override fun getActionText(context: DataContext?): String? {
return null
}
}
}