From c3b2d1829f494a4f3a5c57071698490390a95d92 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 8 Aug 2018 11:59:36 +0300 Subject: [PATCH] Apply "call chain -> sequence" to idea module --- .../idea/actions/KotlinAddImportAction.kt | 4 +- ...otlinGenerateSecondaryConstructorAction.kt | 10 ++-- .../kotlin/idea/actions/generate/utils.kt | 2 +- .../idea/codeInliner/MutableCodeToInline.kt | 2 +- .../KotlinCopyPasteReferenceProcessor.kt | 2 +- .../outdatedBundledCompilerNotification.kt | 2 +- .../copy/PlainTextPasteImportResolver.kt | 12 ++-- .../facet/KotlinFacetCompilerPluginsTab.kt | 24 ++++---- .../calls/KotlinCalleeTreeStructure.kt | 2 +- .../idea/inspections/CanBeValInspection.kt | 3 +- .../CanSealedSubClassBeObjectInspection.kt | 8 +-- .../idea/inspections/ReformatInspection.kt | 4 +- ...eplaceStringFormatWithLiteralInspection.kt | 4 +- .../inspections/SortModifiersInspection.kt | 2 +- .../AddAnnotationUseSiteTargetIntention.kt | 2 +- .../intentions/AddForLoopIndicesIntention.kt | 2 +- .../AddMissingDestructuringIntention.kt | 2 +- .../ConvertForEachToForLoopIntention.kt | 2 +- ...tPrimaryConstructorToSecondaryIntention.kt | 4 +- .../ConvertSealedClassToEnumIntention.kt | 5 +- .../intentions/IterateExpressionIntention.kt | 2 +- .../intentions/RemoveArgumentNameIntention.kt | 2 +- ...veExplicitLambdaParameterTypesIntention.kt | 2 +- .../RemoveForLoopIndicesIntention.kt | 2 +- ...SpecifyExplicitLambdaSignatureIntention.kt | 1 + .../SwapBinaryExpressionIntention.kt | 5 +- .../KotlinInlayParameterHintsProvider.kt | 2 +- .../idea/quickfix/AddAnnotationTargetFix.kt | 3 +- .../idea/quickfix/AddDefaultConstructorFix.kt | 3 +- .../quickfix/AddFunctionToSupertypeFix.kt | 2 + .../idea/quickfix/AddNameToArgumentFix.kt | 3 + .../ChangeMemberFunctionSignatureFix.kt | 6 +- .../kotlin/idea/quickfix/ImportFix.kt | 10 ++-- .../idea/quickfix/KotlinReferenceImporter.kt | 3 +- .../idea/quickfix/SuperClassNotInitialized.kt | 8 ++- .../callableBuilder/typeUtils.kt | 2 +- ...peParameterByUnresolvedRefActionFactory.kt | 16 ++--- .../migration/MigrateExternalExtensionFix.kt | 12 ++-- .../ReplaceWithAnnotationAnalyzer.kt | 2 + .../changeSignature/KotlinChangeInfo.kt | 8 +-- .../ui/KotlinChangeSignatureDialog.kt | 2 +- .../usages/KotlinCallerUsages.kt | 6 +- .../usages/KotlinFunctionCallUsage.kt | 4 +- .../MoveDeclarationsCopyPasteProcessor.kt | 4 +- .../idea/refactoring/elementRenderingUtils.kt | 6 +- .../inline/KotlinInlineTypeAliasHandler.kt | 15 ++--- .../extractClass/ExtractSuperRefactoring.kt | 2 +- .../extractableAnalysisUtil.kt | 2 +- .../extractionEngine/extractorUtil.kt | 2 +- .../KotlinIntroduceParameterDialog.kt | 2 +- .../KotlinIntroduceParameterHandler.kt | 59 +++++++++++-------- .../KotlinIntroduceTypeParameterHandler.kt | 18 +++--- .../KotlinIntroduceVariableHandler.kt | 4 +- .../KotlinInterfaceMemberDependencyGraph.kt | 6 +- .../memberInfo/KotlinMemberInfoStorage.kt | 21 ++++--- .../MoveKotlinDeclarationsProcessor.kt | 2 +- .../pullUp/KotlinPullUpHelperFactory.kt | 7 ++- .../idea/refactoring/pullUp/pullUpUtils.kt | 2 +- .../pushDown/pushDownConflictsUtils.kt | 3 +- .../jetbrains/kotlin/idea/slicer/Slicer.kt | 8 ++- .../KotlinCreateTestIntention.kt | 5 +- .../idea/util/ImportInsertHelperImpl.kt | 21 +++---- 62 files changed, 223 insertions(+), 170 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt index 9a423d0c8ad..74102af5454 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt @@ -83,7 +83,7 @@ internal fun createSingleImportActionForConstructor( .filterIsInstance() .flatMap { it.constructors } - val priority = sameFqNameDescriptors.map { prioritizer.priority(it) }.min() ?: return@mapNotNull null + val priority = sameFqNameDescriptors.asSequence().map { prioritizer.priority(it) }.min() ?: return@mapNotNull null Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority) }.sortedBy { it.priority }.map { it.variant } return KotlinAddImportAction(project, editor, element, variants) @@ -260,7 +260,7 @@ private class DescriptorGroupPrioritizer(file: KtFile) { private val prioritizer = Prioritizer(file, false) inner class Priority(val descriptors: List) : Comparable { - val ownDescriptorsPriority = descriptors.map { prioritizer.priority(it) }.max()!! + val ownDescriptorsPriority = descriptors.asSequence().map { prioritizer.priority(it) }.max()!! override fun compareTo(other: Priority): Int { val c1 = ownDescriptorsPriority.compareTo(other.ownDescriptorsPriority) diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt index 379558868c4..6ca5c0fff5c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt @@ -87,10 +87,12 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase< private fun choosePropertiesToInitialize(klass: KtClassOrObject, context: BindingContext): List { val candidates = klass.declarations - .filterIsInstance() - .filter { it.isVar || context.diagnostics.forElement(it).any { it.factory in Errors.MUST_BE_INITIALIZED_DIAGNOSTICS } } - .map { context.get(BindingContext.VARIABLE, it) as PropertyDescriptor } - .map { DescriptorMemberChooserObject(it.source.getPsi()!!, it) } + .asSequence() + .filterIsInstance() + .filter { it.isVar || context.diagnostics.forElement(it).any { it.factory in Errors.MUST_BE_INITIALIZED_DIAGNOSTICS } } + .map { context.get(BindingContext.VARIABLE, it) as PropertyDescriptor } + .map { DescriptorMemberChooserObject(it.source.getPsi()!!, it) } + .toList() if (ApplicationManager.getApplication().isUnitTestMode || candidates.isEmpty()) return candidates return with(MemberChooser(candidates.toTypedArray(), true, true, klass.project, false, null)) { diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt b/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt index 35c77c7da9f..1d6949b2c29 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt @@ -49,7 +49,7 @@ tailrec fun ClassDescriptor.findDeclaredFunction( fun getPropertiesToUseInGeneratedMember(classOrObject: KtClassOrObject): List { return ArrayList().apply { classOrObject.primaryConstructorParameters.filterTo(this) { it.hasValOrVar() } - classOrObject.declarations.filterIsInstance().filterTo(this) { + classOrObject.declarations.asSequence().filterIsInstance().filterTo(this) { val descriptor = it.unsafeResolveToDescriptor() when (descriptor) { is ValueParameterDescriptor -> true diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInliner/MutableCodeToInline.kt b/idea/src/org/jetbrains/kotlin/idea/codeInliner/MutableCodeToInline.kt index f7097996ba2..d1f0ebd2307 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInliner/MutableCodeToInline.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInliner/MutableCodeToInline.kt @@ -84,7 +84,7 @@ internal class MutableCodeToInline( internal fun CodeToInline.toMutable(): MutableCodeToInline { return MutableCodeToInline( mainExpression?.copied(), - statementsBefore.map { it.copied() }.toMutableList(), + statementsBefore.asSequence().map { it.copied() }.toMutableList(), fqNamesToImport.toMutableSet(), alwaysKeepMainExpression ) diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt index 49cc615ff1f..bc2500f9e4d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -347,7 +347,7 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor() private fun showRestoreReferencesDialog(project: Project, referencesToRestore: List): Collection { - val fqNames = referencesToRestore.map { it.refData.fqName }.toSortedSet() + val fqNames = referencesToRestore.asSequence().map { it.refData.fqName }.toSortedSet() if (ApplicationManager.getApplication().isUnitTestMode) { declarationsToImportSuggested = fqNames diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/outdatedBundledCompilerNotification.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/outdatedBundledCompilerNotification.kt index 74fb2e628e4..c6ad524ca0a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/outdatedBundledCompilerNotification.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/outdatedBundledCompilerNotification.kt @@ -115,7 +115,7 @@ fun createOutdatedBundledCompilerMessage(project: Project, bundledCompilerVersio } var modulesStr = - selectedNewerModulesInfos.take(NUMBER_OF_MODULES_TO_SHOW).joinToString(separator = "") { + selectedNewerModulesInfos.asSequence().take(NUMBER_OF_MODULES_TO_SHOW).joinToString(separator = "") { "
  • ${it.module.name} (${it.externalCompilerVersion})

  • " } diff --git a/idea/src/org/jetbrains/kotlin/idea/conversion/copy/PlainTextPasteImportResolver.kt b/idea/src/org/jetbrains/kotlin/idea/conversion/copy/PlainTextPasteImportResolver.kt index 7ac0d8ab585..3036517c6c0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/conversion/copy/PlainTextPasteImportResolver.kt +++ b/idea/src/org/jetbrains/kotlin/idea/conversion/copy/PlainTextPasteImportResolver.kt @@ -151,11 +151,13 @@ class PlainTextPasteImportResolver(val dataForConversion: DataForConversion, val } val members = (shortNameCache.getMethodsByName(referenceName, scope).asList() + - shortNameCache.getFieldsByName(referenceName, scope).asList()) - .map { it as PsiMember } - .filter { it.getNullableModuleInfo() != null } - .map { it to it.getJavaMemberDescriptor(resolutionFacade) as? DeclarationDescriptorWithVisibility } - .filter { canBeImported(it.second) } + shortNameCache.getFieldsByName(referenceName, scope).asList()) + .asSequence() + .map { it as PsiMember } + .filter { it.getNullableModuleInfo() != null } + .map { it to it.getJavaMemberDescriptor(resolutionFacade) as? DeclarationDescriptorWithVisibility } + .filter { canBeImported(it.second) } + .toList() members.singleOrNull()?.let { (psiMember, _) -> addImport(psiElementFactory.createImportStaticStatement(psiMember.containingClass!!, psiMember.name!!), true) diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt index 6e26be47f95..7449e338822 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt @@ -52,18 +52,18 @@ class KotlinFacetCompilerPluginsTab( val pluginInfos: List = ArrayList().apply { parsePluginOptions(configuration) - .sortedWith( - Comparator { o1, o2 -> - var result = o1.pluginId.compareTo(o2.pluginId) - if (result == 0) { - result = o1.optionName.compareTo(o2.optionName) - } - if (result == 0) { - result = o1.value.compareTo(o2.value) - } - result - } - ) + .sortedWith( + Comparator { o1, o2 -> + var result = o1.pluginId.compareTo(o2.pluginId) + if (result == 0) { + result = o1.optionName.compareTo(o2.optionName) + } + if (result == 0) { + result = o1.value.compareTo(o2.value) + } + result + } + ) .groupBy({ it.pluginId }) .mapTo(this) { PluginInfo(it.key, it.value.map { "${it.optionName}=${it.value}" }) } sortBy { it.id } diff --git a/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeTreeStructure.kt b/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeTreeStructure.kt index d153552c004..e3bfb14d299 100644 --- a/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeTreeStructure.kt +++ b/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeTreeStructure.kt @@ -44,7 +44,7 @@ class KotlinCalleeTreeStructure( is KtClassOrObject -> { superTypeListEntries.filterIsInstance() + getAnonymousInitializers().map { it.body } + - declarations.filterIsInstance().map { it.initializer } + declarations.asSequence().filterIsInstance().map { it.initializer }.toList() } else -> emptyList() }.filterNotNull() diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt index 6e58936b981..5a6c4860686 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt @@ -103,7 +103,8 @@ class CanBeValInspection : AbstractKotlinInspection() { private fun Pseudocode.collectWriteInstructions(descriptor: DeclarationDescriptor): Set = with (instructionsIncludingDeadCode) { filterIsInstance() - .filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor } + .asSequence() + .filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor } .toSet() + filterIsInstance() diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanSealedSubClassBeObjectInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanSealedSubClassBeObjectInspection.kt index f36b6648272..f315f6f02f2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanSealedSubClassBeObjectInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanSealedSubClassBeObjectInspection.kt @@ -74,9 +74,9 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() { } private fun List.withEmptyConstructors(): List { - return map { it.kotlinOrigin }.filterIsInstance() + return map { it.kotlinOrigin }.asSequence().filterIsInstance() .filter { it.primaryConstructorParameters.isEmpty() } - .filter { klass -> klass.secondaryConstructors.all { cons -> cons.valueParameters.isEmpty() } } + .filter { klass -> klass.secondaryConstructors.all { cons -> cons.valueParameters.isEmpty() } }.toList() } private fun List.thatHasNoCompanionObjects(): List { @@ -112,7 +112,7 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() { val body = getBody() return body == null || run { val declarations = body.declarations - declarations.filterIsInstance().none { property -> + declarations.asSequence().filterIsInstance().none { property -> // Simplified "backing field required" when { property.isAbstract() -> false @@ -121,7 +121,7 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() { !property.isVar -> property.getter == null else -> property.getter == null || property.setter == null } - } && declarations.filterIsInstance().none { function -> + } && declarations.asSequence().filterIsInstance().none { function -> val name = function.name val valueParameters = function.valueParameters val noTypeParameters = function.typeParameters.isEmpty() diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReformatInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReformatInspection.kt index b7af27b1742..8432d955d47 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReformatInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReformatInspection.kt @@ -51,7 +51,7 @@ class ReformatInspection : LocalInspectionTool() { val changes = collectFormattingChanges(file) if (changes.isEmpty()) return null - val elements = changes.map { + val elements = changes.asSequence().map { val rangeOffset = when (it) { is ShiftIndentInsideRange -> it.range.startOffset is ReplaceWhiteSpace -> it.textRange.startOffset @@ -62,7 +62,7 @@ class ReformatInspection : LocalInspectionTool() { if (leaf is PsiWhiteSpace && isEmptyLineReformat(leaf, it)) return@map null leaf - }.filterNotNull() + }.filterNotNull().toList() return elements.map { ProblemDescriptorImpl( diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceStringFormatWithLiteralInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceStringFormatWithLiteralInspection.kt index 600d33ee671..55a45922823 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceStringFormatWithLiteralInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceStringFormatWithLiteralInspection.kt @@ -49,7 +49,7 @@ class ReplaceStringFormatWithLiteralInspection : AbstractKotlinInspection() { } val context = callExpression.analyze(BodyResolveMode.PARTIAL) - if (args.drop(1).any { it.isSubtypeOfFormattable(context) }) return + if (args.asSequence().drop(1).any { it.isSubtypeOfFormattable(context) }) return holder.registerProblem( qualifiedExpression ?: callExpression, @@ -75,7 +75,7 @@ class ReplaceStringFormatWithLiteralInspection : AbstractKotlinInspection() { val args = callExpression.valueArguments.mapNotNull { it.getArgumentExpression() } val format = args[0].text.removePrefix("\"").removeSuffix("\"") - val replaceArgs = args.drop(1).mapTo(LinkedList()) { ConvertToStringTemplateIntention.buildText(it, false) } + val replaceArgs = args.asSequence().drop(1).mapTo(LinkedList()) { ConvertToStringTemplateIntention.buildText(it, false) } val stringLiteral = stringPlaceHolder.replace(format) { replaceArgs.pop() } (qualifiedExpression ?: callExpression).also { it.replace(KtPsiFactory(it).createStringTemplate(stringLiteral)) } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/SortModifiersInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/SortModifiersInspection.kt index 7d88e076d69..a44401e7bd9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/SortModifiersInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/SortModifiersInspection.kt @@ -32,7 +32,7 @@ class SortModifiersInspection : AbstractKotlinInspection(), CleanupLocalInspecti } } - val modifiers = modifierElements.mapNotNull { it.node.elementType as? KtModifierKeywordToken }.toList() + val modifiers = modifierElements.asSequence().mapNotNull { it.node.elementType as? KtModifierKeywordToken }.toList() if (modifiers.isEmpty()) return val startElement = modifierElements.firstOrNull { it.node.elementType is KtModifierKeywordToken } ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt index 595849715a3..4be23f239e3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddAnnotationUseSiteTargetIntention.kt @@ -133,7 +133,7 @@ private fun KtAnnotationEntry.applicableUseSiteTargets(): List(KtForExpression::class.java, "Add indices to 'for' loop"), LowPriorityAction { private val WITH_INDEX_NAME = "withIndex" - private val WITH_INDEX_FQ_NAMES = listOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet() + private val WITH_INDEX_FQ_NAMES = sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet() override fun applicabilityRange(element: KtForExpression): TextRange? { if (element.loopParameter == null) return null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt index a3a4ecb0128..01693b8cd0b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddMissingDestructuringIntention.kt @@ -47,7 +47,7 @@ class AddMissingDestructuringIntention : SelfTargetingIntention(K if (entriesToAdd.isNotEmpty()) { val firstEntry = entriesToAdd - .reversed() - .map { klass.addDeclarationBefore(it, null) } + .reversed() + .asSequence() + .map { klass.addDeclarationBefore(it, null) } .last() // TODO: Add formatter rule firstEntry.parent.addBefore(psiFactory.createNewLine(), firstEntry) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt index 25241323d5d..998f537783c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt @@ -79,7 +79,7 @@ class IterateExpressionIntention : SelfTargetingIntention(KtExpres listOf(KotlinNameSuggester.suggestIterationVariableNames(element, elementType, bindingContext, nameValidator, "e")) } - val paramPattern = (names.singleOrNull()?.first() + val paramPattern = (names.asSequence().singleOrNull()?.first() ?: psiFactory.createDestructuringParameter(names.indices.joinToString(prefix = "(", postfix = ")") { "p$it" })) var forExpression = psiFactory.createExpressionByPattern("for($0 in $1) {\nx\n}", paramPattern, element) as KtForExpression forExpression = element.replaced(forExpression) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveArgumentNameIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveArgumentNameIntention.kt index 9c247c6c7f9..894d2579219 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveArgumentNameIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveArgumentNameIntention.kt @@ -34,7 +34,7 @@ class RemoveArgumentNameIntention val argumentList = element.parent as? KtValueArgumentList ?: return null val arguments = argumentList.arguments - if (arguments.takeWhile { it != element }.any { it.isNamed() }) return null + if (arguments.asSequence().takeWhile { it != element }.any { it.isNamed() }) return null val callExpr = argumentList.parent as? KtCallElement ?: return null val resolvedCall = callExpr.resolveToCall() ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt index 08a3ba3a42e..3a369688882 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt @@ -31,7 +31,7 @@ class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention(KtForExpression::class.java, "Remove indices in 'for' loop") { private val WITH_INDEX_NAME = "withIndex" - private val WITH_INDEX_FQ_NAMES = listOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet() + private val WITH_INDEX_FQ_NAMES = sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet() override fun applicabilityRange(element: KtForExpression): TextRange? { val loopRange = element.loopRange as? KtDotQualifiedExpression ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt index bf54524b8b0..f398cfcd37e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyExplicitLambdaSignatureIntention.kt @@ -48,6 +48,7 @@ class SpecifyExplicitLambdaSignatureIntention : SelfTargetingOffsetIndependentIn val functionDescriptor = element.analyze(BodyResolveMode.PARTIAL)[BindingContext.FUNCTION, functionLiteral]!! val parameterString = functionDescriptor.valueParameters + .asSequence() .mapIndexed { index, parameterDescriptor -> parameterDescriptor.render(psiName = functionLiteral.valueParameters.getOrNull(index)?.let { it.name ?: it.destructuringDeclaration?.text diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt index 31bee4889e7..4724eae470b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt @@ -31,8 +31,9 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention companion object { private val SUPPORTED_OPERATIONS = setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ) - private val SUPPORTED_OPERATION_NAMES = SUPPORTED_OPERATIONS.mapNotNull { OperatorConventions.BINARY_OPERATION_NAMES[it]?.asString() }.toSet() + - setOf("xor", "or", "and", "equals") + private val SUPPORTED_OPERATION_NAMES = + SUPPORTED_OPERATIONS.asSequence().mapNotNull { OperatorConventions.BINARY_OPERATION_NAMES[it]?.asString() }.toSet() + + setOf("xor", "or", "and", "equals") } override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt index abd3d0e5429..add5f445a13 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt @@ -174,7 +174,7 @@ class KotlinInlayParameterHintsProvider : InlayParameterHintsProvider { val resolvedCallee = resolvedCall?.candidateDescriptor if (resolvedCallee is FunctionDescriptor) { val paramNames = - resolvedCallee.valueParameters.map { it.name }.filter { !it.isSpecial }.map(Name::asString) + resolvedCallee.valueParameters.asSequence().map { it.name }.filter { !it.isSpecial }.map(Name::asString).toList() val fqName = if (resolvedCallee is ConstructorDescriptor) resolvedCallee.containingDeclaration.fqNameSafe.asString() else diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddAnnotationTargetFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddAnnotationTargetFix.kt index 6a288f30c35..34f2a90f27b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddAnnotationTargetFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddAnnotationTargetFix.kt @@ -92,7 +92,8 @@ private fun KtAnnotationEntry.getRequiredAnnotationTargets(annotationClass: KtCl } }.flatten().toSet() val annotationTargetValueNames = AnnotationTarget.values().map { it.name } - return (requiredTargets + otherReferenceRequiredTargets).distinct().filter { it.name in annotationTargetValueNames } + return (requiredTargets + otherReferenceRequiredTargets).asSequence().distinct().filter { it.name in annotationTargetValueNames } + .toList() } private fun getActualTargetList(annotated: PsiTarget): AnnotationChecker.Companion.TargetList { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddDefaultConstructorFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddDefaultConstructorFix.kt index 994ac6ddde1..4921649bb97 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddDefaultConstructorFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddDefaultConstructorFix.kt @@ -40,7 +40,8 @@ class AddDefaultConstructorFix(expectClass: KtClass) : KotlinQuickFixAction() ?: return null val context = derivedClass.analyze() - val baseTypeCallEntry = derivedClass.superTypeListEntries.filterIsInstance().firstOrNull() ?: return null + val baseTypeCallEntry = derivedClass.superTypeListEntries.asSequence().filterIsInstance().firstOrNull() + ?: return null val baseClass = superTypeEntryToClass(baseTypeCallEntry, context) ?: return null return AddDefaultConstructorFix(baseClass) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt index 843f915f0f2..4b000804d08 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt @@ -164,8 +164,10 @@ class AddFunctionToSupertypeFix private constructor( // TODO: filter out impossible supertypes (for example when argument's type isn't visible in a superclass). return getSuperClasses(containingClass) + .asSequence() .filterNot { KotlinBuiltIns.isAnyOrNullableAny(it.defaultType) } .map { generateFunctionSignatureForType(functionDescriptor, it) } + .toList() } private fun MutableList.sortSubtypesFirst(): List { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt index 6e4bc2b465e..212e6abc800 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt @@ -74,6 +74,7 @@ class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction() .filter { argumentMatch -> argumentType == null || argumentType.isError || !argumentMatch.isError() } @@ -81,8 +82,10 @@ class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction + val parameters = newParameters.asSequence().withIndex().map { (index, parameter) -> ValueParameterDescriptorImpl( descriptor, null, index, parameter.annotations, parameter.name, parameter.returnType!!, parameter.declaresDefaultValue(), parameter.isCrossinline, parameter.isNoinline, parameter.varargElementType, SourceElement.NO_SOURCE ) - } + }.toList() return descriptor.apply { initialize( diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt index 78a7979a541..777ce941313 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt @@ -145,10 +145,12 @@ internal abstract class ImportFixBase protected constructor( if (importNames.isEmpty()) return emptyList() return importNames - .flatMap { collectSuggestionsForName(it, callTypeAndReceiver) } - .distinct() - .map { it.fqNameSafe } - .distinct() + .flatMap { collectSuggestionsForName(it, callTypeAndReceiver) } + .asSequence() + .distinct() + .map { it.fqNameSafe } + .distinct() + .toList() } private fun collectSuggestionsForName(name: Name, callTypeAndReceiver: CallTypeAndReceiver<*, *>): Collection { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt index d984d08b6d9..7b01f864933 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt @@ -68,7 +68,8 @@ class KotlinReferenceImporter : ReferenceImporter { ): ImportFixBase? { var importFix: ImportFixBase? = null DaemonCodeAnalyzerEx.processHighlights(editor.document, file.project, null, offset, offset) { info -> - importFix = info.quickFixActionRanges?.map { it.first.action }?.filterIsInstance>()?.firstOrNull() + importFix = info.quickFixActionRanges?.asSequence() + ?.map { it.first.action }?.filterIsInstance>()?.firstOrNull() importFix == null } return importFix diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt index 41173a32a93..803d5d2c65b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt @@ -83,8 +83,10 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() { val substitutor = TypeConstructorSubstitution.create(superClass.typeConstructor, superType.arguments).buildSubstitutor() val substitutedConstructors = constructors + .asSequence() .filter { it.valueParameters.isNotEmpty() } .mapNotNull { it.substitute(substitutor) } + .toList() if (substitutedConstructors.isNotEmpty()) { val parameterTypes: List> = substitutedConstructors.map { @@ -93,7 +95,7 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() { fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size == parameterTypes.size - val maxParams = parameterTypes.map { it.size }.max()!! + val maxParams = parameterTypes.asSequence().map { it.size }.max()!! val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) { maxParams } else { @@ -101,7 +103,9 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() { } for ((constructor, types) in substitutedConstructors.zip(parameterTypes)) { - val typesRendered = types.take(maxParamsToDisplay).map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) } + val typesRendered = + types.asSequence().take(maxParamsToDisplay).map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) } + .toList() val parameterString = typesRendered.joinToString(", ", "(", if (types.size <= maxParamsToDisplay) ")" else ",...)") val text = "Add constructor parameters from " + superClass.name.asString() + parameterString fixes.addIfNotNull(AddParametersFix.create(delegator, classOrObjectDeclaration, constructor, text)) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index e82e444c722..7c21f1c4602 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -333,7 +333,7 @@ private fun TypePredicate.getRepresentativeTypes(): Set { is AllSubtypes -> Collections.singleton(upperBound) is ForAllTypes -> { if (typeSets.isEmpty()) AllTypes.getRepresentativeTypes() - else typeSets.map { it.getRepresentativeTypes() }.reduce { a, b -> a.intersect(b) } + else typeSets.asSequence().map { it.getRepresentativeTypes() }.reduce { a, b -> a.intersect(b) } } is ForSomeType -> typeSets.flatMapTo(LinkedHashSet()) { it.getRepresentativeTypes() } is AllTypes -> emptySet() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterByUnresolvedRefActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterByUnresolvedRefActionFactory.kt index e74e477d8fd..8989b86fbc2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterByUnresolvedRefActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterByUnresolvedRefActionFactory.kt @@ -84,14 +84,16 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa val ktUserType = originalElementPointer.element ?: return emptyList() val name = ktUserType.referencedName ?: return emptyList() return getPossibleTypeParameterContainers(ktUserType) - .filter { it.typeParameters.all { it.name != name } } - .map { - QuickFixWithDelegateFactory factory@ { - val originalElement = originalElementPointer.element ?: return@factory null - val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null - CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true) - } + .asSequence() + .filter { it.typeParameters.all { it.name != name } } + .map { + QuickFixWithDelegateFactory factory@ { + val originalElement = originalElementPointer.element ?: return@factory null + val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null + CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true) } + } + .toList() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt index 27408cc7c87..540a72ddb55 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt @@ -64,11 +64,13 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration) } private fun fixNativeClass(containingClass: KtClassOrObject) { - val membersToFix = containingClass.declarations.filterIsInstance().filter { isMemberDeclaration(it) && !isMemberExtensionDeclaration(it) }. map { - it to fetchJsNativeAnnotations(it) - }.filter { - it.second.annotations.isNotEmpty() - } + val membersToFix = + containingClass.declarations.asSequence().filterIsInstance() + .filter { isMemberDeclaration(it) && !isMemberExtensionDeclaration(it) }. map { + it to fetchJsNativeAnnotations(it) + }.filter { + it.second.annotations.isNotEmpty() + }.toList() membersToFix.asReversed().forEach { (memberDeclaration, annotations) -> if (annotations.nativeAnnotation != null && !annotations.isGetter && !annotations.isSetter && !annotations.isInvoke) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt index f58d660d6e8..ce36f194e43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt @@ -169,10 +169,12 @@ object ReplaceWithAnnotationAnalyzer { private fun importFqNames(annotation: ReplaceWith): List { return annotation.imports + .asSequence() .filter { FqNameUnsafe.isValid(it) } .map(::FqNameUnsafe) .filter(FqNameUnsafe::isSafe) .map(FqNameUnsafe::toSafe) + .toList() } private fun getResolutionScope( diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeInfo.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeInfo.kt index 8c7eba20ac7..313007976e7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeInfo.kt @@ -126,7 +126,7 @@ open class KotlinChangeInfo( fun hasAppendedParametersOnly(): Boolean { val oldParamCount = originalBaseFunctionDescriptor.valueParameters.size - return newParameters.withIndex().all { (i, p) -> if (i < oldParamCount) p.oldIndex == i else p.isNewParameter } + return newParameters.asSequence().withIndex().all { (i, p) -> if (i < oldParamCount) p.oldIndex == i else p.isNewParameter } } override fun getNewParameters(): Array = newParameters.toTypedArray() @@ -334,7 +334,7 @@ open class KotlinChangeInfo( val mandatoryParams = parameters.toMutableList() val defaultValues = ArrayList() return psiMethods.map { - JvmOverloadSignature(it, mandatoryParams.map(getPsi).toSet(), defaultValues.toSet()).apply { + JvmOverloadSignature(it, mandatoryParams.asSequence().map(getPsi).toSet(), defaultValues.toSet()).apply { val param = mandatoryParams.removeLast { getDefaultValue(it) != null } ?: return@apply defaultValues.add(getDefaultValue(param)!!) } @@ -428,13 +428,13 @@ open class KotlinChangeInfo( var defaultValuesRemained = defaultValuesToRetain for (param in newParameterList) { if (param.isNewParameter || param.defaultValueForParameter == null || defaultValuesRemained-- > 0) continue - newParameterList.withIndex().filter { it.value.oldIndex >= param.oldIndex }.forEach { oldIndices[it.index]-- } + newParameterList.asSequence().withIndex().filter { it.value.oldIndex >= param.oldIndex }.toList().forEach { oldIndices[it.index]-- } } defaultValuesRemained = defaultValuesToRetain val oldParameterCount = originalPsiMethod.parameterList.parametersCount var indexInCurrentPsiMethod = 0 - return newParameterList.withIndex() + return newParameterList.asSequence().withIndex() .mapNotNullTo(ArrayList()) map@ { pair -> val (i, info) = pair diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt index d3bf9ddad0c..59d618977a3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt @@ -136,7 +136,7 @@ class KotlinChangeSignatureDialog( } private fun getColumnTextMaxLength(nameFunction: Function1, String?>) = - parametersTableModel.items.map { nameFunction(it)?.length ?: 0 }.max() ?: 0 + parametersTableModel.items.asSequence().map { nameFunction(it)?.length ?: 0 }.max() ?: 0 private fun getParamNamesMaxLength() = getColumnTextMaxLength { getPresentationName(it) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallerUsages.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallerUsages.kt index 4eaf9ed4818..23a459fd733 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallerUsages.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallerUsages.kt @@ -35,8 +35,10 @@ class KotlinCallerUsage(element: KtNamedDeclaration): KotlinUsageInfo null } ?: return true changeInfo.getNonReceiverParameters() - .withIndex() - .filter { it.value.isNewParameter } + .asSequence() + .withIndex() + .filter { it.value.isNewParameter } + .toList() .forEach { val newParameter = it.value.getDeclarationSignature(it.index, changeInfo.methodDescriptor.originalPrimaryCallable) parameterList.addParameter(newParameter).addToShorteningWaitSet() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt index 7c496a7bf98..b463e9bc151 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt @@ -335,7 +335,7 @@ class KotlinFunctionCallUsage( // Do not add extension receiver to calls with explicit dispatch receiver if (newReceiverInfo != null && fullCallElement is KtQualifiedExpression && dispatchReceiver is ExpressionReceiver) return element - val newArgumentInfos = newParameters.withIndex().map { + val newArgumentInfos = newParameters.asSequence().withIndex().map { val (index, param) = it val oldIndex = param.oldIndex val resolvedArgument = if (oldIndex >= 0) getResolvedValueArgument(oldIndex) else null @@ -346,7 +346,7 @@ class KotlinFunctionCallUsage( receiverValue = receiverValue.wrapInvalidated(element) } ArgumentInfo(param, index, resolvedArgument, receiverValue) - } + }.toList() val lastParameterIndex = newParameters.lastIndex var firstNamedIndex = newArgumentInfos.firstOrNull { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsCopyPasteProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsCopyPasteProcessor.kt index 0b3a2599afd..21e7f12671d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsCopyPasteProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsCopyPasteProcessor.kt @@ -65,7 +65,7 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor null is KtClassBody -> (parent.parent as? KtObjectDeclaration)?.fqName?.asString() ?: return emptyList() @@ -73,7 +73,7 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor { val exprText = if (outputValue.callSiteReturn) { - val firstReturn = outputValue.originalExpressions.filterIsInstance().firstOrNull() + val firstReturn = outputValue.originalExpressions.asSequence().filterIsInstance().firstOrNull() val label = firstReturn?.getTargetLabel()?.text ?: "" "return$label $callText" } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt index 08eb01df87a..6197a65e20c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt @@ -248,7 +248,7 @@ class KotlinIntroduceParameterDialog private constructor( val space = if (statement.isMultiLine()) "\n" else " " val parameters = function.valueParameters val parametersText = if (parameters.isNotEmpty()) { - " " + parameters.map { it.name }.joinToString() + " ->" + " " + parameters.asSequence().map { it.name }.joinToString() + " ->" } else "" val text = "{$parametersText$space${statement.text}$space}" diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt index 084e4ed45e0..a06ee2ce5a3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt @@ -124,12 +124,14 @@ fun getParametersToRemove( val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() } return parametersUsages.entrySet() - .filter { - it.value.all { paramUsage -> - occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramUsage.textRange) } - } + .asSequence() + .filter { + it.value.all { paramUsage -> + occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramUsage.textRange) } } - .map { it.key } + } + .map { it.key } + .toList() } fun IntroduceParameterDescriptor.performRefactoring(onExit: (() -> Unit)? = null) { @@ -140,12 +142,12 @@ fun IntroduceParameterDescriptor.performRefactoring(onExit: (() -> Unit)? = null val parameters = callable.getValueParameters() val withReceiver = methodDescriptor.receiver != null parametersToRemove - .map { - if (it is KtParameter) { - parameters.indexOf(it) + if (withReceiver) 1 else 0 - } else 0 - } - .sortedDescending() + .map { + if (it is KtParameter) { + parameters.indexOf(it) + if (withReceiver) 1 else 0 + } else 0 + } + .sortedDescending() .forEach { methodDescriptor.removeParameter(it) } } @@ -269,28 +271,33 @@ open class KotlinIntroduceParameterHandler( val parametersUsages = findInternalUsagesOfParametersAndReceiver(targetParent, functionDescriptor) ?: return - val forbiddenRanges = (targetParent as? KtClass)?.declarations?.filter(::isObjectOrNonInnerClass)?.map { it.textRange } - ?: Collections.emptyList() + val forbiddenRanges = (targetParent as? KtClass)?.declarations?.asSequence() + ?.filter(::isObjectOrNonInnerClass) + ?.map { it.textRange } + ?.toList() + ?: Collections.emptyList() val occurrencesToReplace = if (expression is KtProperty) { ReferencesSearch.search(expression).mapNotNullTo(SmartList(expression.toRange())) { it.element?.toRange() } } else { expression.toRange() - .match(targetParent, KotlinPsiUnifier.DEFAULT) - .filterNot { - val textRange = it.range.getPhysicalTextRange() - forbiddenRanges.any { it.intersects(textRange) } - } - .mapNotNull { - val matchedElement = it.range.elements.singleOrNull() - val matchedExpr = when (matchedElement) { - is KtExpression -> matchedElement - is KtStringTemplateEntryWithExpression -> matchedElement.expression - else -> null - } - matchedExpr?.toRange() + .match(targetParent, KotlinPsiUnifier.DEFAULT) + .asSequence() + .filterNot { + val textRange = it.range.getPhysicalTextRange() + forbiddenRanges.any { it.intersects(textRange) } + } + .mapNotNull { + val matchedElement = it.range.elements.singleOrNull() + val matchedExpr = when (matchedElement) { + is KtExpression -> matchedElement + is KtStringTemplateEntryWithExpression -> matchedElement.expression + else -> null } + matchedExpr?.toRange() + } + .toList() } project.executeCommand( diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeParameter/KotlinIntroduceTypeParameterHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeParameter/KotlinIntroduceTypeParameterHandler.kt index 4e73a91aa8b..d2eae7ffb27 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeParameter/KotlinIntroduceTypeParameterHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceTypeParameter/KotlinIntroduceTypeParameterHandler.kt @@ -117,14 +117,16 @@ object KotlinIntroduceTypeParameterHandler : RefactoringActionHandler { val parameterRefElement = KtPsiFactory(project).createType(restoredTypeParameter.name ?: "_").typeElement!! val duplicateRanges = restoredOriginalTypeElement - .toRange() - .match(restoredOwner, KotlinPsiUnifier.DEFAULT) - .filterNot { - val textRange = it.range.getTextRange() - restoredOriginalTypeElement.textRange.intersects(textRange) - || restoredOwner.typeParameterList?.textRange?.intersects(textRange) ?: false - } - .map { it.range.elements.toRange() } + .toRange() + .match(restoredOwner, KotlinPsiUnifier.DEFAULT) + .asSequence() + .filterNot { + val textRange = it.range.getTextRange() + restoredOriginalTypeElement.textRange.intersects(textRange) + || restoredOwner.typeParameterList?.textRange?.intersects(textRange) ?: false + } + .map { it.range.elements.toRange() } + .toList() runWriteAction { restoredOriginalTypeElement.replace(parameterRefElement) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt index af9d0971f83..365ea849897 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt @@ -124,7 +124,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler { private fun replaceExpression(expressionToReplace: KtExpression, addToReferences: Boolean): KtExpression { val isActualExpression = expression == expressionToReplace - val replacement = psiFactory.createExpression(nameSuggestions.single().first()) + val replacement = psiFactory.createExpression(nameSuggestions.asSequence().single().first()) val substringInfo = expressionToReplace.extractableSubstringInfo var result = when { expressionToReplace.isLambdaOutsideParentheses() -> { @@ -167,7 +167,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler { else { buildString { append("$varOvVal ") - append(nameSuggestions.single().first()) + append(nameSuggestions.asSequence().single().first()) if (noTypeInference) { val typeToRender = expressionType ?: resolutionFacade.moduleDescriptor.builtIns.anyType append(": ").append(IdeDescriptorRenderers.SOURCE_CODE.renderType(typeToRender)) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinInterfaceMemberDependencyGraph.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinInterfaceMemberDependencyGraph.kt index abb7a2a751e..786a4d85048 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinInterfaceMemberDependencyGraph.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinInterfaceMemberDependencyGraph.kt @@ -37,7 +37,8 @@ class KotlinInterfaceMemberDependencyGraph()) as Set @Suppress("UNCHECKED_CAST") @@ -45,7 +46,8 @@ class KotlinInterfaceMemberDependencyGraph()) as Set } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfoStorage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfoStorage.kt index 124b8d6d738..cf932b72292 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfoStorage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfoStorage.kt @@ -91,12 +91,13 @@ fun extractClassMembers( result: MutableCollection ) { declarations - .filter { - it is KtNamedDeclaration - && it !is KtConstructor<*> - && !(it is KtObjectDeclaration && it.isCompanion()) - && (filter == null || filter(it)) - } + .asSequence() + .filter { + it is KtNamedDeclaration + && it !is KtConstructor<*> + && !(it is KtObjectDeclaration && it.isCompanion()) + && (filter == null || filter(it)) + } .mapTo(result) { KotlinMemberInfo(it as KtNamedDeclaration, isCompanionMember = isCompanion) } } @@ -104,7 +105,8 @@ fun extractClassMembers( if (collectSuperTypeEntries) { aClass.superTypeListEntries - .filterIsInstance() + .asSequence() + .filterIsInstance() .mapNotNull { val typeReference = it.typeReference ?: return@mapNotNull null val type = typeReference.analyze(BodyResolveMode.PARTIAL)[BindingContext.TYPE, typeReference] @@ -121,8 +123,9 @@ fun extractClassMembers( } aClass.primaryConstructor - ?.valueParameters - ?.filter { it.hasValOrVar() } + ?.valueParameters + ?.asSequence() + ?.filter { it.hasValOrVar() } ?.mapTo(result) { KotlinMemberInfo(it) } aClass.extractFromClassBody(filter, false, result) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt index 9fb40b8f59d..a6552f83fca 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt @@ -322,7 +322,7 @@ class MoveKotlinDeclarationsProcessor( } val internalUsageScopes: List = if (descriptor.scanEntireFile) { - newDeclarations.map { it.containingKtFile }.distinct() + newDeclarations.asSequence().map { it.containingKtFile }.distinct().toList() } else { newDeclarations } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelperFactory.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelperFactory.kt index 1ca7e1ea38a..acde44bfcfb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelperFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelperFactory.kt @@ -38,8 +38,8 @@ class KotlinPullUpHelperFactory : PullUpHelperFactory { val sourceClass = sourceClass.unwrapped as? KtClassOrObject ?: return null val targetClass = targetClass.unwrapped as? PsiNamedElement ?: return null val membersToMove = membersToMove - .mapNotNull { it.toKtDeclarationWrapperAware() } - .sortedBy { it.startOffset } + .mapNotNull { it.toKtDeclarationWrapperAware() } + .sortedBy { it.startOffset } return KotlinPullUpData(sourceClass, targetClass, membersToMove) } @@ -90,7 +90,8 @@ class JavaToKotlinPullUpHelperFactory : PullUpHelperFactory { psiClass } return outerPsiClasses - .drop(1) + .asSequence() + .drop(1) .plus(dummyTargetClass) .fold(dummyFile.add(outerPsiClasses.first()), PsiElement::add) as PsiClass } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt index 71afa576cf4..04538caffc8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt @@ -69,7 +69,7 @@ fun addMemberToTarget(targetMember: KtNamedDeclaration, targetClass: KtClassOrOb return parameterList.addParameterBefore(targetMember, anchor) } - val anchor = targetClass.declarations.filterIsInstance(targetMember::class.java).lastOrNull() + val anchor = targetClass.declarations.asSequence().filterIsInstance(targetMember::class.java).lastOrNull() return when { anchor == null && targetMember is KtProperty -> targetClass.addDeclarationBefore(targetMember, null) else -> targetClass.addDeclarationAfter(targetMember, anchor) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pushDown/pushDownConflictsUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pushDown/pushDownConflictsUtils.kt index fe30218ce5d..ac592669650 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pushDown/pushDownConflictsUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pushDown/pushDownConflictsUtils.kt @@ -132,7 +132,8 @@ private fun checkMemberClashing( is KtClassOrObject -> { targetClass.declarations - .filterIsInstance() + .asSequence() + .filterIsInstance() .firstOrNull() { it.name == member.name } ?.let { val message = "${targetClassDescriptor.renderForConflicts()} " + diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt index b36a2417dae..1d3deee4e05 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt @@ -80,9 +80,11 @@ private fun KtDeclaration.processHierarchyUpward(scope: AnalysisScope, processor processor() val descriptor = unsafeResolveToDescriptor() as? CallableMemberDescriptor ?: return DescriptorUtils - .getAllOverriddenDescriptors(descriptor) - .mapNotNull { it.source.getPsi() } - .filter { scope.contains(it) } + .getAllOverriddenDescriptors(descriptor) + .asSequence() + .mapNotNull { it.source.getPsi() } + .filter { scope.contains(it) } + .toList() .forEach(processor) } diff --git a/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt b/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt index c4f6d0c7c71..aa2816b82a6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt @@ -169,8 +169,9 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention() + .declarations + .asSequence() + .filterIsInstance() .mapTo(HashSet()) { it.name } generatedClass .methods diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt index d90afc97f20..eca27f81d93 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt @@ -221,17 +221,18 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper( val imports = file.importDirectives val scopeToImport = getMemberScope(parentFqName, moduleDescriptor) ?: return ImportDescriptorResult.FAIL val importedScopes = imports - .filter { it.isAllUnder } - .mapNotNull { - val importPath = it.importPath - if (importPath != null) { - val fqName = importPath.fqName - getMemberScope(fqName, moduleDescriptor) - } - else { - null - } + .asSequence() + .filter { it.isAllUnder } + .mapNotNull { + val importPath = it.importPath + if (importPath != null) { + val fqName = importPath.fqName + getMemberScope(fqName, moduleDescriptor) + } else { + null } + } + .toList() val filePackage = moduleDescriptor.getPackage(file.packageFqName)