Apply "call chain -> sequence" to idea module

This commit is contained in:
Mikhail Glukhikh
2018-08-08 11:59:36 +03:00
parent 7f49b78e5f
commit c3b2d1829f
62 changed files with 223 additions and 170 deletions
@@ -83,7 +83,7 @@ internal fun createSingleImportActionForConstructor(
.filterIsInstance<ClassDescriptor>()
.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<DeclarationDescriptor>) : Comparable<Priority> {
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)
@@ -87,10 +87,12 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
private fun choosePropertiesToInitialize(klass: KtClassOrObject, context: BindingContext): List<DescriptorMemberChooserObject> {
val candidates = klass.declarations
.filterIsInstance<KtProperty>()
.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<KtProperty>()
.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)) {
@@ -49,7 +49,7 @@ tailrec fun ClassDescriptor.findDeclaredFunction(
fun getPropertiesToUseInGeneratedMember(classOrObject: KtClassOrObject): List<KtNamedDeclaration> {
return ArrayList<KtNamedDeclaration>().apply {
classOrObject.primaryConstructorParameters.filterTo(this) { it.hasValOrVar() }
classOrObject.declarations.filterIsInstance<KtProperty>().filterTo(this) {
classOrObject.declarations.asSequence().filterIsInstance<KtProperty>().filterTo(this) {
val descriptor = it.unsafeResolveToDescriptor()
when (descriptor) {
is ValueParameterDescriptor -> true
@@ -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
)
@@ -347,7 +347,7 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor<KotlinReference
= findImportableDescriptors(fqName, file).firstIsInstanceOrNull<CallableDescriptor>()
private fun showRestoreReferencesDialog(project: Project, referencesToRestore: List<ReferenceToRestoreData>): Collection<ReferenceToRestoreData> {
val fqNames = referencesToRestore.map { it.refData.fqName }.toSortedSet()
val fqNames = referencesToRestore.asSequence().map { it.refData.fqName }.toSortedSet()
if (ApplicationManager.getApplication().isUnitTestMode) {
declarationsToImportSuggested = fqNames
@@ -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 = "") {
"<li>${it.module.name} (${it.externalCompilerVersion})</li><br/>"
}
@@ -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)
@@ -52,18 +52,18 @@ class KotlinFacetCompilerPluginsTab(
val pluginInfos: List<PluginInfo> = ArrayList<PluginInfo>().apply {
parsePluginOptions(configuration)
.sortedWith(
Comparator<CliOptionValue> { 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<CliOptionValue> { 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 }
@@ -44,7 +44,7 @@ class KotlinCalleeTreeStructure(
is KtClassOrObject -> {
superTypeListEntries.filterIsInstance<KtCallElement>() +
getAnonymousInitializers().map { it.body } +
declarations.filterIsInstance<KtProperty>().map { it.initializer }
declarations.asSequence().filterIsInstance<KtProperty>().map { it.initializer }.toList()
}
else -> emptyList()
}.filterNotNull()
@@ -103,7 +103,8 @@ class CanBeValInspection : AbstractKotlinInspection() {
private fun Pseudocode.collectWriteInstructions(descriptor: DeclarationDescriptor): Set<WriteValueInstruction> =
with (instructionsIncludingDeadCode) {
filterIsInstance<WriteValueInstruction>()
.filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor }
.asSequence()
.filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor }
.toSet() +
filterIsInstance<LocalFunctionDeclarationInstruction>()
@@ -74,9 +74,9 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() {
}
private fun List<KtLightClassImpl>.withEmptyConstructors(): List<KtClass> {
return map { it.kotlinOrigin }.filterIsInstance<KtClass>()
return map { it.kotlinOrigin }.asSequence().filterIsInstance<KtClass>()
.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<KtClass>.thatHasNoCompanionObjects(): List<KtClass> {
@@ -112,7 +112,7 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() {
val body = getBody()
return body == null || run {
val declarations = body.declarations
declarations.filterIsInstance<KtProperty>().none { property ->
declarations.asSequence().filterIsInstance<KtProperty>().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<KtNamedFunction>().none { function ->
} && declarations.asSequence().filterIsInstance<KtNamedFunction>().none { function ->
val name = function.name
val valueParameters = function.valueParameters
val noTypeParameters = function.typeParameters.isEmpty()
@@ -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(
@@ -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)) }
@@ -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
@@ -133,7 +133,7 @@ private fun KtAnnotationEntry.applicableUseSiteTargets(): List<AnnotationUseSite
if (chosenTarget.isNullOrBlank())
targets.take(1)
else
targets.filter { it.renderName == chosenTarget }.take(1)
targets.asSequence().filter { it.renderName == chosenTarget }.take(1).toList()
} else {
targets
}
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(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
@@ -47,7 +47,7 @@ class AddMissingDestructuringIntention : SelfTargetingIntention<KtDestructuringD
)
val newEntries = entries.joinToString(postfix = ", ") { it.text } +
primaryParameters.drop(entries.size).joinToString {
primaryParameters.asSequence().drop(entries.size).joinToString {
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
}
val initializer = element.initializer ?: return
@@ -33,7 +33,7 @@ class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIntention
) {
companion object {
private const val FOR_EACH_NAME = "forEach"
private val FOR_EACH_FQ_NAMES = listOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$FOR_EACH_NAME" }.toSet()
private val FOR_EACH_FQ_NAMES = sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$FOR_EACH_NAME" }.toSet()
}
override fun isApplicableTo(element: KtSimpleNameExpression): Boolean {
@@ -101,11 +101,11 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
superTypeEntry.replace(factory.createSuperTypeEntry(superTypeEntry.typeReference!!.text))
}
}
val valueParameterInitializers = element.valueParameters.filter { it.hasValOrVar() }.joinToString(separator = "\n") {
val valueParameterInitializers = element.valueParameters.asSequence().filter { it.hasValOrVar() }.joinToString(separator = "\n") {
val name = it.name!!
"this.$name = $name"
}
val classBodyInitializers = klass.declarations.filter {
val classBodyInitializers = klass.declarations.asSequence().filter {
(it is KtProperty && initializerMap[it] != null) || it is KtAnonymousInitializer
}.joinToString(separator = "\n") {
if (it is KtProperty) {
@@ -140,8 +140,9 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(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)
@@ -79,7 +79,7 @@ class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(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)
@@ -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
@@ -31,7 +31,7 @@ class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtLam
override fun applyTo(element: KtLambdaExpression, editor: Editor?) {
val oldParameterList = element.functionLiteral.valueParameterList!!
val parameterString = oldParameterList.parameters.map {
val parameterString = oldParameterList.parameters.asSequence().map {
it.destructuringDeclaration?.text ?: it.name
}.joinToString(", ")
val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString)
@@ -38,7 +38,7 @@ class RemoveForLoopIndicesInspection : IntentionBasedInspection<KtForExpression>
class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(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
@@ -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
@@ -31,8 +31,9 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
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 {
@@ -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
@@ -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 {
@@ -40,7 +40,8 @@ class AddDefaultConstructorFix(expectClass: KtClass) : KotlinQuickFixAction<KtCl
if (argumentList.arguments.isNotEmpty()) return null
val derivedClass = argumentList.getStrictParentOfType<KtClassOrObject>() ?: return null
val context = derivedClass.analyze()
val baseTypeCallEntry = derivedClass.superTypeListEntries.filterIsInstance<KtSuperTypeCallEntry>().firstOrNull() ?: return null
val baseTypeCallEntry = derivedClass.superTypeListEntries.asSequence().filterIsInstance<KtSuperTypeCallEntry>().firstOrNull()
?: return null
val baseClass = superTypeEntryToClass(baseTypeCallEntry, context) ?: return null
return AddDefaultConstructorFix(baseClass)
}
@@ -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<KotlinType>.sortSubtypesFirst(): List<KotlinType> {
@@ -74,6 +74,7 @@ class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction<KtV
val argumentType = element!!.getArgumentExpression()?.let { context.getType(it) }
val usedParameters = resolvedCall.call.valueArguments
.asSequence()
.map { resolvedCall.getArgumentMapping(it) }
.filterIsInstance<ArgumentMatch>()
.filter { argumentMatch -> argumentType == null || argumentType.isError || !argumentMatch.isError() }
@@ -81,8 +82,10 @@ class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction<KtV
.toSet()
return resolvedCall.resultingDescriptor.valueParameters
.asSequence()
.filter { it !in usedParameters }
.map { it.name }
.toList()
}
private fun addName(project: Project, argument: KtValueArgument, name: Name) {
@@ -105,10 +105,12 @@ class ChangeMemberFunctionSignatureFix private constructor(
val superFunctions = getPossibleSuperFunctionsDescriptors(functionDescriptor)
return superFunctions
.asSequence()
.filter { it.kind.isReal }
.map { signatureToMatch(functionDescriptor, it) }
.distinctBy { it.sourceCode }
.sortedBy { it.preview }
.toList()
}
/**
@@ -207,13 +209,13 @@ class ChangeMemberFunctionSignatureFix private constructor(
SourceElement.NO_SOURCE
)
val parameters = newParameters.withIndex().map { (index, parameter) ->
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(
@@ -145,10 +145,12 @@ internal abstract class ImportFixBase<T : KtExpression> 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<DeclarationDescriptor> {
@@ -68,7 +68,8 @@ class KotlinReferenceImporter : ReferenceImporter {
): ImportFixBase<out KtExpression>? {
var importFix: ImportFixBase<out KtExpression>? = null
DaemonCodeAnalyzerEx.processHighlights(editor.document, file.project, null, offset, offset) { info ->
importFix = info.quickFixActionRanges?.map { it.first.action }?.filterIsInstance<ImportFixBase<*>>()?.firstOrNull()
importFix = info.quickFixActionRanges?.asSequence()
?.map { it.first.action }?.filterIsInstance<ImportFixBase<*>>()?.firstOrNull()
importFix == null
}
return importFix
@@ -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<List<KotlinType>> = 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))
@@ -333,7 +333,7 @@ private fun TypePredicate.getRepresentativeTypes(): Set<KotlinType> {
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<KotlinType>()) { it.getRepresentativeTypes() }
is AllTypes -> emptySet()
@@ -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()
}
}
@@ -64,11 +64,13 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration)
}
private fun fixNativeClass(containingClass: KtClassOrObject) {
val membersToFix = containingClass.declarations.filterIsInstance<KtCallableDeclaration>().filter { isMemberDeclaration(it) && !isMemberExtensionDeclaration(it) }. map {
it to fetchJsNativeAnnotations(it)
}.filter {
it.second.annotations.isNotEmpty()
}
val membersToFix =
containingClass.declarations.asSequence().filterIsInstance<KtCallableDeclaration>()
.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) {
@@ -169,10 +169,12 @@ object ReplaceWithAnnotationAnalyzer {
private fun importFqNames(annotation: ReplaceWith): List<FqName> {
return annotation.imports
.asSequence()
.filter { FqNameUnsafe.isValid(it) }
.map(::FqNameUnsafe)
.filter(FqNameUnsafe::isSafe)
.map(FqNameUnsafe::toSafe)
.toList()
}
private fun getResolutionScope(
@@ -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<KotlinParameterInfo> = newParameters.toTypedArray()
@@ -334,7 +334,7 @@ open class KotlinChangeInfo(
val mandatoryParams = parameters.toMutableList()
val defaultValues = ArrayList<KtExpression>()
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
@@ -136,7 +136,7 @@ class KotlinChangeSignatureDialog(
}
private fun getColumnTextMaxLength(nameFunction: Function1<ParameterTableModelItemBase<KotlinParameterInfo>, 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) }
@@ -35,8 +35,10 @@ class KotlinCallerUsage(element: KtNamedDeclaration): KotlinUsageInfo<KtNamedDec
else -> 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()
@@ -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 {
@@ -65,7 +65,7 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor<MoveDeclaratio
val declarations = rangeToDeclarations(file, startOffsets[0], endOffsets[0])
if (declarations.isEmpty()) return emptyList()
val parent = declarations.map { it.parent }.distinct().singleOrNull() ?: return emptyList()
val parent = declarations.asSequence().map { it.parent }.distinct().singleOrNull() ?: return emptyList()
val sourceObjectFqName = when (parent) {
is KtFile -> null
is KtClassBody -> (parent.parent as? KtObjectDeclaration)?.fqName?.asString() ?: return emptyList()
@@ -73,7 +73,7 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor<MoveDeclaratio
}
if (declarations.any { it.name == null }) return emptyList()
val declarationNames = declarations.map { it.name!! }.toSet()
val declarationNames = declarations.asSequence().map { it.name!! }.toSet()
val stubTexts = declarations.map { MoveDeclarationsTransferableData.STUB_RENDERER.render(it.unsafeResolveToDescriptor()) }
return listOf(MoveDeclarationsTransferableData(file.virtualFile.url, sourceObjectFqName, stubTexts, declarationNames))
@@ -242,7 +242,7 @@ fun KtElement.renderTrimmed(): String {
it.accept(this)
}
function.name?.let { builder.append(" $it") }
function.valueParameters.mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
function.valueParameters.asSequence().mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
function.equalsToken?.let { builder.append(" = ") }
function.bodyExpression?.accept(this)
}
@@ -255,12 +255,12 @@ fun KtElement.renderTrimmed(): String {
}
override fun visitPrimaryConstructor(constructor: KtPrimaryConstructor) {
constructor.valueParameters.mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
constructor.valueParameters.asSequence().mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
}
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor) {
builder.append("constructor")
constructor.valueParameters.mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
constructor.valueParameters.asSequence().mapNotNull { it.typeReference }.joinTo(builder, prefix = "(", postfix = ")")
constructor.bodyExpression?.accept(this)
}
@@ -106,13 +106,14 @@ class KotlinInlineTypeAliasHandler : InlineActionHandler() {
val context = usage.analyze(BodyResolveMode.PARTIAL)
val argumentTypes = usage
.typeArguments
.filterNotNull()
.mapNotNull {
val type = context[BindingContext.ABBREVIATED_TYPE, it.typeReference] ?:
context[BindingContext.TYPE, it.typeReference]
if (type != null) TypeProjectionImpl(type) else null
}
.typeArguments
.asSequence()
.filterNotNull()
.mapNotNull {
val type = context[BindingContext.ABBREVIATED_TYPE, it.typeReference] ?: context[BindingContext.TYPE, it.typeReference]
if (type != null) TypeProjectionImpl(type) else null
}
.toList()
if (argumentTypes.size != typeConstructorsToInline.size) return null
val substitution = (typeConstructorsToInline zip argumentTypes).toMap()
val substitutor = TypeSubstitutor.create(substitution)
@@ -155,7 +155,7 @@ class ExtractSuperRefactoring(
elementsToMove,
moveTarget,
originalClass,
memberInfos.filter { it.isToAbstract }.mapNotNull { it.member }
memberInfos.asSequence().filter { it.isToAbstract }.mapNotNull { it.member }.toList()
)
project.runSynchronouslyWithProgress(RefactoringBundle.message("detecting.possible.conflicts"), true) {
@@ -307,7 +307,7 @@ private fun ExtractionData.analyzeControlFlow(
}
val outParameters =
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortedBy { it.nameForRef }
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortedBy { it.nameForRef }
val outDeclarations =
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null }
val modifiedValueCount = outParameters.size + outDeclarations.size
@@ -360,7 +360,7 @@ private fun makeCall(
return when (outputValue) {
is OutputValue.ExpressionValue -> {
val exprText = if (outputValue.callSiteReturn) {
val firstReturn = outputValue.originalExpressions.filterIsInstance<KtReturnExpression>().firstOrNull()
val firstReturn = outputValue.originalExpressions.asSequence().filterIsInstance<KtReturnExpression>().firstOrNull()
val label = firstReturn?.getTargetLabel()?.text ?: ""
"return$label $callText"
}
@@ -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}"
@@ -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(
@@ -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)
@@ -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))
@@ -37,7 +37,8 @@ class KotlinInterfaceMemberDependencyGraph<T : KtNamedDeclaration, M : MemberInf
@Suppress("UNCHECKED_CAST")
override fun getDependent() = delegateGraph.dependent
.mapNotNull { it.unwrapped }
.asSequence()
.mapNotNull { it.unwrapped }
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
@Suppress("UNCHECKED_CAST")
@@ -45,7 +46,8 @@ class KotlinInterfaceMemberDependencyGraph<T : KtNamedDeclaration, M : MemberInf
val psiMember = lightElementForMemberInfo(member) ?: return emptySet()
val psiMemberDependencies = delegateGraph.getDependenciesOf(psiMember) ?: return emptySet()
return psiMemberDependencies
.mapNotNull { it.unwrapped }
.asSequence()
.mapNotNull { it.unwrapped }
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
}
}
@@ -91,12 +91,13 @@ fun extractClassMembers(
result: MutableCollection<KotlinMemberInfo>
) {
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<KtSuperTypeEntry>()
.asSequence()
.filterIsInstance<KtSuperTypeEntry>()
.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)
@@ -322,7 +322,7 @@ class MoveKotlinDeclarationsProcessor(
}
val internalUsageScopes: List<KtElement> = if (descriptor.scanEntireFile) {
newDeclarations.map { it.containingKtFile }.distinct()
newDeclarations.asSequence().map { it.containingKtFile }.distinct().toList()
} else {
newDeclarations
}
@@ -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
}
@@ -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)
@@ -132,7 +132,8 @@ private fun checkMemberClashing(
is KtClassOrObject -> {
targetClass.declarations
.filterIsInstance<KtClassOrObject>()
.asSequence()
.filterIsInstance<KtClassOrObject>()
.firstOrNull() { it.name == member.name }
?.let {
val message = "${targetClassDescriptor.renderForConflicts()} " +
@@ -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)
}
@@ -169,8 +169,9 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention<KtNamedDeclaration
if (existingClass != null) {
runWriteAction {
val existingMethodNames = existingClass
.declarations
.filterIsInstance<KtNamedFunction>()
.declarations
.asSequence()
.filterIsInstance<KtNamedFunction>()
.mapTo(HashSet()) { it.name }
generatedClass
.methods
@@ -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)