Replace deprecated usages of max/min with maxOrNull/minOrNull
This commit is contained in:
+1
-1
@@ -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() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ open class KotlinPsiChecker : AbstractKotlinPsiChecker() {
|
||||
}
|
||||
|
||||
private fun createQuickFixes(similarDiagnostics: Collection<Diagnostic>): MultiMap<Diagnostic, IntentionAction> {
|
||||
val first = similarDiagnostics.minBy { it.toString() }
|
||||
val first = similarDiagnostics.minByOrNull { it.toString() }
|
||||
val factory = similarDiagnostics.first().getRealDiagnosticFactory()
|
||||
|
||||
val actions = MultiMap<Diagnostic, IntentionAction>()
|
||||
|
||||
+2
-2
@@ -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()
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ object NameSimilarityWeigher : LookupElementWeigher("kotlin.nameSimilarity") {
|
||||
}
|
||||
|
||||
fun calcNameSimilarity(name: String, expectedInfos: Collection<ExpectedInfo>): 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)
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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() }!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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) }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ class KotlinMavenArchetypesProvider(private val kotlinPluginVersion: String, pri
|
||||
}
|
||||
|
||||
private fun chooseVersion(versions: List<MavenArchetype>): MavenArchetype? {
|
||||
return versions.maxBy { MavenVersionComparable(it.version) }
|
||||
return versions.maxByOrNull { MavenVersionComparable(it.version) }
|
||||
}
|
||||
|
||||
private fun <R> connectAndApply(url: String, timeoutSeconds: Int = 15, block: (HttpURLConnection) -> R): R {
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
|
||||
}
|
||||
|
||||
private fun createFixes(project: MavenProject, versionElement: GenericDomValue<*>, versions: List<String>): List<SetVersionQuickFix> {
|
||||
val bestVersion = versions.maxBy(::MavenVersionComparable)!!
|
||||
val bestVersion = versions.maxByOrNull(::MavenVersionComparable)!!
|
||||
if (bestVersion == versionElement.stringValue) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase
|
||||
private fun renderTableWithResults(expected: List<String>, actual: List<String>): 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()) {
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ private fun readClassFileImpl(
|
||||
}
|
||||
|
||||
private fun findClassFileByPaths(packageName: String, className: String, paths: List<String>): 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
|
||||
|
||||
@@ -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<ClassDescriptor>()
|
||||
.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<DeclarationDescriptor>,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) : Comparable<Priority> {
|
||||
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<DeclarationDescriptor>
|
||||
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")
|
||||
)
|
||||
|
||||
|
||||
+1
-3
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor<BasicKotlinRefe
|
||||
|
||||
val packageName = file.packageDirective?.fqName?.asString() ?: ""
|
||||
val imports = file.importDirectives.map { it.text }
|
||||
val endOfImportsOffset = file.importDirectives.map { it.endOffset }.max() ?: file.packageDirective?.endOffset ?: 0
|
||||
val endOfImportsOffset = file.importDirectives.maxOfOrNull { it.endOffset } ?: file.packageDirective?.endOffset ?: 0
|
||||
val offsetDelta = if (startOffsets.any { it <= endOfImportsOffset }) 0 else endOfImportsOffset
|
||||
val text = file.text.substring(offsetDelta)
|
||||
val ranges = startOffsets.indices.map { TextRange(startOffsets[it], endOffsets[it]) }
|
||||
|
||||
@@ -88,7 +88,7 @@ object KDocRenderer {
|
||||
fun String.leadingIndent() = indexOfFirst { !it.isWhitespace() }
|
||||
|
||||
val lines = text.split('\n')
|
||||
val minIndent = lines.filter { it.trim().isNotEmpty() }.map(String::leadingIndent).min() ?: 0
|
||||
val minIndent = lines.filter { it.trim().isNotEmpty() }.minOfOrNull(String::leadingIndent) ?: 0
|
||||
return lines.joinToString("\n") { it.drop(minIndent) }
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
|
||||
|
||||
fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size == parameterTypes.size
|
||||
|
||||
val maxParams = parameterTypes.asSequence().map { it.size }.max()!!
|
||||
val maxParams = parameterTypes.maxOf { it.size }
|
||||
val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) {
|
||||
maxParams
|
||||
} else {
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaOrKotlinMemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.util.javaResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.j2k.j2k
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor.Kind
|
||||
@@ -45,10 +44,10 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCaller
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.isError
|
||||
@@ -372,9 +371,9 @@ open class KotlinChangeInfo(
|
||||
val currentSignatures = initCurrentSignatures(currentPsiMethods)
|
||||
return originalSignatures.associateBy({ it.method }) { originalSignature ->
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<ParameterTableModelItemBase<KotlinParameterInfo>, 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) }
|
||||
|
||||
|
||||
+2
-2
@@ -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")
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -240,7 +240,7 @@ fun <T : KtDeclaration> 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")
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user