Apply "call chain -> sequence" to idea module
This commit is contained in:
@@ -83,7 +83,7 @@ internal fun createSingleImportActionForConstructor(
|
|||||||
.filterIsInstance<ClassDescriptor>()
|
.filterIsInstance<ClassDescriptor>()
|
||||||
.flatMap { it.constructors }
|
.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)
|
Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority)
|
||||||
}.sortedBy { it.priority }.map { it.variant }
|
}.sortedBy { it.priority }.map { it.variant }
|
||||||
return KotlinAddImportAction(project, editor, element, variants)
|
return KotlinAddImportAction(project, editor, element, variants)
|
||||||
@@ -260,7 +260,7 @@ private class DescriptorGroupPrioritizer(file: KtFile) {
|
|||||||
private val prioritizer = Prioritizer(file, false)
|
private val prioritizer = Prioritizer(file, false)
|
||||||
|
|
||||||
inner class Priority(val descriptors: List<DeclarationDescriptor>) : Comparable<Priority> {
|
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 {
|
override fun compareTo(other: Priority): Int {
|
||||||
val c1 = ownDescriptorsPriority.compareTo(other.ownDescriptorsPriority)
|
val c1 = ownDescriptorsPriority.compareTo(other.ownDescriptorsPriority)
|
||||||
|
|||||||
+6
-4
@@ -87,10 +87,12 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
|
|||||||
|
|
||||||
private fun choosePropertiesToInitialize(klass: KtClassOrObject, context: BindingContext): List<DescriptorMemberChooserObject> {
|
private fun choosePropertiesToInitialize(klass: KtClassOrObject, context: BindingContext): List<DescriptorMemberChooserObject> {
|
||||||
val candidates = klass.declarations
|
val candidates = klass.declarations
|
||||||
.filterIsInstance<KtProperty>()
|
.asSequence()
|
||||||
.filter { it.isVar || context.diagnostics.forElement(it).any { it.factory in Errors.MUST_BE_INITIALIZED_DIAGNOSTICS } }
|
.filterIsInstance<KtProperty>()
|
||||||
.map { context.get(BindingContext.VARIABLE, it) as PropertyDescriptor }
|
.filter { it.isVar || context.diagnostics.forElement(it).any { it.factory in Errors.MUST_BE_INITIALIZED_DIAGNOSTICS } }
|
||||||
.map { DescriptorMemberChooserObject(it.source.getPsi()!!, it) }
|
.map { context.get(BindingContext.VARIABLE, it) as PropertyDescriptor }
|
||||||
|
.map { DescriptorMemberChooserObject(it.source.getPsi()!!, it) }
|
||||||
|
.toList()
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode || candidates.isEmpty()) return candidates
|
if (ApplicationManager.getApplication().isUnitTestMode || candidates.isEmpty()) return candidates
|
||||||
|
|
||||||
return with(MemberChooser(candidates.toTypedArray(), true, true, klass.project, false, null)) {
|
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> {
|
fun getPropertiesToUseInGeneratedMember(classOrObject: KtClassOrObject): List<KtNamedDeclaration> {
|
||||||
return ArrayList<KtNamedDeclaration>().apply {
|
return ArrayList<KtNamedDeclaration>().apply {
|
||||||
classOrObject.primaryConstructorParameters.filterTo(this) { it.hasValOrVar() }
|
classOrObject.primaryConstructorParameters.filterTo(this) { it.hasValOrVar() }
|
||||||
classOrObject.declarations.filterIsInstance<KtProperty>().filterTo(this) {
|
classOrObject.declarations.asSequence().filterIsInstance<KtProperty>().filterTo(this) {
|
||||||
val descriptor = it.unsafeResolveToDescriptor()
|
val descriptor = it.unsafeResolveToDescriptor()
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is ValueParameterDescriptor -> true
|
is ValueParameterDescriptor -> true
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ internal class MutableCodeToInline(
|
|||||||
internal fun CodeToInline.toMutable(): MutableCodeToInline {
|
internal fun CodeToInline.toMutable(): MutableCodeToInline {
|
||||||
return MutableCodeToInline(
|
return MutableCodeToInline(
|
||||||
mainExpression?.copied(),
|
mainExpression?.copied(),
|
||||||
statementsBefore.map { it.copied() }.toMutableList(),
|
statementsBefore.asSequence().map { it.copied() }.toMutableList(),
|
||||||
fqNamesToImport.toMutableSet(),
|
fqNamesToImport.toMutableSet(),
|
||||||
alwaysKeepMainExpression
|
alwaysKeepMainExpression
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor<KotlinReference
|
|||||||
= findImportableDescriptors(fqName, file).firstIsInstanceOrNull<CallableDescriptor>()
|
= findImportableDescriptors(fqName, file).firstIsInstanceOrNull<CallableDescriptor>()
|
||||||
|
|
||||||
private fun showRestoreReferencesDialog(project: Project, referencesToRestore: List<ReferenceToRestoreData>): Collection<ReferenceToRestoreData> {
|
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) {
|
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
declarationsToImportSuggested = fqNames
|
declarationsToImportSuggested = fqNames
|
||||||
|
|||||||
+1
-1
@@ -115,7 +115,7 @@ fun createOutdatedBundledCompilerMessage(project: Project, bundledCompilerVersio
|
|||||||
}
|
}
|
||||||
|
|
||||||
var modulesStr =
|
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/>"
|
"<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() +
|
val members = (shortNameCache.getMethodsByName(referenceName, scope).asList() +
|
||||||
shortNameCache.getFieldsByName(referenceName, scope).asList())
|
shortNameCache.getFieldsByName(referenceName, scope).asList())
|
||||||
.map { it as PsiMember }
|
.asSequence()
|
||||||
.filter { it.getNullableModuleInfo() != null }
|
.map { it as PsiMember }
|
||||||
.map { it to it.getJavaMemberDescriptor(resolutionFacade) as? DeclarationDescriptorWithVisibility }
|
.filter { it.getNullableModuleInfo() != null }
|
||||||
.filter { canBeImported(it.second) }
|
.map { it to it.getJavaMemberDescriptor(resolutionFacade) as? DeclarationDescriptorWithVisibility }
|
||||||
|
.filter { canBeImported(it.second) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
members.singleOrNull()?.let { (psiMember, _) ->
|
members.singleOrNull()?.let { (psiMember, _) ->
|
||||||
addImport(psiElementFactory.createImportStaticStatement(psiMember.containingClass!!, psiMember.name!!), true)
|
addImport(psiElementFactory.createImportStaticStatement(psiMember.containingClass!!, psiMember.name!!), true)
|
||||||
|
|||||||
@@ -52,18 +52,18 @@ class KotlinFacetCompilerPluginsTab(
|
|||||||
|
|
||||||
val pluginInfos: List<PluginInfo> = ArrayList<PluginInfo>().apply {
|
val pluginInfos: List<PluginInfo> = ArrayList<PluginInfo>().apply {
|
||||||
parsePluginOptions(configuration)
|
parsePluginOptions(configuration)
|
||||||
.sortedWith(
|
.sortedWith(
|
||||||
Comparator<CliOptionValue> { o1, o2 ->
|
Comparator<CliOptionValue> { o1, o2 ->
|
||||||
var result = o1.pluginId.compareTo(o2.pluginId)
|
var result = o1.pluginId.compareTo(o2.pluginId)
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = o1.optionName.compareTo(o2.optionName)
|
result = o1.optionName.compareTo(o2.optionName)
|
||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = o1.value.compareTo(o2.value)
|
result = o1.value.compareTo(o2.value)
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.groupBy({ it.pluginId })
|
.groupBy({ it.pluginId })
|
||||||
.mapTo(this) { PluginInfo(it.key, it.value.map { "${it.optionName}=${it.value}" }) }
|
.mapTo(this) { PluginInfo(it.key, it.value.map { "${it.optionName}=${it.value}" }) }
|
||||||
sortBy { it.id }
|
sortBy { it.id }
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class KotlinCalleeTreeStructure(
|
|||||||
is KtClassOrObject -> {
|
is KtClassOrObject -> {
|
||||||
superTypeListEntries.filterIsInstance<KtCallElement>() +
|
superTypeListEntries.filterIsInstance<KtCallElement>() +
|
||||||
getAnonymousInitializers().map { it.body } +
|
getAnonymousInitializers().map { it.body } +
|
||||||
declarations.filterIsInstance<KtProperty>().map { it.initializer }
|
declarations.asSequence().filterIsInstance<KtProperty>().map { it.initializer }.toList()
|
||||||
}
|
}
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ class CanBeValInspection : AbstractKotlinInspection() {
|
|||||||
private fun Pseudocode.collectWriteInstructions(descriptor: DeclarationDescriptor): Set<WriteValueInstruction> =
|
private fun Pseudocode.collectWriteInstructions(descriptor: DeclarationDescriptor): Set<WriteValueInstruction> =
|
||||||
with (instructionsIncludingDeadCode) {
|
with (instructionsIncludingDeadCode) {
|
||||||
filterIsInstance<WriteValueInstruction>()
|
filterIsInstance<WriteValueInstruction>()
|
||||||
.filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor }
|
.asSequence()
|
||||||
|
.filter { (it.target as? AccessTarget.Call)?.resolvedCall?.resultingDescriptor == descriptor }
|
||||||
.toSet() +
|
.toSet() +
|
||||||
|
|
||||||
filterIsInstance<LocalFunctionDeclarationInstruction>()
|
filterIsInstance<LocalFunctionDeclarationInstruction>()
|
||||||
|
|||||||
+4
-4
@@ -74,9 +74,9 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun List<KtLightClassImpl>.withEmptyConstructors(): List<KtClass> {
|
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 { 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> {
|
private fun List<KtClass>.thatHasNoCompanionObjects(): List<KtClass> {
|
||||||
@@ -112,7 +112,7 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() {
|
|||||||
val body = getBody()
|
val body = getBody()
|
||||||
return body == null || run {
|
return body == null || run {
|
||||||
val declarations = body.declarations
|
val declarations = body.declarations
|
||||||
declarations.filterIsInstance<KtProperty>().none { property ->
|
declarations.asSequence().filterIsInstance<KtProperty>().none { property ->
|
||||||
// Simplified "backing field required"
|
// Simplified "backing field required"
|
||||||
when {
|
when {
|
||||||
property.isAbstract() -> false
|
property.isAbstract() -> false
|
||||||
@@ -121,7 +121,7 @@ class CanSealedSubClassBeObjectInspection : AbstractKotlinInspection() {
|
|||||||
!property.isVar -> property.getter == null
|
!property.isVar -> property.getter == null
|
||||||
else -> property.getter == null || property.setter == null
|
else -> property.getter == null || property.setter == null
|
||||||
}
|
}
|
||||||
} && declarations.filterIsInstance<KtNamedFunction>().none { function ->
|
} && declarations.asSequence().filterIsInstance<KtNamedFunction>().none { function ->
|
||||||
val name = function.name
|
val name = function.name
|
||||||
val valueParameters = function.valueParameters
|
val valueParameters = function.valueParameters
|
||||||
val noTypeParameters = function.typeParameters.isEmpty()
|
val noTypeParameters = function.typeParameters.isEmpty()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class ReformatInspection : LocalInspectionTool() {
|
|||||||
val changes = collectFormattingChanges(file)
|
val changes = collectFormattingChanges(file)
|
||||||
if (changes.isEmpty()) return null
|
if (changes.isEmpty()) return null
|
||||||
|
|
||||||
val elements = changes.map {
|
val elements = changes.asSequence().map {
|
||||||
val rangeOffset = when (it) {
|
val rangeOffset = when (it) {
|
||||||
is ShiftIndentInsideRange -> it.range.startOffset
|
is ShiftIndentInsideRange -> it.range.startOffset
|
||||||
is ReplaceWhiteSpace -> it.textRange.startOffset
|
is ReplaceWhiteSpace -> it.textRange.startOffset
|
||||||
@@ -62,7 +62,7 @@ class ReformatInspection : LocalInspectionTool() {
|
|||||||
if (leaf is PsiWhiteSpace && isEmptyLineReformat(leaf, it)) return@map null
|
if (leaf is PsiWhiteSpace && isEmptyLineReformat(leaf, it)) return@map null
|
||||||
|
|
||||||
leaf
|
leaf
|
||||||
}.filterNotNull()
|
}.filterNotNull().toList()
|
||||||
|
|
||||||
return elements.map {
|
return elements.map {
|
||||||
ProblemDescriptorImpl(
|
ProblemDescriptorImpl(
|
||||||
|
|||||||
+2
-2
@@ -49,7 +49,7 @@ class ReplaceStringFormatWithLiteralInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val context = callExpression.analyze(BodyResolveMode.PARTIAL)
|
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(
|
holder.registerProblem(
|
||||||
qualifiedExpression ?: callExpression,
|
qualifiedExpression ?: callExpression,
|
||||||
@@ -75,7 +75,7 @@ class ReplaceStringFormatWithLiteralInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
val args = callExpression.valueArguments.mapNotNull { it.getArgumentExpression() }
|
val args = callExpression.valueArguments.mapNotNull { it.getArgumentExpression() }
|
||||||
val format = args[0].text.removePrefix("\"").removeSuffix("\"")
|
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() }
|
val stringLiteral = stringPlaceHolder.replace(format) { replaceArgs.pop() }
|
||||||
|
|
||||||
(qualifiedExpression ?: callExpression).also { it.replace(KtPsiFactory(it).createStringTemplate(stringLiteral)) }
|
(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
|
if (modifiers.isEmpty()) return
|
||||||
|
|
||||||
val startElement = modifierElements.firstOrNull { it.node.elementType is KtModifierKeywordToken } ?: return
|
val startElement = modifierElements.firstOrNull { it.node.elementType is KtModifierKeywordToken } ?: return
|
||||||
|
|||||||
+1
-1
@@ -133,7 +133,7 @@ private fun KtAnnotationEntry.applicableUseSiteTargets(): List<AnnotationUseSite
|
|||||||
if (chosenTarget.isNullOrBlank())
|
if (chosenTarget.isNullOrBlank())
|
||||||
targets.take(1)
|
targets.take(1)
|
||||||
else
|
else
|
||||||
targets.filter { it.renderName == chosenTarget }.take(1)
|
targets.asSequence().filter { it.renderName == chosenTarget }.take(1).toList()
|
||||||
} else {
|
} else {
|
||||||
targets
|
targets
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Add indices to 'for' loop"),
|
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Add indices to 'for' loop"),
|
||||||
LowPriorityAction {
|
LowPriorityAction {
|
||||||
private val WITH_INDEX_NAME = "withIndex"
|
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? {
|
override fun applicabilityRange(element: KtForExpression): TextRange? {
|
||||||
if (element.loopParameter == null) return null
|
if (element.loopParameter == null) return null
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class AddMissingDestructuringIntention : SelfTargetingIntention<KtDestructuringD
|
|||||||
)
|
)
|
||||||
|
|
||||||
val newEntries = entries.joinToString(postfix = ", ") { it.text } +
|
val newEntries = entries.joinToString(postfix = ", ") { it.text } +
|
||||||
primaryParameters.drop(entries.size).joinToString {
|
primaryParameters.asSequence().drop(entries.size).joinToString {
|
||||||
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
|
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
|
||||||
}
|
}
|
||||||
val initializer = element.initializer ?: return
|
val initializer = element.initializer ?: return
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIntention
|
|||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val FOR_EACH_NAME = "forEach"
|
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 {
|
override fun isApplicableTo(element: KtSimpleNameExpression): Boolean {
|
||||||
|
|||||||
+2
-2
@@ -101,11 +101,11 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
superTypeEntry.replace(factory.createSuperTypeEntry(superTypeEntry.typeReference!!.text))
|
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!!
|
val name = it.name!!
|
||||||
"this.$name = $name"
|
"this.$name = $name"
|
||||||
}
|
}
|
||||||
val classBodyInitializers = klass.declarations.filter {
|
val classBodyInitializers = klass.declarations.asSequence().filter {
|
||||||
(it is KtProperty && initializerMap[it] != null) || it is KtAnonymousInitializer
|
(it is KtProperty && initializerMap[it] != null) || it is KtAnonymousInitializer
|
||||||
}.joinToString(separator = "\n") {
|
}.joinToString(separator = "\n") {
|
||||||
if (it is KtProperty) {
|
if (it is KtProperty) {
|
||||||
|
|||||||
@@ -140,8 +140,9 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
|
|||||||
|
|
||||||
if (entriesToAdd.isNotEmpty()) {
|
if (entriesToAdd.isNotEmpty()) {
|
||||||
val firstEntry = entriesToAdd
|
val firstEntry = entriesToAdd
|
||||||
.reversed()
|
.reversed()
|
||||||
.map { klass.addDeclarationBefore(it, null) }
|
.asSequence()
|
||||||
|
.map { klass.addDeclarationBefore(it, null) }
|
||||||
.last()
|
.last()
|
||||||
// TODO: Add formatter rule
|
// TODO: Add formatter rule
|
||||||
firstEntry.parent.addBefore(psiFactory.createNewLine(), firstEntry)
|
firstEntry.parent.addBefore(psiFactory.createNewLine(), firstEntry)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(KtExpres
|
|||||||
listOf(KotlinNameSuggester.suggestIterationVariableNames(element, elementType, bindingContext, nameValidator, "e"))
|
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" }))
|
?: psiFactory.createDestructuringParameter(names.indices.joinToString(prefix = "(", postfix = ")") { "p$it" }))
|
||||||
var forExpression = psiFactory.createExpressionByPattern("for($0 in $1) {\nx\n}", paramPattern, element) as KtForExpression
|
var forExpression = psiFactory.createExpressionByPattern("for($0 in $1) {\nx\n}", paramPattern, element) as KtForExpression
|
||||||
forExpression = element.replaced(forExpression)
|
forExpression = element.replaced(forExpression)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class RemoveArgumentNameIntention
|
|||||||
|
|
||||||
val argumentList = element.parent as? KtValueArgumentList ?: return null
|
val argumentList = element.parent as? KtValueArgumentList ?: return null
|
||||||
val arguments = argumentList.arguments
|
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 callExpr = argumentList.parent as? KtCallElement ?: return null
|
||||||
val resolvedCall = callExpr.resolveToCall() ?: return null
|
val resolvedCall = callExpr.resolveToCall() ?: return null
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtLam
|
|||||||
override fun applyTo(element: KtLambdaExpression, editor: Editor?) {
|
override fun applyTo(element: KtLambdaExpression, editor: Editor?) {
|
||||||
val oldParameterList = element.functionLiteral.valueParameterList!!
|
val oldParameterList = element.functionLiteral.valueParameterList!!
|
||||||
|
|
||||||
val parameterString = oldParameterList.parameters.map {
|
val parameterString = oldParameterList.parameters.asSequence().map {
|
||||||
it.destructuringDeclaration?.text ?: it.name
|
it.destructuringDeclaration?.text ?: it.name
|
||||||
}.joinToString(", ")
|
}.joinToString(", ")
|
||||||
val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString)
|
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") {
|
class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Remove indices in 'for' loop") {
|
||||||
private val WITH_INDEX_NAME = "withIndex"
|
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? {
|
override fun applicabilityRange(element: KtForExpression): TextRange? {
|
||||||
val loopRange = element.loopRange as? KtDotQualifiedExpression ?: return null
|
val loopRange = element.loopRange as? KtDotQualifiedExpression ?: return null
|
||||||
|
|||||||
+1
@@ -48,6 +48,7 @@ class SpecifyExplicitLambdaSignatureIntention : SelfTargetingOffsetIndependentIn
|
|||||||
val functionDescriptor = element.analyze(BodyResolveMode.PARTIAL)[BindingContext.FUNCTION, functionLiteral]!!
|
val functionDescriptor = element.analyze(BodyResolveMode.PARTIAL)[BindingContext.FUNCTION, functionLiteral]!!
|
||||||
|
|
||||||
val parameterString = functionDescriptor.valueParameters
|
val parameterString = functionDescriptor.valueParameters
|
||||||
|
.asSequence()
|
||||||
.mapIndexed { index, parameterDescriptor ->
|
.mapIndexed { index, parameterDescriptor ->
|
||||||
parameterDescriptor.render(psiName = functionLiteral.valueParameters.getOrNull(index)?.let {
|
parameterDescriptor.render(psiName = functionLiteral.valueParameters.getOrNull(index)?.let {
|
||||||
it.name ?: it.destructuringDeclaration?.text
|
it.name ?: it.destructuringDeclaration?.text
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
|
|||||||
companion object {
|
companion object {
|
||||||
private val SUPPORTED_OPERATIONS = setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ)
|
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() +
|
private val SUPPORTED_OPERATION_NAMES =
|
||||||
setOf("xor", "or", "and", "equals")
|
SUPPORTED_OPERATIONS.asSequence().mapNotNull { OperatorConventions.BINARY_OPERATION_NAMES[it]?.asString() }.toSet() +
|
||||||
|
setOf("xor", "or", "and", "equals")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||||
|
|||||||
+1
-1
@@ -174,7 +174,7 @@ class KotlinInlayParameterHintsProvider : InlayParameterHintsProvider {
|
|||||||
val resolvedCallee = resolvedCall?.candidateDescriptor
|
val resolvedCallee = resolvedCall?.candidateDescriptor
|
||||||
if (resolvedCallee is FunctionDescriptor) {
|
if (resolvedCallee is FunctionDescriptor) {
|
||||||
val paramNames =
|
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)
|
val fqName = if (resolvedCallee is ConstructorDescriptor)
|
||||||
resolvedCallee.containingDeclaration.fqNameSafe.asString()
|
resolvedCallee.containingDeclaration.fqNameSafe.asString()
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ private fun KtAnnotationEntry.getRequiredAnnotationTargets(annotationClass: KtCl
|
|||||||
}
|
}
|
||||||
}.flatten().toSet()
|
}.flatten().toSet()
|
||||||
val annotationTargetValueNames = AnnotationTarget.values().map { it.name }
|
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 {
|
private fun getActualTargetList(annotated: PsiTarget): AnnotationChecker.Companion.TargetList {
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class AddDefaultConstructorFix(expectClass: KtClass) : KotlinQuickFixAction<KtCl
|
|||||||
if (argumentList.arguments.isNotEmpty()) return null
|
if (argumentList.arguments.isNotEmpty()) return null
|
||||||
val derivedClass = argumentList.getStrictParentOfType<KtClassOrObject>() ?: return null
|
val derivedClass = argumentList.getStrictParentOfType<KtClassOrObject>() ?: return null
|
||||||
val context = derivedClass.analyze()
|
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
|
val baseClass = superTypeEntryToClass(baseTypeCallEntry, context) ?: return null
|
||||||
return AddDefaultConstructorFix(baseClass)
|
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).
|
// TODO: filter out impossible supertypes (for example when argument's type isn't visible in a superclass).
|
||||||
return getSuperClasses(containingClass)
|
return getSuperClasses(containingClass)
|
||||||
|
.asSequence()
|
||||||
.filterNot { KotlinBuiltIns.isAnyOrNullableAny(it.defaultType) }
|
.filterNot { KotlinBuiltIns.isAnyOrNullableAny(it.defaultType) }
|
||||||
.map { generateFunctionSignatureForType(functionDescriptor, it) }
|
.map { generateFunctionSignatureForType(functionDescriptor, it) }
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MutableList<KotlinType>.sortSubtypesFirst(): List<KotlinType> {
|
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 argumentType = element!!.getArgumentExpression()?.let { context.getType(it) }
|
||||||
|
|
||||||
val usedParameters = resolvedCall.call.valueArguments
|
val usedParameters = resolvedCall.call.valueArguments
|
||||||
|
.asSequence()
|
||||||
.map { resolvedCall.getArgumentMapping(it) }
|
.map { resolvedCall.getArgumentMapping(it) }
|
||||||
.filterIsInstance<ArgumentMatch>()
|
.filterIsInstance<ArgumentMatch>()
|
||||||
.filter { argumentMatch -> argumentType == null || argumentType.isError || !argumentMatch.isError() }
|
.filter { argumentMatch -> argumentType == null || argumentType.isError || !argumentMatch.isError() }
|
||||||
@@ -81,8 +82,10 @@ class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAction<KtV
|
|||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
return resolvedCall.resultingDescriptor.valueParameters
|
return resolvedCall.resultingDescriptor.valueParameters
|
||||||
|
.asSequence()
|
||||||
.filter { it !in usedParameters }
|
.filter { it !in usedParameters }
|
||||||
.map { it.name }
|
.map { it.name }
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addName(project: Project, argument: KtValueArgument, name: Name) {
|
private fun addName(project: Project, argument: KtValueArgument, name: Name) {
|
||||||
|
|||||||
@@ -105,10 +105,12 @@ class ChangeMemberFunctionSignatureFix private constructor(
|
|||||||
val superFunctions = getPossibleSuperFunctionsDescriptors(functionDescriptor)
|
val superFunctions = getPossibleSuperFunctionsDescriptors(functionDescriptor)
|
||||||
|
|
||||||
return superFunctions
|
return superFunctions
|
||||||
|
.asSequence()
|
||||||
.filter { it.kind.isReal }
|
.filter { it.kind.isReal }
|
||||||
.map { signatureToMatch(functionDescriptor, it) }
|
.map { signatureToMatch(functionDescriptor, it) }
|
||||||
.distinctBy { it.sourceCode }
|
.distinctBy { it.sourceCode }
|
||||||
.sortedBy { it.preview }
|
.sortedBy { it.preview }
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,13 +209,13 @@ class ChangeMemberFunctionSignatureFix private constructor(
|
|||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
)
|
)
|
||||||
|
|
||||||
val parameters = newParameters.withIndex().map { (index, parameter) ->
|
val parameters = newParameters.asSequence().withIndex().map { (index, parameter) ->
|
||||||
ValueParameterDescriptorImpl(
|
ValueParameterDescriptorImpl(
|
||||||
descriptor, null, index,
|
descriptor, null, index,
|
||||||
parameter.annotations, parameter.name, parameter.returnType!!, parameter.declaresDefaultValue(),
|
parameter.annotations, parameter.name, parameter.returnType!!, parameter.declaresDefaultValue(),
|
||||||
parameter.isCrossinline, parameter.isNoinline, parameter.varargElementType, SourceElement.NO_SOURCE
|
parameter.isCrossinline, parameter.isNoinline, parameter.varargElementType, SourceElement.NO_SOURCE
|
||||||
)
|
)
|
||||||
}
|
}.toList()
|
||||||
|
|
||||||
return descriptor.apply {
|
return descriptor.apply {
|
||||||
initialize(
|
initialize(
|
||||||
|
|||||||
@@ -145,10 +145,12 @@ internal abstract class ImportFixBase<T : KtExpression> protected constructor(
|
|||||||
if (importNames.isEmpty()) return emptyList()
|
if (importNames.isEmpty()) return emptyList()
|
||||||
|
|
||||||
return importNames
|
return importNames
|
||||||
.flatMap { collectSuggestionsForName(it, callTypeAndReceiver) }
|
.flatMap { collectSuggestionsForName(it, callTypeAndReceiver) }
|
||||||
.distinct()
|
.asSequence()
|
||||||
.map { it.fqNameSafe }
|
.distinct()
|
||||||
.distinct()
|
.map { it.fqNameSafe }
|
||||||
|
.distinct()
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collectSuggestionsForName(name: Name, callTypeAndReceiver: CallTypeAndReceiver<*, *>): Collection<DeclarationDescriptor> {
|
private fun collectSuggestionsForName(name: Name, callTypeAndReceiver: CallTypeAndReceiver<*, *>): Collection<DeclarationDescriptor> {
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ class KotlinReferenceImporter : ReferenceImporter {
|
|||||||
): ImportFixBase<out KtExpression>? {
|
): ImportFixBase<out KtExpression>? {
|
||||||
var importFix: ImportFixBase<out KtExpression>? = null
|
var importFix: ImportFixBase<out KtExpression>? = null
|
||||||
DaemonCodeAnalyzerEx.processHighlights(editor.document, file.project, null, offset, offset) { info ->
|
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
|
importFix == null
|
||||||
}
|
}
|
||||||
return importFix
|
return importFix
|
||||||
|
|||||||
@@ -83,8 +83,10 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
|
|||||||
val substitutor = TypeConstructorSubstitution.create(superClass.typeConstructor, superType.arguments).buildSubstitutor()
|
val substitutor = TypeConstructorSubstitution.create(superClass.typeConstructor, superType.arguments).buildSubstitutor()
|
||||||
|
|
||||||
val substitutedConstructors = constructors
|
val substitutedConstructors = constructors
|
||||||
|
.asSequence()
|
||||||
.filter { it.valueParameters.isNotEmpty() }
|
.filter { it.valueParameters.isNotEmpty() }
|
||||||
.mapNotNull { it.substitute(substitutor) }
|
.mapNotNull { it.substitute(substitutor) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
if (substitutedConstructors.isNotEmpty()) {
|
if (substitutedConstructors.isNotEmpty()) {
|
||||||
val parameterTypes: List<List<KotlinType>> = substitutedConstructors.map {
|
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
|
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) {
|
val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) {
|
||||||
maxParams
|
maxParams
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +103,9 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ((constructor, types) in substitutedConstructors.zip(parameterTypes)) {
|
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 parameterString = typesRendered.joinToString(", ", "(", if (types.size <= maxParamsToDisplay) ")" else ",...)")
|
||||||
val text = "Add constructor parameters from " + superClass.name.asString() + parameterString
|
val text = "Add constructor parameters from " + superClass.name.asString() + parameterString
|
||||||
fixes.addIfNotNull(AddParametersFix.create(delegator, classOrObjectDeclaration, constructor, text))
|
fixes.addIfNotNull(AddParametersFix.create(delegator, classOrObjectDeclaration, constructor, text))
|
||||||
|
|||||||
+1
-1
@@ -333,7 +333,7 @@ private fun TypePredicate.getRepresentativeTypes(): Set<KotlinType> {
|
|||||||
is AllSubtypes -> Collections.singleton(upperBound)
|
is AllSubtypes -> Collections.singleton(upperBound)
|
||||||
is ForAllTypes -> {
|
is ForAllTypes -> {
|
||||||
if (typeSets.isEmpty()) AllTypes.getRepresentativeTypes()
|
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 ForSomeType -> typeSets.flatMapTo(LinkedHashSet<KotlinType>()) { it.getRepresentativeTypes() }
|
||||||
is AllTypes -> emptySet()
|
is AllTypes -> emptySet()
|
||||||
|
|||||||
+9
-7
@@ -84,14 +84,16 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
|||||||
val ktUserType = originalElementPointer.element ?: return emptyList()
|
val ktUserType = originalElementPointer.element ?: return emptyList()
|
||||||
val name = ktUserType.referencedName ?: return emptyList()
|
val name = ktUserType.referencedName ?: return emptyList()
|
||||||
return getPossibleTypeParameterContainers(ktUserType)
|
return getPossibleTypeParameterContainers(ktUserType)
|
||||||
.filter { it.typeParameters.all { it.name != name } }
|
.asSequence()
|
||||||
.map {
|
.filter { it.typeParameters.all { it.name != name } }
|
||||||
QuickFixWithDelegateFactory factory@ {
|
.map {
|
||||||
val originalElement = originalElementPointer.element ?: return@factory null
|
QuickFixWithDelegateFactory factory@ {
|
||||||
val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null
|
val originalElement = originalElementPointer.element ?: return@factory null
|
||||||
CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true)
|
val data = quickFixDataFactory()?.copy(declaration = it) ?: return@factory null
|
||||||
}
|
CreateTypeParameterFromUsageFix(originalElement, data, presentTypeParameterNames = true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -64,11 +64,13 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fixNativeClass(containingClass: KtClassOrObject) {
|
private fun fixNativeClass(containingClass: KtClassOrObject) {
|
||||||
val membersToFix = containingClass.declarations.filterIsInstance<KtCallableDeclaration>().filter { isMemberDeclaration(it) && !isMemberExtensionDeclaration(it) }. map {
|
val membersToFix =
|
||||||
it to fetchJsNativeAnnotations(it)
|
containingClass.declarations.asSequence().filterIsInstance<KtCallableDeclaration>()
|
||||||
}.filter {
|
.filter { isMemberDeclaration(it) && !isMemberExtensionDeclaration(it) }. map {
|
||||||
it.second.annotations.isNotEmpty()
|
it to fetchJsNativeAnnotations(it)
|
||||||
}
|
}.filter {
|
||||||
|
it.second.annotations.isNotEmpty()
|
||||||
|
}.toList()
|
||||||
|
|
||||||
membersToFix.asReversed().forEach { (memberDeclaration, annotations) ->
|
membersToFix.asReversed().forEach { (memberDeclaration, annotations) ->
|
||||||
if (annotations.nativeAnnotation != null && !annotations.isGetter && !annotations.isSetter && !annotations.isInvoke) {
|
if (annotations.nativeAnnotation != null && !annotations.isGetter && !annotations.isSetter && !annotations.isInvoke) {
|
||||||
|
|||||||
+2
@@ -169,10 +169,12 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
|
|
||||||
private fun importFqNames(annotation: ReplaceWith): List<FqName> {
|
private fun importFqNames(annotation: ReplaceWith): List<FqName> {
|
||||||
return annotation.imports
|
return annotation.imports
|
||||||
|
.asSequence()
|
||||||
.filter { FqNameUnsafe.isValid(it) }
|
.filter { FqNameUnsafe.isValid(it) }
|
||||||
.map(::FqNameUnsafe)
|
.map(::FqNameUnsafe)
|
||||||
.filter(FqNameUnsafe::isSafe)
|
.filter(FqNameUnsafe::isSafe)
|
||||||
.map(FqNameUnsafe::toSafe)
|
.map(FqNameUnsafe::toSafe)
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getResolutionScope(
|
private fun getResolutionScope(
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ open class KotlinChangeInfo(
|
|||||||
|
|
||||||
fun hasAppendedParametersOnly(): Boolean {
|
fun hasAppendedParametersOnly(): Boolean {
|
||||||
val oldParamCount = originalBaseFunctionDescriptor.valueParameters.size
|
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()
|
override fun getNewParameters(): Array<KotlinParameterInfo> = newParameters.toTypedArray()
|
||||||
@@ -334,7 +334,7 @@ open class KotlinChangeInfo(
|
|||||||
val mandatoryParams = parameters.toMutableList()
|
val mandatoryParams = parameters.toMutableList()
|
||||||
val defaultValues = ArrayList<KtExpression>()
|
val defaultValues = ArrayList<KtExpression>()
|
||||||
return psiMethods.map {
|
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
|
val param = mandatoryParams.removeLast { getDefaultValue(it) != null } ?: return@apply
|
||||||
defaultValues.add(getDefaultValue(param)!!)
|
defaultValues.add(getDefaultValue(param)!!)
|
||||||
}
|
}
|
||||||
@@ -428,13 +428,13 @@ open class KotlinChangeInfo(
|
|||||||
var defaultValuesRemained = defaultValuesToRetain
|
var defaultValuesRemained = defaultValuesToRetain
|
||||||
for (param in newParameterList) {
|
for (param in newParameterList) {
|
||||||
if (param.isNewParameter || param.defaultValueForParameter == null || defaultValuesRemained-- > 0) continue
|
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
|
defaultValuesRemained = defaultValuesToRetain
|
||||||
val oldParameterCount = originalPsiMethod.parameterList.parametersCount
|
val oldParameterCount = originalPsiMethod.parameterList.parametersCount
|
||||||
var indexInCurrentPsiMethod = 0
|
var indexInCurrentPsiMethod = 0
|
||||||
return newParameterList.withIndex()
|
return newParameterList.asSequence().withIndex()
|
||||||
.mapNotNullTo(ArrayList()) map@ { pair ->
|
.mapNotNullTo(ArrayList()) map@ { pair ->
|
||||||
val (i, info) = pair
|
val (i, info) = pair
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -136,7 +136,7 @@ class KotlinChangeSignatureDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getColumnTextMaxLength(nameFunction: Function1<ParameterTableModelItemBase<KotlinParameterInfo>, String?>) =
|
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) }
|
private fun getParamNamesMaxLength() = getColumnTextMaxLength { getPresentationName(it) }
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -35,8 +35,10 @@ class KotlinCallerUsage(element: KtNamedDeclaration): KotlinUsageInfo<KtNamedDec
|
|||||||
else -> null
|
else -> null
|
||||||
} ?: return true
|
} ?: return true
|
||||||
changeInfo.getNonReceiverParameters()
|
changeInfo.getNonReceiverParameters()
|
||||||
.withIndex()
|
.asSequence()
|
||||||
.filter { it.value.isNewParameter }
|
.withIndex()
|
||||||
|
.filter { it.value.isNewParameter }
|
||||||
|
.toList()
|
||||||
.forEach {
|
.forEach {
|
||||||
val newParameter = it.value.getDeclarationSignature(it.index, changeInfo.methodDescriptor.originalPrimaryCallable)
|
val newParameter = it.value.getDeclarationSignature(it.index, changeInfo.methodDescriptor.originalPrimaryCallable)
|
||||||
parameterList.addParameter(newParameter).addToShorteningWaitSet()
|
parameterList.addParameter(newParameter).addToShorteningWaitSet()
|
||||||
|
|||||||
+2
-2
@@ -335,7 +335,7 @@ class KotlinFunctionCallUsage(
|
|||||||
// Do not add extension receiver to calls with explicit dispatch receiver
|
// Do not add extension receiver to calls with explicit dispatch receiver
|
||||||
if (newReceiverInfo != null && fullCallElement is KtQualifiedExpression && dispatchReceiver is ExpressionReceiver) return element
|
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 (index, param) = it
|
||||||
val oldIndex = param.oldIndex
|
val oldIndex = param.oldIndex
|
||||||
val resolvedArgument = if (oldIndex >= 0) getResolvedValueArgument(oldIndex) else null
|
val resolvedArgument = if (oldIndex >= 0) getResolvedValueArgument(oldIndex) else null
|
||||||
@@ -346,7 +346,7 @@ class KotlinFunctionCallUsage(
|
|||||||
receiverValue = receiverValue.wrapInvalidated(element)
|
receiverValue = receiverValue.wrapInvalidated(element)
|
||||||
}
|
}
|
||||||
ArgumentInfo(param, index, resolvedArgument, receiverValue)
|
ArgumentInfo(param, index, resolvedArgument, receiverValue)
|
||||||
}
|
}.toList()
|
||||||
|
|
||||||
val lastParameterIndex = newParameters.lastIndex
|
val lastParameterIndex = newParameters.lastIndex
|
||||||
var firstNamedIndex = newArgumentInfos.firstOrNull {
|
var firstNamedIndex = newArgumentInfos.firstOrNull {
|
||||||
|
|||||||
+2
-2
@@ -65,7 +65,7 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor<MoveDeclaratio
|
|||||||
val declarations = rangeToDeclarations(file, startOffsets[0], endOffsets[0])
|
val declarations = rangeToDeclarations(file, startOffsets[0], endOffsets[0])
|
||||||
if (declarations.isEmpty()) return emptyList()
|
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) {
|
val sourceObjectFqName = when (parent) {
|
||||||
is KtFile -> null
|
is KtFile -> null
|
||||||
is KtClassBody -> (parent.parent as? KtObjectDeclaration)?.fqName?.asString() ?: return emptyList()
|
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()
|
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()) }
|
val stubTexts = declarations.map { MoveDeclarationsTransferableData.STUB_RENDERER.render(it.unsafeResolveToDescriptor()) }
|
||||||
return listOf(MoveDeclarationsTransferableData(file.virtualFile.url, sourceObjectFqName, stubTexts, declarationNames))
|
return listOf(MoveDeclarationsTransferableData(file.virtualFile.url, sourceObjectFqName, stubTexts, declarationNames))
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ fun KtElement.renderTrimmed(): String {
|
|||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
function.name?.let { builder.append(" $it") }
|
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.equalsToken?.let { builder.append(" = ") }
|
||||||
function.bodyExpression?.accept(this)
|
function.bodyExpression?.accept(this)
|
||||||
}
|
}
|
||||||
@@ -255,12 +255,12 @@ fun KtElement.renderTrimmed(): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPrimaryConstructor(constructor: KtPrimaryConstructor) {
|
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) {
|
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor) {
|
||||||
builder.append("constructor")
|
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)
|
constructor.bodyExpression?.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-7
@@ -106,13 +106,14 @@ class KotlinInlineTypeAliasHandler : InlineActionHandler() {
|
|||||||
val context = usage.analyze(BodyResolveMode.PARTIAL)
|
val context = usage.analyze(BodyResolveMode.PARTIAL)
|
||||||
|
|
||||||
val argumentTypes = usage
|
val argumentTypes = usage
|
||||||
.typeArguments
|
.typeArguments
|
||||||
.filterNotNull()
|
.asSequence()
|
||||||
.mapNotNull {
|
.filterNotNull()
|
||||||
val type = context[BindingContext.ABBREVIATED_TYPE, it.typeReference] ?:
|
.mapNotNull {
|
||||||
context[BindingContext.TYPE, it.typeReference]
|
val type = context[BindingContext.ABBREVIATED_TYPE, it.typeReference] ?: context[BindingContext.TYPE, it.typeReference]
|
||||||
if (type != null) TypeProjectionImpl(type) else null
|
if (type != null) TypeProjectionImpl(type) else null
|
||||||
}
|
}
|
||||||
|
.toList()
|
||||||
if (argumentTypes.size != typeConstructorsToInline.size) return null
|
if (argumentTypes.size != typeConstructorsToInline.size) return null
|
||||||
val substitution = (typeConstructorsToInline zip argumentTypes).toMap()
|
val substitution = (typeConstructorsToInline zip argumentTypes).toMap()
|
||||||
val substitutor = TypeSubstitutor.create(substitution)
|
val substitutor = TypeSubstitutor.create(substitution)
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ class ExtractSuperRefactoring(
|
|||||||
elementsToMove,
|
elementsToMove,
|
||||||
moveTarget,
|
moveTarget,
|
||||||
originalClass,
|
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) {
|
project.runSynchronouslyWithProgress(RefactoringBundle.message("detecting.possible.conflicts"), true) {
|
||||||
|
|||||||
+1
-1
@@ -307,7 +307,7 @@ private fun ExtractionData.analyzeControlFlow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val outParameters =
|
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 =
|
val outDeclarations =
|
||||||
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null }
|
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null }
|
||||||
val modifiedValueCount = outParameters.size + outDeclarations.size
|
val modifiedValueCount = outParameters.size + outDeclarations.size
|
||||||
|
|||||||
+1
-1
@@ -360,7 +360,7 @@ private fun makeCall(
|
|||||||
return when (outputValue) {
|
return when (outputValue) {
|
||||||
is OutputValue.ExpressionValue -> {
|
is OutputValue.ExpressionValue -> {
|
||||||
val exprText = if (outputValue.callSiteReturn) {
|
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 ?: ""
|
val label = firstReturn?.getTargetLabel()?.text ?: ""
|
||||||
"return$label $callText"
|
"return$label $callText"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -248,7 +248,7 @@ class KotlinIntroduceParameterDialog private constructor(
|
|||||||
val space = if (statement.isMultiLine()) "\n" else " "
|
val space = if (statement.isMultiLine()) "\n" else " "
|
||||||
val parameters = function.valueParameters
|
val parameters = function.valueParameters
|
||||||
val parametersText = if (parameters.isNotEmpty()) {
|
val parametersText = if (parameters.isNotEmpty()) {
|
||||||
" " + parameters.map { it.name }.joinToString() + " ->"
|
" " + parameters.asSequence().map { it.name }.joinToString() + " ->"
|
||||||
} else ""
|
} else ""
|
||||||
val text = "{$parametersText$space${statement.text}$space}"
|
val text = "{$parametersText$space${statement.text}$space}"
|
||||||
|
|
||||||
|
|||||||
+33
-26
@@ -124,12 +124,14 @@ fun getParametersToRemove(
|
|||||||
|
|
||||||
val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() }
|
val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() }
|
||||||
return parametersUsages.entrySet()
|
return parametersUsages.entrySet()
|
||||||
.filter {
|
.asSequence()
|
||||||
it.value.all { paramUsage ->
|
.filter {
|
||||||
occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramUsage.textRange) }
|
it.value.all { paramUsage ->
|
||||||
}
|
occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramUsage.textRange) }
|
||||||
}
|
}
|
||||||
.map { it.key }
|
}
|
||||||
|
.map { it.key }
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IntroduceParameterDescriptor.performRefactoring(onExit: (() -> Unit)? = null) {
|
fun IntroduceParameterDescriptor.performRefactoring(onExit: (() -> Unit)? = null) {
|
||||||
@@ -140,12 +142,12 @@ fun IntroduceParameterDescriptor.performRefactoring(onExit: (() -> Unit)? = null
|
|||||||
val parameters = callable.getValueParameters()
|
val parameters = callable.getValueParameters()
|
||||||
val withReceiver = methodDescriptor.receiver != null
|
val withReceiver = methodDescriptor.receiver != null
|
||||||
parametersToRemove
|
parametersToRemove
|
||||||
.map {
|
.map {
|
||||||
if (it is KtParameter) {
|
if (it is KtParameter) {
|
||||||
parameters.indexOf(it) + if (withReceiver) 1 else 0
|
parameters.indexOf(it) + if (withReceiver) 1 else 0
|
||||||
} else 0
|
} else 0
|
||||||
}
|
}
|
||||||
.sortedDescending()
|
.sortedDescending()
|
||||||
.forEach { methodDescriptor.removeParameter(it) }
|
.forEach { methodDescriptor.removeParameter(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,28 +271,33 @@ open class KotlinIntroduceParameterHandler(
|
|||||||
|
|
||||||
val parametersUsages = findInternalUsagesOfParametersAndReceiver(targetParent, functionDescriptor) ?: return
|
val parametersUsages = findInternalUsagesOfParametersAndReceiver(targetParent, functionDescriptor) ?: return
|
||||||
|
|
||||||
val forbiddenRanges = (targetParent as? KtClass)?.declarations?.filter(::isObjectOrNonInnerClass)?.map { it.textRange }
|
val forbiddenRanges = (targetParent as? KtClass)?.declarations?.asSequence()
|
||||||
?: Collections.emptyList()
|
?.filter(::isObjectOrNonInnerClass)
|
||||||
|
?.map { it.textRange }
|
||||||
|
?.toList()
|
||||||
|
?: Collections.emptyList()
|
||||||
|
|
||||||
val occurrencesToReplace = if (expression is KtProperty) {
|
val occurrencesToReplace = if (expression is KtProperty) {
|
||||||
ReferencesSearch.search(expression).mapNotNullTo(SmartList(expression.toRange())) { it.element?.toRange() }
|
ReferencesSearch.search(expression).mapNotNullTo(SmartList(expression.toRange())) { it.element?.toRange() }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
expression.toRange()
|
expression.toRange()
|
||||||
.match(targetParent, KotlinPsiUnifier.DEFAULT)
|
.match(targetParent, KotlinPsiUnifier.DEFAULT)
|
||||||
.filterNot {
|
.asSequence()
|
||||||
val textRange = it.range.getPhysicalTextRange()
|
.filterNot {
|
||||||
forbiddenRanges.any { it.intersects(textRange) }
|
val textRange = it.range.getPhysicalTextRange()
|
||||||
}
|
forbiddenRanges.any { it.intersects(textRange) }
|
||||||
.mapNotNull {
|
}
|
||||||
val matchedElement = it.range.elements.singleOrNull()
|
.mapNotNull {
|
||||||
val matchedExpr = when (matchedElement) {
|
val matchedElement = it.range.elements.singleOrNull()
|
||||||
is KtExpression -> matchedElement
|
val matchedExpr = when (matchedElement) {
|
||||||
is KtStringTemplateEntryWithExpression -> matchedElement.expression
|
is KtExpression -> matchedElement
|
||||||
else -> null
|
is KtStringTemplateEntryWithExpression -> matchedElement.expression
|
||||||
}
|
else -> null
|
||||||
matchedExpr?.toRange()
|
|
||||||
}
|
}
|
||||||
|
matchedExpr?.toRange()
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
project.executeCommand(
|
project.executeCommand(
|
||||||
|
|||||||
+10
-8
@@ -117,14 +117,16 @@ object KotlinIntroduceTypeParameterHandler : RefactoringActionHandler {
|
|||||||
val parameterRefElement = KtPsiFactory(project).createType(restoredTypeParameter.name ?: "_").typeElement!!
|
val parameterRefElement = KtPsiFactory(project).createType(restoredTypeParameter.name ?: "_").typeElement!!
|
||||||
|
|
||||||
val duplicateRanges = restoredOriginalTypeElement
|
val duplicateRanges = restoredOriginalTypeElement
|
||||||
.toRange()
|
.toRange()
|
||||||
.match(restoredOwner, KotlinPsiUnifier.DEFAULT)
|
.match(restoredOwner, KotlinPsiUnifier.DEFAULT)
|
||||||
.filterNot {
|
.asSequence()
|
||||||
val textRange = it.range.getTextRange()
|
.filterNot {
|
||||||
restoredOriginalTypeElement.textRange.intersects(textRange)
|
val textRange = it.range.getTextRange()
|
||||||
|| restoredOwner.typeParameterList?.textRange?.intersects(textRange) ?: false
|
restoredOriginalTypeElement.textRange.intersects(textRange)
|
||||||
}
|
|| restoredOwner.typeParameterList?.textRange?.intersects(textRange) ?: false
|
||||||
.map { it.range.elements.toRange() }
|
}
|
||||||
|
.map { it.range.elements.toRange() }
|
||||||
|
.toList()
|
||||||
|
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
restoredOriginalTypeElement.replace(parameterRefElement)
|
restoredOriginalTypeElement.replace(parameterRefElement)
|
||||||
|
|||||||
+2
-2
@@ -124,7 +124,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
|||||||
private fun replaceExpression(expressionToReplace: KtExpression, addToReferences: Boolean): KtExpression {
|
private fun replaceExpression(expressionToReplace: KtExpression, addToReferences: Boolean): KtExpression {
|
||||||
val isActualExpression = expression == expressionToReplace
|
val isActualExpression = expression == expressionToReplace
|
||||||
|
|
||||||
val replacement = psiFactory.createExpression(nameSuggestions.single().first())
|
val replacement = psiFactory.createExpression(nameSuggestions.asSequence().single().first())
|
||||||
val substringInfo = expressionToReplace.extractableSubstringInfo
|
val substringInfo = expressionToReplace.extractableSubstringInfo
|
||||||
var result = when {
|
var result = when {
|
||||||
expressionToReplace.isLambdaOutsideParentheses() -> {
|
expressionToReplace.isLambdaOutsideParentheses() -> {
|
||||||
@@ -167,7 +167,7 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
|||||||
else {
|
else {
|
||||||
buildString {
|
buildString {
|
||||||
append("$varOvVal ")
|
append("$varOvVal ")
|
||||||
append(nameSuggestions.single().first())
|
append(nameSuggestions.asSequence().single().first())
|
||||||
if (noTypeInference) {
|
if (noTypeInference) {
|
||||||
val typeToRender = expressionType ?: resolutionFacade.moduleDescriptor.builtIns.anyType
|
val typeToRender = expressionType ?: resolutionFacade.moduleDescriptor.builtIns.anyType
|
||||||
append(": ").append(IdeDescriptorRenderers.SOURCE_CODE.renderType(typeToRender))
|
append(": ").append(IdeDescriptorRenderers.SOURCE_CODE.renderType(typeToRender))
|
||||||
|
|||||||
+4
-2
@@ -37,7 +37,8 @@ class KotlinInterfaceMemberDependencyGraph<T : KtNamedDeclaration, M : MemberInf
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun getDependent() = delegateGraph.dependent
|
override fun getDependent() = delegateGraph.dependent
|
||||||
.mapNotNull { it.unwrapped }
|
.asSequence()
|
||||||
|
.mapNotNull { it.unwrapped }
|
||||||
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
|
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@@ -45,7 +46,8 @@ class KotlinInterfaceMemberDependencyGraph<T : KtNamedDeclaration, M : MemberInf
|
|||||||
val psiMember = lightElementForMemberInfo(member) ?: return emptySet()
|
val psiMember = lightElementForMemberInfo(member) ?: return emptySet()
|
||||||
val psiMemberDependencies = delegateGraph.getDependenciesOf(psiMember) ?: return emptySet()
|
val psiMemberDependencies = delegateGraph.getDependenciesOf(psiMember) ?: return emptySet()
|
||||||
return psiMemberDependencies
|
return psiMemberDependencies
|
||||||
.mapNotNull { it.unwrapped }
|
.asSequence()
|
||||||
|
.mapNotNull { it.unwrapped }
|
||||||
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
|
.filterIsInstanceTo(LinkedHashSet<KtNamedDeclaration>()) as Set<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-9
@@ -91,12 +91,13 @@ fun extractClassMembers(
|
|||||||
result: MutableCollection<KotlinMemberInfo>
|
result: MutableCollection<KotlinMemberInfo>
|
||||||
) {
|
) {
|
||||||
declarations
|
declarations
|
||||||
.filter {
|
.asSequence()
|
||||||
it is KtNamedDeclaration
|
.filter {
|
||||||
&& it !is KtConstructor<*>
|
it is KtNamedDeclaration
|
||||||
&& !(it is KtObjectDeclaration && it.isCompanion())
|
&& it !is KtConstructor<*>
|
||||||
&& (filter == null || filter(it))
|
&& !(it is KtObjectDeclaration && it.isCompanion())
|
||||||
}
|
&& (filter == null || filter(it))
|
||||||
|
}
|
||||||
.mapTo(result) { KotlinMemberInfo(it as KtNamedDeclaration, isCompanionMember = isCompanion) }
|
.mapTo(result) { KotlinMemberInfo(it as KtNamedDeclaration, isCompanionMember = isCompanion) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +105,8 @@ fun extractClassMembers(
|
|||||||
|
|
||||||
if (collectSuperTypeEntries) {
|
if (collectSuperTypeEntries) {
|
||||||
aClass.superTypeListEntries
|
aClass.superTypeListEntries
|
||||||
.filterIsInstance<KtSuperTypeEntry>()
|
.asSequence()
|
||||||
|
.filterIsInstance<KtSuperTypeEntry>()
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
val typeReference = it.typeReference ?: return@mapNotNull null
|
val typeReference = it.typeReference ?: return@mapNotNull null
|
||||||
val type = typeReference.analyze(BodyResolveMode.PARTIAL)[BindingContext.TYPE, typeReference]
|
val type = typeReference.analyze(BodyResolveMode.PARTIAL)[BindingContext.TYPE, typeReference]
|
||||||
@@ -121,8 +123,9 @@ fun extractClassMembers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
aClass.primaryConstructor
|
aClass.primaryConstructor
|
||||||
?.valueParameters
|
?.valueParameters
|
||||||
?.filter { it.hasValOrVar() }
|
?.asSequence()
|
||||||
|
?.filter { it.hasValOrVar() }
|
||||||
?.mapTo(result) { KotlinMemberInfo(it) }
|
?.mapTo(result) { KotlinMemberInfo(it) }
|
||||||
|
|
||||||
aClass.extractFromClassBody(filter, false, result)
|
aClass.extractFromClassBody(filter, false, result)
|
||||||
|
|||||||
+1
-1
@@ -322,7 +322,7 @@ class MoveKotlinDeclarationsProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val internalUsageScopes: List<KtElement> = if (descriptor.scanEntireFile) {
|
val internalUsageScopes: List<KtElement> = if (descriptor.scanEntireFile) {
|
||||||
newDeclarations.map { it.containingKtFile }.distinct()
|
newDeclarations.asSequence().map { it.containingKtFile }.distinct().toList()
|
||||||
} else {
|
} else {
|
||||||
newDeclarations
|
newDeclarations
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class KotlinPullUpHelperFactory : PullUpHelperFactory {
|
|||||||
val sourceClass = sourceClass.unwrapped as? KtClassOrObject ?: return null
|
val sourceClass = sourceClass.unwrapped as? KtClassOrObject ?: return null
|
||||||
val targetClass = targetClass.unwrapped as? PsiNamedElement ?: return null
|
val targetClass = targetClass.unwrapped as? PsiNamedElement ?: return null
|
||||||
val membersToMove = membersToMove
|
val membersToMove = membersToMove
|
||||||
.mapNotNull { it.toKtDeclarationWrapperAware() }
|
.mapNotNull { it.toKtDeclarationWrapperAware() }
|
||||||
.sortedBy { it.startOffset }
|
.sortedBy { it.startOffset }
|
||||||
return KotlinPullUpData(sourceClass, targetClass, membersToMove)
|
return KotlinPullUpData(sourceClass, targetClass, membersToMove)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,8 @@ class JavaToKotlinPullUpHelperFactory : PullUpHelperFactory {
|
|||||||
psiClass
|
psiClass
|
||||||
}
|
}
|
||||||
return outerPsiClasses
|
return outerPsiClasses
|
||||||
.drop(1)
|
.asSequence()
|
||||||
|
.drop(1)
|
||||||
.plus(dummyTargetClass)
|
.plus(dummyTargetClass)
|
||||||
.fold(dummyFile.add(outerPsiClasses.first()), PsiElement::add) as PsiClass
|
.fold(dummyFile.add(outerPsiClasses.first()), PsiElement::add) as PsiClass
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ fun addMemberToTarget(targetMember: KtNamedDeclaration, targetClass: KtClassOrOb
|
|||||||
return parameterList.addParameterBefore(targetMember, anchor)
|
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 {
|
return when {
|
||||||
anchor == null && targetMember is KtProperty -> targetClass.addDeclarationBefore(targetMember, null)
|
anchor == null && targetMember is KtProperty -> targetClass.addDeclarationBefore(targetMember, null)
|
||||||
else -> targetClass.addDeclarationAfter(targetMember, anchor)
|
else -> targetClass.addDeclarationAfter(targetMember, anchor)
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ private fun checkMemberClashing(
|
|||||||
|
|
||||||
is KtClassOrObject -> {
|
is KtClassOrObject -> {
|
||||||
targetClass.declarations
|
targetClass.declarations
|
||||||
.filterIsInstance<KtClassOrObject>()
|
.asSequence()
|
||||||
|
.filterIsInstance<KtClassOrObject>()
|
||||||
.firstOrNull() { it.name == member.name }
|
.firstOrNull() { it.name == member.name }
|
||||||
?.let {
|
?.let {
|
||||||
val message = "${targetClassDescriptor.renderForConflicts()} " +
|
val message = "${targetClassDescriptor.renderForConflicts()} " +
|
||||||
|
|||||||
@@ -80,9 +80,11 @@ private fun KtDeclaration.processHierarchyUpward(scope: AnalysisScope, processor
|
|||||||
processor()
|
processor()
|
||||||
val descriptor = unsafeResolveToDescriptor() as? CallableMemberDescriptor ?: return
|
val descriptor = unsafeResolveToDescriptor() as? CallableMemberDescriptor ?: return
|
||||||
DescriptorUtils
|
DescriptorUtils
|
||||||
.getAllOverriddenDescriptors(descriptor)
|
.getAllOverriddenDescriptors(descriptor)
|
||||||
.mapNotNull { it.source.getPsi() }
|
.asSequence()
|
||||||
.filter { scope.contains(it) }
|
.mapNotNull { it.source.getPsi() }
|
||||||
|
.filter { scope.contains(it) }
|
||||||
|
.toList()
|
||||||
.forEach(processor)
|
.forEach(processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,8 +169,9 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention<KtNamedDeclaration
|
|||||||
if (existingClass != null) {
|
if (existingClass != null) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
val existingMethodNames = existingClass
|
val existingMethodNames = existingClass
|
||||||
.declarations
|
.declarations
|
||||||
.filterIsInstance<KtNamedFunction>()
|
.asSequence()
|
||||||
|
.filterIsInstance<KtNamedFunction>()
|
||||||
.mapTo(HashSet()) { it.name }
|
.mapTo(HashSet()) { it.name }
|
||||||
generatedClass
|
generatedClass
|
||||||
.methods
|
.methods
|
||||||
|
|||||||
@@ -221,17 +221,18 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper(
|
|||||||
val imports = file.importDirectives
|
val imports = file.importDirectives
|
||||||
val scopeToImport = getMemberScope(parentFqName, moduleDescriptor) ?: return ImportDescriptorResult.FAIL
|
val scopeToImport = getMemberScope(parentFqName, moduleDescriptor) ?: return ImportDescriptorResult.FAIL
|
||||||
val importedScopes = imports
|
val importedScopes = imports
|
||||||
.filter { it.isAllUnder }
|
.asSequence()
|
||||||
.mapNotNull {
|
.filter { it.isAllUnder }
|
||||||
val importPath = it.importPath
|
.mapNotNull {
|
||||||
if (importPath != null) {
|
val importPath = it.importPath
|
||||||
val fqName = importPath.fqName
|
if (importPath != null) {
|
||||||
getMemberScope(fqName, moduleDescriptor)
|
val fqName = importPath.fqName
|
||||||
}
|
getMemberScope(fqName, moduleDescriptor)
|
||||||
else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
|
|
||||||
val filePackage = moduleDescriptor.getPackage(file.packageFqName)
|
val filePackage = moduleDescriptor.getPackage(file.packageFqName)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user