From a9ddf02556c5bf77c12315c151bcba6ddcacf5f1 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 13 Aug 2020 18:14:02 +0200 Subject: [PATCH] Replace deprecated usages of max/min with maxOrNull/minOrNull --- .../kotlin/incremental/IncrementalJsCache.kt | 2 +- .../kotlin/codegen/inline/ParametersBuilder.kt | 2 +- compiler/daemon/daemon-client-new/build.gradle.kts | 8 ++++++-- compiler/daemon/daemon-client/build.gradle.kts | 7 +++++++ .../jetbrains/kotlin/daemon/CompilerDaemonTest.kt | 2 +- .../experimental/integration/CompilerDaemonTest.kt | 2 +- .../daemon/experimental/unit/ConnectionsTest.kt | 2 +- .../jetbrains/kotlin/daemon/CompileServiceImpl.kt | 2 +- .../experimental/CompileServiceServerSideImpl.kt | 2 +- .../fir/NonFirResolveModularizedTotalKotlinTest.kt | 2 +- .../kotlin/resolve/deprecation/Deprecation.kt | 2 +- .../org/jetbrains/kotlin/resolve/sinceKotlinUtil.kt | 2 +- .../jetbrains/kotlin/ir/types/IrTypeSystemContext.kt | 4 ++-- .../org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt | 2 +- .../src/org/jetbrains/kotlin/psi/createByPattern.kt | 2 +- .../resolve/calls/NewCommonSuperTypeCalculator.kt | 2 +- .../kotlin/resolve/calls/tower/ImplicitScopeTower.kt | 10 ++++++---- .../kotlin/resolve/calls/tower/TowerResolver.kt | 7 +++---- .../jetbrains/kotlin/cfg/AbstractPseudoValueTest.kt | 6 +++--- .../org/jetbrains/kotlin/test/util/jetTestUtils.kt | 5 ----- .../kotlin/types/checker/ClassicTypeSystemContext.kt | 4 ++-- .../deserialization/MemberDeserializer.kt | 2 +- .../decompiler/navigation/SourceNavigationHelper.kt | 2 +- .../kotlin/idea/facet/KotlinVersionInfoProvider.kt | 4 ++-- .../kotlin/idea/highlighter/KotlinPsiChecker.kt | 2 +- .../idea/completion/CompletionBenchmarkSink.kt | 4 ++-- .../kotlin/idea/completion/LookupElementFactory.kt | 4 ++-- .../kotlin/idea/completion/smart/NameSimilarity.kt | 2 +- .../configuration/KotlinMPPGradleProjectResolver.kt | 2 +- .../idea/configuration/klib/KlibInfoProvider.kt | 2 +- .../idea/scratch/output/InlayScratchOutputHandler.kt | 5 ++--- .../idea/maven/KotlinMavenArchetypesProvider.kt | 2 +- .../DifferentMavenStdlibVersionInspection.kt | 2 +- .../idea/debugger/test/AbstractSmartStepIntoTest.kt | 2 +- .../idea/debugger/NoStrataPositionManagerHelper.kt | 2 +- .../kotlin/idea/actions/KotlinAddImportAction.kt | 12 ++++++------ .../benchmark/HighlightingBenchmarkAction.kt | 4 +--- .../codeInsight/KotlinCopyPasteReferenceProcessor.kt | 2 +- .../org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt | 2 +- .../kotlin/idea/quickfix/SuperClassNotInitialized.kt | 2 +- .../refactoring/changeSignature/KotlinChangeInfo.kt | 7 +++---- .../ui/KotlinChangeSignatureDialog.kt | 4 ++-- .../cutPaste/MoveDeclarationsProcessor.kt | 4 ++-- .../introduce/extractionEngine/extractorUtil.kt | 4 ++-- .../idea/refactoring/introduce/introduceUtil.kt | 2 +- .../kotlin/psi/injection/StringInjectionHostTest.kt | 4 ++-- nj2k/src/org/jetbrains/kotlin/nj2k/BaseConversion.kt | 5 ++--- plugins/kapt3/kapt3-cli/src/help.kt | 4 ++-- 48 files changed, 86 insertions(+), 84 deletions(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt index 8cec7d5d511..e0fc64a147d 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt @@ -75,7 +75,7 @@ open class IncrementalJsCache( override fun markDirty(removedAndCompiledSources: Collection) { removedAndCompiledSources.forEach { sourceFile -> // The common prefix of all FQN parents has to be the file package - sourceToClassesMap[sourceFile].map { it.parentOrNull()?.asString() ?: "" }.minBy { it.length }?.let { + sourceToClassesMap[sourceFile].map { it.parentOrNull()?.asString() ?: "" }.minByOrNull { it.length }?.let { packageMetadata.remove(it) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ParametersBuilder.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ParametersBuilder.kt index 33d7506a0df..3e620e7c038 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ParametersBuilder.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ParametersBuilder.kt @@ -91,7 +91,7 @@ class ParametersBuilder private constructor() { } fun buildParameters(): Parameters { - var nextDeclarationIndex = (params.maxBy { it.declarationIndex }?.declarationIndex ?: -1) + 1 + var nextDeclarationIndex = (params.maxOfOrNull { it.declarationIndex } ?: -1) + 1 return Parameters(params.map { param -> if (param is CapturedParamInfo) { diff --git a/compiler/daemon/daemon-client-new/build.gradle.kts b/compiler/daemon/daemon-client-new/build.gradle.kts index 0bed204965a..c94462e9635 100644 --- a/compiler/daemon/daemon-client-new/build.gradle.kts +++ b/compiler/daemon/daemon-client-new/build.gradle.kts @@ -1,5 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - description = "Kotlin Daemon Client New" plugins { @@ -49,6 +47,12 @@ dependencies { } } +tasks.withType> { + kotlinOptions { + apiVersion = "1.3" + } +} + sourceSets { "main" { projectDefault() } "test" {} diff --git a/compiler/daemon/daemon-client/build.gradle.kts b/compiler/daemon/daemon-client/build.gradle.kts index 47026bd22a8..1be90e1a62d 100644 --- a/compiler/daemon/daemon-client/build.gradle.kts +++ b/compiler/daemon/daemon-client/build.gradle.kts @@ -38,6 +38,13 @@ dependencies { } } +tasks.withType> { + kotlinOptions { + // This module is being run from within Gradle, older versions of which only have kotlin-stdlib 1.3 in the runtime classpath. + apiVersion = "1.3" + } +} + sourceSets { "main" { projectDefault() } "test" {} diff --git a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 1970b291066..fd53833dd37 100644 --- a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -170,7 +170,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { val opts2 = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false) assertEquals("300m", opts2.maxMemory) assertEquals( -1, DaemonJVMOptionsMemoryComparator().compare(opts, opts2)) - assertEquals("300m", listOf(opts, opts2).maxWith(DaemonJVMOptionsMemoryComparator())?.maxMemory) + assertEquals("300m", listOf(opts, opts2).maxWithOrNull(DaemonJVMOptionsMemoryComparator())?.maxMemory) val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") } TestCase.assertNotNull(myXmxParam) diff --git a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt index 0a38d52b6b0..e6cde507d29 100644 --- a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt +++ b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt @@ -244,7 +244,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false) assertEquals("300m", opts2.maxMemory) assertEquals(-1, DaemonJVMOptionsMemoryComparator().compare(opts, opts2)) - assertEquals("300m", listOf(opts, opts2).maxWith(DaemonJVMOptionsMemoryComparator())?.maxMemory) + assertEquals("300m", listOf(opts, opts2).maxWithOrNull(DaemonJVMOptionsMemoryComparator())?.maxMemory) val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") } TestCase.assertNotNull(myXmxParam) diff --git a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt index 80a39fd1579..cc205bae8ab 100644 --- a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt +++ b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt @@ -229,7 +229,7 @@ class ConnectionsTest : KotlinIntegrationTestBase() { private fun expectNewDaemon(serverType: ServerType, extraAction: (CompileServiceAsync) -> Unit = {}) = expectDaemon( getDaemons = ::getNewDaemonsOrAsyncWrappers, - chooseDaemon = { daemons -> daemons.maxWith(comparator)!!.daemon }, + chooseDaemon = { daemons -> daemons.maxWithOrNull(comparator)!!.daemon }, getInfo = { d -> runBlocking { d.getDaemonInfo() } }, registerClient = { d -> runBlocking { d.registerClient(generateClient()) } }, port = { d -> d.serverPort }, diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index cd21966485c..53fa924fe76 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -1006,7 +1006,7 @@ class CompileServiceImpl( val comparator = compareByDescending(DaemonJVMOptionsMemoryComparator(), { it.jvmOptions }) .thenBy(FileAgeComparator()) { it.runFile } - aliveWithOpts.maxWith(comparator)?.let { bestDaemonWithMetadata -> + aliveWithOpts.maxWithOrNull(comparator)?.let { bestDaemonWithMetadata -> val fattestOpts = bestDaemonWithMetadata.jvmOptions if (fattestOpts memorywiseFitsInto daemonJVMOptions && FileAgeComparator().compare( bestDaemonWithMetadata.runFile, diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt index 7a68b72a667..5dbef209db5 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt @@ -496,7 +496,7 @@ class CompileServiceServerSideImpl( } .thenBy(FileAgeComparator()) { it.runFile } .thenBy { it.daemon.serverPort } - aliveWithOpts.maxWith(comparator)?.let { bestDaemonWithMetadata -> + aliveWithOpts.maxWithOrNull(comparator)?.let { bestDaemonWithMetadata -> val fattestOpts = bestDaemonWithMetadata.jvmOptions if (fattestOpts memorywiseFitsInto daemonJVMOptions && FileAgeComparator().compare( bestDaemonWithMetadata.runFile, diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt index 2109f162a4e..c4b7daea002 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt @@ -118,7 +118,7 @@ class NonFirResolveModularizedTotalKotlinTest : AbstractModularizedTest() { totalTime = 0L } - val bestTime = times.min()!! + val bestTime = times.minOrNull()!! val bestPass = times.indexOf(bestTime) dumpTime("Best pass: $bestPass", bestTime) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt index ab41cfeee84..e549d4b6477 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt @@ -117,7 +117,7 @@ internal data class DeprecatedByOverridden(private val deprecations: Collection< assert(deprecations.none { it is DeprecatedByOverridden }) } - override val deprecationLevel: DeprecationLevelValue = deprecations.map(Deprecation::deprecationLevel).min()!! + override val deprecationLevel: DeprecationLevelValue = deprecations.map(Deprecation::deprecationLevel).minOrNull()!! override val target: DeclarationDescriptor get() = deprecations.first().target diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/sinceKotlinUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/sinceKotlinUtil.kt index 9648f9f3ba9..a18d94e7c2f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/sinceKotlinUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/sinceKotlinUtil.kt @@ -60,7 +60,7 @@ private data class SinceKotlinValue( private fun getSinceKotlinVersionByOverridden(descriptor: CallableMemberDescriptor): SinceKotlinValue? { // TODO: combine wasExperimentalMarkerClasses in case of several members with the same minimal API version return DescriptorUtils.getAllOverriddenDeclarations(descriptor).map { it.getOwnSinceKotlinVersion() ?: return null } - .minBy { it.apiVersion } + .minByOrNull { it.apiVersion } } /** diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 11f7a3f8fae..9e64d4e4bdb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -250,9 +250,9 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon } override fun SimpleTypeMarker.typeDepth(): Int { - val maxInArguments = (this as IrSimpleType).arguments.asSequence().map { + val maxInArguments = (this as IrSimpleType).arguments.maxOfOrNull { if (it is IrStarProjection) 1 else it.getType().typeDepth() - }.max() ?: 0 + } ?: 0 return maxInArguments + 1 } diff --git a/compiler/psi/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt b/compiler/psi/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt index a99f034e532..26f6de35e30 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt @@ -142,7 +142,7 @@ open class KDocTag(node: ASTNode) : KDocElementImpl(node) { private fun trimCommonIndent(builder: StringBuilder, prepend4WhiteSpaces: Boolean = false): String { val lines = builder.toString().split('\n') - val minIndent = lines.filter { it.trim().isNotEmpty() }.map { it.calcIndent() }.min() ?: 0 + val minIndent = lines.filter { it.trim().isNotEmpty() }.minOfOrNull { it.calcIndent() } ?: 0 var processedLines = lines.map { it.drop(minIndent) } if (prepend4WhiteSpaces) processedLines = processedLines.map { if (it.isNotBlank()) it.prependIndent(indentationWhiteSpaces) else it } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/createByPattern.kt index 4c4c073943d..4cc15eb0446 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -286,7 +286,7 @@ private fun processPattern(pattern: String, args: List): PatternData { } if (!ranges.isEmpty()) { - val max = ranges.keys.max()!! + val max = ranges.keys.maxOrNull()!! for (i in 0..max) { check(ranges.contains(i), "no '$$i' placeholder") } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt index 1cb45dc647e..0fe5c24788a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt @@ -29,7 +29,7 @@ object NewCommonSuperTypeCalculator { } fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List): KotlinTypeMarker { - val maxDepth = types.maxBy { it.typeDepth() }?.typeDepth() ?: 0 + val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0 return commonSuperType(types, -maxDepth, true) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index a970d6dbd15..65dd7f7ded3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -22,7 +22,10 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.* -import org.jetbrains.kotlin.resolve.scopes.* +import org.jetbrains.kotlin.resolve.scopes.LexicalScope +import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.resolve.scopes.ResolutionScope +import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf import org.jetbrains.kotlin.types.KotlinType @@ -86,8 +89,7 @@ class CandidateWithBoundDispatchReceiver( ) fun getResultApplicability(diagnostics: Collection) = - diagnostics.maxBy { it.candidateApplicability }?.candidateApplicability - ?: RESOLVED + diagnostics.maxOfOrNull { it.candidateApplicability } ?: RESOLVED enum class ResolutionCandidateApplicability { RESOLVED, // call success or has uncompleted inference or in other words possible successful candidate @@ -136,4 +138,4 @@ object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(CONVENTION_ object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR) object DeprecatedUnaryPlusAsPlus : ResolutionDiagnostic(CONVENTION_ERROR) -class ResolvedUsingDeprecatedVisibility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED) \ No newline at end of file +class ResolvedUsingDeprecatedVisibility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt index 7e1bc8a2723..28238aa2994 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt @@ -376,15 +376,14 @@ class TowerResolver { } override fun getFinalCandidates(): Collection { - val moreSuitableGroup = candidateGroups.minBy { it.groupApplicability } ?: return emptyList() + val moreSuitableGroup = candidateGroups.minByOrNull { it.groupApplicability } ?: return emptyList() val groupApplicability = moreSuitableGroup.groupApplicability if (groupApplicability == ResolutionCandidateApplicability.HIDDEN) return emptyList() return moreSuitableGroup.filter { it.resultingApplicability == groupApplicability } } - private val Collection.groupApplicability - get() = - minBy { it.resultingApplicability }?.resultingApplicability ?: ResolutionCandidateApplicability.HIDDEN + private val Collection.groupApplicability: ResolutionCandidateApplicability + get() = minOfOrNull { it.resultingApplicability } ?: ResolutionCandidateApplicability.HIDDEN } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/AbstractPseudoValueTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/AbstractPseudoValueTest.kt index 8e5fa2ad3b7..900ba87690c 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/AbstractPseudoValueTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/AbstractPseudoValueTest.kt @@ -79,9 +79,9 @@ abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() { valueDescriptions[value to element] = valueDescription(element, value) } - val elementColumnWidth = elementToValues.keys.map { elementText(it).length }.max() ?: 1 - val valueColumnWidth = allValues.map { valueDecl(it).length }.max()!! - val valueDescColumnWidth = valueDescriptions.values.map { it.length }.max()!! + val elementColumnWidth = elementToValues.keys.maxOfOrNull { elementText(it).length } ?: 1 + val valueColumnWidth = allValues.maxOf { valueDecl(it).length } + val valueDescColumnWidth = valueDescriptions.values.maxOf { it.length } for ((ve, description) in valueDescriptions.entries) { val (value, element) = ve diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/util/jetTestUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/util/jetTestUtils.kt index 56dc826050e..43c44475b69 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/util/jetTestUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/util/jetTestUtils.kt @@ -23,7 +23,6 @@ import com.intellij.util.SmartFMap import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtPackageDirective import org.jetbrains.kotlin.psi.KtTreeVisitorVoid -import java.io.File fun String.trimTrailingWhitespaces(): String = this.split('\n').joinToString(separator = "\n") { it.trimEnd() } @@ -61,10 +60,6 @@ fun PsiFile.findElementsByCommentPrefix(prefix: String): Map return result } -fun findLastModifiedFile(dir: File, skipFile: (File) -> Boolean): File { - return dir.walk().filterNot(skipFile).maxBy { it.lastModified() }!! -} - val CodeInsightTestFixture.elementByOffset: PsiElement get() { return file.findElementAt(editor.caretModel.offset) ?: error("Can't find element at offset. Probably is missing.") diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index b407539b4dd..48288e3952c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -291,9 +291,9 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy require(this is SimpleType, this::errorMessage) if (this is TypeUtils.SpecialType) return 0 - val maxInArguments = arguments.asSequence().map { + val maxInArguments = arguments.maxOfOrNull { if (it.isStarProjection) 1 else it.type.unwrap().typeDepth() - }.max() ?: 0 + } ?: 0 return maxInArguments + 1 } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index 2a3c442dbe3..4944febae7c 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -230,7 +230,7 @@ class MemberDeserializer(private val c: DeserializationContext) { else -> CoroutinesCompatibilityMode.COMPATIBLE } - }.max() ?: CoroutinesCompatibilityMode.COMPATIBLE + }.maxOrNull() ?: CoroutinesCompatibilityMode.COMPATIBLE return maxOf( if (isSuspend) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt index 526dea6ff87..d1797a502b5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt @@ -197,7 +197,7 @@ object SourceNavigationHelper { ): T? { val classFqName = entity.fqName ?: return null return targetScopes(entity, navigationKind).firstNotNullResult { scope -> - index.get(classFqName.asString(), entity.project, scope).minBy { it.isExpectDeclaration() } + index.get(classFqName.asString(), entity.project, scope).minByOrNull { it.isExpectDeclaration() } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt index f9c1bac3b16..c43997f530f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt @@ -47,7 +47,7 @@ fun getLibraryLanguageLevel( ): LanguageVersion { val minVersion = getRuntimeLibraryVersions(module, rootModel, platformKind.orDefault()) .addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased) - .minWith(VersionComparatorUtil.COMPARATOR) + .minWithOrNull(VersionComparatorUtil.COMPARATOR) return getDefaultLanguageLevel(module, minVersion, coerceRuntimeLibraryVersionToReleased) } @@ -60,7 +60,7 @@ fun getDefaultLanguageLevel( ?: KotlinVersionInfoProvider.EP_NAME.extensions .mapNotNull { it.getCompilerVersion(module) } .addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased) - .minWith(VersionComparatorUtil.COMPARATOR) + .minWithOrNull(VersionComparatorUtil.COMPARATOR) ?: return VersionView.RELEASED_VERSION return libVersion.toLanguageVersion() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt index 5c4fda46423..593008c7296 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt @@ -94,7 +94,7 @@ open class KotlinPsiChecker : AbstractKotlinPsiChecker() { } private fun createQuickFixes(similarDiagnostics: Collection): MultiMap { - val first = similarDiagnostics.minBy { it.toString() } + val first = similarDiagnostics.minByOrNull { it.toString() } val factory = similarDiagnostics.first().getRealDiagnosticFactory() val actions = MultiMap() diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionBenchmarkSink.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionBenchmarkSink.kt index 5f0503bea3c..b32d6167867 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionBenchmarkSink.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionBenchmarkSink.kt @@ -65,8 +65,8 @@ interface CompletionBenchmarkSink { pendingSessions -= completionSession perSessionResults[completionSession]?.onEnd(canceled) if (pendingSessions.isEmpty()) { - val firstFlush = perSessionResults.values.filterNot { results -> results.canceled }.map { it.firstFlush }.min() ?: 0 - val full = perSessionResults.values.map { it.full }.max() ?: 0 + val firstFlush = perSessionResults.values.filterNot { results -> results.canceled }.minOfOrNull { it.firstFlush } ?: 0 + val full = perSessionResults.values.maxOfOrNull { it.full } ?: 0 channel.offer(CompletionBenchmarkResults(firstFlush, full)) reset() } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index 4a874324625..03353c6ae52 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -335,7 +335,7 @@ class LookupElementFactory( if (descriptor.overriddenDescriptors.isNotEmpty()) { // Optimization: when one of direct overridden fits, then nothing can fit better descriptor.overriddenDescriptors.mapNotNull { it.callableWeightBasedOnReceiver(receiverTypes, onReceiverTypeMismatch = null) } - .minBy { it.enum }?.let { return it } + .minByOrNull { it.enum }?.let { return it } val overridden = descriptor.overriddenTreeUniqueAsSequence(useOriginal = false) return overridden.map { callableWeightBasic(it, receiverTypes)!! }.minBy { it.enum }!! @@ -397,7 +397,7 @@ class LookupElementFactory( val receiverIndex = bestReceiverType!!.receiverIndex var receiverIndexToUse: Int? = receiverIndex - val maxReceiverIndex = receiverTypes.map { it.receiverIndex }.max()!! + val maxReceiverIndex = receiverTypes.maxOf { it.receiverIndex } if (maxReceiverIndex > 0) { val matchesAllReceivers = (0..maxReceiverIndex).all { it in matchingReceiverIndices } if (matchesAllReceivers) { // if descriptor is matching all receivers then use null as receiverIndex - otherwise e.g. all members of Any would have too high priority diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt index 75b152bd248..a229db95644 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt @@ -20,7 +20,7 @@ object NameSimilarityWeigher : LookupElementWeigher("kotlin.nameSimilarity") { } fun calcNameSimilarity(name: String, expectedInfos: Collection): Int = - expectedInfos.mapNotNull { it.expectedName }.map { calcNameSimilarity(name, it) }.max() ?: 0 + expectedInfos.mapNotNull { it.expectedName }.maxOfOrNull { calcNameSimilarity(name, it) } ?: 0 private fun calcNameSimilarity(name: String, expectedName: String): Int { val words1 = NameUtil.nameToWordsLowerCase(name) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt index ad5f78a451c..764f98259dd 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt @@ -431,7 +431,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp sourceSetToCompilationData[sourceSet.name]?.let { compilationDataRecords -> it.targetCompatibility = compilationDataRecords .mapNotNull { compilationData -> compilationData.targetCompatibility } - .minWith(VersionComparatorUtil.COMPARATOR) + .minWithOrNull(VersionComparatorUtil.COMPARATOR) if (sourceSet.actualPlatforms.getSinglePlatform() == KotlinPlatform.NATIVE) { it.konanTargets = compilationDataRecords diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/klib/KlibInfoProvider.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/klib/KlibInfoProvider.kt index 494148e9f7b..60aad0f7ff3 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/klib/KlibInfoProvider.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/klib/KlibInfoProvider.kt @@ -109,7 +109,7 @@ class KlibInfoProvider(kotlinNativeHome: File) { 1 -> candidates.single() else -> { // there are multiple components, let's take just the first one alphabetically - candidates.minBy { it.getName(it.nameCount - 2).toString() }!! + candidates.minByOrNull { it.getName(it.nameCount - 2).toString() }!! } } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt index f9431622508..c974ccc10c9 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt @@ -106,8 +106,7 @@ class InlayScratchOutputHandler( val doc = textEditor.editor.document return file.getExpressions() .flatMap { it.lineStart..it.lineEnd } - .map { doc.getLineEndOffset(it) - doc.getLineStartOffset(it) } - .max() ?: 0 + .maxOfOrNull { doc.getLineEndOffset(it) - doc.getLineStartOffset(it) } ?: 0 } private fun clearInlays(editor: TextEditor) { @@ -118,4 +117,4 @@ class InlayScratchOutputHandler( .forEach { Disposer.dispose(it) } }) } -} \ No newline at end of file +} diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt index b4f6451e852..cc8aeb84a19 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt @@ -105,7 +105,7 @@ class KotlinMavenArchetypesProvider(private val kotlinPluginVersion: String, pri } private fun chooseVersion(versions: List): MavenArchetype? { - return versions.maxBy { MavenVersionComparable(it.version) } + return versions.maxByOrNull { MavenVersionComparable(it.version) } } private fun connectAndApply(url: String, timeoutSeconds: Int = 15, block: (HttpURLConnection) -> R): R { diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt index a2fdc29598c..409b54f4d0a 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt @@ -73,7 +73,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection, versions: List): List { - val bestVersion = versions.maxBy(::MavenVersionComparable)!! + val bestVersion = versions.maxByOrNull(::MavenVersionComparable)!! if (bestVersion == versionElement.stringValue) { return emptyList() } diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSmartStepIntoTest.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSmartStepIntoTest.kt index 29bc986d8d8..8b00f607092 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSmartStepIntoTest.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSmartStepIntoTest.kt @@ -57,7 +57,7 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase private fun renderTableWithResults(expected: List, actual: List): String { val sb = StringBuilder() - val maxExtStrSize = (expected.maxBy { it.length }?.length ?: 0) + 5 + val maxExtStrSize = (expected.maxOfOrNull { it.length } ?: 0) + 5 val longerList = (if (expected.size < actual.size) actual else expected).sorted() val shorterList = (if (expected.size < actual.size) expected else actual).sorted() for ((i, element) in longerList.withIndex()) { diff --git a/idea/jvm-debugger/jvm-debugger-util/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt b/idea/jvm-debugger/jvm-debugger-util/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt index ee650af506a..6f07ce88176 100644 --- a/idea/jvm-debugger/jvm-debugger-util/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt +++ b/idea/jvm-debugger/jvm-debugger-util/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt @@ -145,7 +145,7 @@ private fun readClassFileImpl( } private fun findClassFileByPaths(packageName: String, className: String, paths: List): File? = - paths.mapNotNull { path -> findClassFileByPath(packageName, className, path) }.maxBy { it.lastModified() } + paths.mapNotNull { path -> findClassFileByPath(packageName, className, path) }.maxByOrNull { it.lastModified() } private fun findClassFileByPath(packageName: String, className: String, outputDirPath: String): File? { val outDirFile = File(outputDirPath).takeIf(File::exists) ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt index 99701d8de5c..e6b07730d4e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinAddImportAction.kt @@ -71,7 +71,8 @@ internal fun createSingleImportAction( val prioritizer = Prioritizer(element.containingKtFile) val variants = fqNames.mapNotNull { fqName -> val sameFqNameDescriptors = file.resolveImportReference(fqName) - val priority = sameFqNameDescriptors.map { prioritizer.priority(it, file.languageVersionSettings) }.min() ?: return@mapNotNull null + val priority = sameFqNameDescriptors.minOfOrNull { prioritizer.priority(it, file.languageVersionSettings) } + ?: return@mapNotNull null Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority) }.sortedBy { it.priority }.map { it.variant } @@ -90,9 +91,8 @@ internal fun createSingleImportActionForConstructor( val sameFqNameDescriptors = file.resolveImportReference(fqName.parent()) .filterIsInstance() .flatMap { it.constructors } - - val priority = - sameFqNameDescriptors.asSequence().map { prioritizer.priority(it, file.languageVersionSettings) }.min() ?: return@mapNotNull null + val priority = sameFqNameDescriptors.minOfOrNull { prioritizer.priority(it, file.languageVersionSettings) } + ?: return@mapNotNull null Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority) }.sortedBy { it.priority }.map { it.variant } return KotlinAddImportAction(project, editor, element, variants) @@ -313,7 +313,7 @@ private class DescriptorGroupPrioritizer(file: KtFile) { val descriptors: List, languageVersionSettings: LanguageVersionSettings ) : Comparable { - val ownDescriptorsPriority = descriptors.asSequence().map { prioritizer.priority(it, languageVersionSettings) }.max()!! + val ownDescriptorsPriority = descriptors.maxOf { prioritizer.priority(it, languageVersionSettings) } override fun compareTo(other: Priority): Int { val c1 = ownDescriptorsPriority.compareTo(other.ownDescriptorsPriority) @@ -356,7 +356,7 @@ private class SingleImportVariant( override val descriptorsToImport: Collection get() = listOf( descriptors.singleOrNull() - ?: descriptors.minBy { if (it is ClassDescriptor) 0 else 1 } + ?: descriptors.minByOrNull { if (it is ClassDescriptor) 0 else 1 } ?: error("we create the class with not-empty descriptors always") ) diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/internal/benchmark/HighlightingBenchmarkAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/internal/benchmark/HighlightingBenchmarkAction.kt index 54e3618c354..a5bbad1e2bd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/internal/benchmark/HighlightingBenchmarkAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/internal/benchmark/HighlightingBenchmarkAction.kt @@ -194,7 +194,7 @@ class HighlightingBenchmarkAction : AnAction() { .mapNotNull { highlighter -> val info = highlighter.errorStripeTooltip as? HighlightInfo ?: return@mapNotNull null info.severity - }.maxWith(Comparator { o1, o2 -> severityRegistrar.compare(o1, o2) }) + }.maxWithOrNull(severityRegistrar) return Result.Success(location, lines, analysisTime, maxSeverity?.myName ?: "clean") } @@ -222,5 +222,3 @@ class HighlightingBenchmarkAction : AnAction() { e.presentation.isEnabledAndVisible = ApplicationManager.getApplication().isInternal } } - - diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt index 95d63efab9a..731c77d98e3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -103,7 +103,7 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor var constrainedCurrentSignatures = currentSignatures.map { it.constrainBy(originalSignature) } - val maxMandatoryCount = constrainedCurrentSignatures.maxBy { it.mandatoryParams.size }!!.mandatoryParams.size + val maxMandatoryCount = constrainedCurrentSignatures.maxOf { it.mandatoryParams.size } constrainedCurrentSignatures = constrainedCurrentSignatures.filter { it.mandatoryParams.size == maxMandatoryCount } - val maxDefaultCount = constrainedCurrentSignatures.maxBy { it.defaultValues.size }!!.defaultValues.size + val maxDefaultCount = constrainedCurrentSignatures.maxOf { it.defaultValues.size } constrainedCurrentSignatures.last { it.defaultValues.size == maxDefaultCount }.method } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt index 065edf90aa0..a370b9a4ced 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt @@ -44,9 +44,9 @@ import com.intellij.util.ui.table.JBTableRow import com.intellij.util.ui.table.JBTableRowEditor import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.refactoring.changeSignature.* import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor.Kind import org.jetbrains.kotlin.idea.refactoring.validateElement @@ -138,7 +138,7 @@ class KotlinChangeSignatureDialog( } private fun getColumnTextMaxLength(nameFunction: Function1, String?>) = - parametersTableModel.items.asSequence().map { nameFunction(it)?.length ?: 0 }.max() ?: 0 + parametersTableModel.items.maxOfOrNull { nameFunction(it)?.length ?: 0 } ?: 0 private fun getParamNamesMaxLength() = getColumnTextMaxLength { getPresentationName(it) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsProcessor.kt index f366ae85d02..f2df8382e28 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/cutPaste/MoveDeclarationsProcessor.kt @@ -93,8 +93,8 @@ class MoveDeclarationsProcessor( // temporary revert imports to the state before they have been changed val importsSubstitution = if (sourcePsiFile.importDirectives.size != imports.size) { - val startOffset = sourcePsiFile.importDirectives.map { it.startOffset }.min() ?: 0 - val endOffset = sourcePsiFile.importDirectives.map { it.endOffset }.min() ?: 0 + val startOffset = sourcePsiFile.importDirectives.minOfOrNull { it.startOffset } ?: 0 + val endOffset = sourcePsiFile.importDirectives.minOfOrNull { it.endOffset } ?: 0 val importsDeclarationsText = sourceDocument.getText(TextRange(startOffset, endOffset)) val tempImportsText = imports.joinToString(separator = "\n") diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index 75af0003f99..c25e671e4a7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -642,9 +642,9 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( } val marginalCandidate = if (insertBefore) { - anchorCandidates.minBy { it.startOffset }!! + anchorCandidates.minByOrNull { it.startOffset }!! } else { - anchorCandidates.maxBy { it.startOffset }!! + anchorCandidates.maxByOrNull { it.startOffset }!! } // Ascend to the level of targetSibling diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceUtil.kt index 41b654dd36c..7ff9b01cf60 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceUtil.kt @@ -240,7 +240,7 @@ fun insertDeclaration(declaration: T, targetSibling: PsiElem anchorCandidates.add(targetSibling.siblings().last { it is KtEnumEntry }) } - val anchor = anchorCandidates.minBy { it.startOffset }!!.parentsWithSelf.first { it.parent == targetParent } + val anchor = anchorCandidates.minByOrNull { it.startOffset }!!.parentsWithSelf.first { it.parent == targetParent } val targetContainer = anchor.parent!! @Suppress("UNCHECKED_CAST") diff --git a/idea/tests/org/jetbrains/kotlin/psi/injection/StringInjectionHostTest.kt b/idea/tests/org/jetbrains/kotlin/psi/injection/StringInjectionHostTest.kt index ee33911b0f4..2a5cd05939b 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/injection/StringInjectionHostTest.kt +++ b/idea/tests/org/jetbrains/kotlin/psi/injection/StringInjectionHostTest.kt @@ -164,11 +164,11 @@ class StringInjectionHostTest : KotlinTestWithEnvironment() { assertEquals(decoded, chars.substring(prefix.length)) val extendedOffsets = HashMap(targetToSourceOffsets) - val beforeStart = targetToSourceOffsets.keys.min()!! - 1 + val beforeStart = targetToSourceOffsets.keys.minOrNull()!! - 1 if (beforeStart >= 0) { extendedOffsets[beforeStart] = -1 } - extendedOffsets[targetToSourceOffsets.keys.max()!! + 1] = -1 + extendedOffsets[targetToSourceOffsets.keys.maxOrNull()!! + 1] = -1 for ((target, source) in extendedOffsets) { assertEquals("Wrong source offset for $target", source, escaper.getOffsetInHost(target, range)) } diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/BaseConversion.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/BaseConversion.kt index db453af3a9b..41f1dbb249f 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/BaseConversion.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/BaseConversion.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.nj2k - import org.jetbrains.kotlin.nj2k.tree.JKTreeElement import org.jetbrains.kotlin.nj2k.types.JKTypeFactory @@ -25,6 +24,6 @@ interface SequentialBaseConversion : Conversion { fun runConversion(treeRoot: JKTreeElement, context: NewJ2kConverterContext): Boolean override fun runConversion(treeRoots: Sequence, context: NewJ2kConverterContext): Boolean { - return treeRoots.asSequence().map { runConversion(it, context) }.max() ?: false + return treeRoots.maxOfOrNull { runConversion(it, context) } ?: false } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-cli/src/help.kt b/plugins/kapt3/kapt3-cli/src/help.kt index bd712e41085..6c1e6c3ad48 100644 --- a/plugins/kapt3/kapt3-cli/src/help.kt +++ b/plugins/kapt3/kapt3-cli/src/help.kt @@ -17,7 +17,7 @@ internal fun printHelp() { .filter { it.cliToolOption != null } .map { OptionToRender(it.nameArgs(), it.description) } - val optionNameColumnWidth = options.asSequence().map { it.nameArgs.length }.max()!! + 2 + val optionNameColumnWidth = options.maxOf { it.nameArgs.length } + 2 val renderedOptions = options.joinToString("\n|") { it.render(optionNameColumnWidth) } val message = """ @@ -41,4 +41,4 @@ private fun KaptCliOption.nameArgs(): String { VALUE -> cliToolOption.name + "=" + valueDescription KEY_VALUE -> cliToolOption.name + valueDescription } -} \ No newline at end of file +}