Replace deprecated usages of max/min with maxOrNull/minOrNull
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
|
||||
kotlinOptions {
|
||||
apiVersion = "1.3"
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" {}
|
||||
|
||||
@@ -38,6 +38,13 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
|
||||
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" {}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+1
-1
@@ -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 },
|
||||
|
||||
@@ -1006,7 +1006,7 @@ class CompileServiceImpl(
|
||||
val comparator =
|
||||
compareByDescending<DaemonWithMetadata, DaemonJVMOptions>(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,
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -286,7 +286,7 @@ private fun processPattern(pattern: String, args: List<Any>): 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")
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ object NewCommonSuperTypeCalculator {
|
||||
}
|
||||
|
||||
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
||||
val maxDepth = types.maxBy { it.typeDepth() }?.typeDepth() ?: 0
|
||||
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
|
||||
return commonSuperType(types, -maxDepth, true)
|
||||
}
|
||||
|
||||
|
||||
+6
-4
@@ -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<KotlinCallDiagnostic>) =
|
||||
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)
|
||||
class ResolvedUsingDeprecatedVisibility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED)
|
||||
|
||||
@@ -376,15 +376,14 @@ class TowerResolver {
|
||||
}
|
||||
|
||||
override fun getFinalCandidates(): Collection<C> {
|
||||
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<C>.groupApplicability
|
||||
get() =
|
||||
minBy { it.resultingApplicability }?.resultingApplicability ?: ResolutionCandidateApplicability.HIDDEN
|
||||
private val Collection<C>.groupApplicability: ResolutionCandidateApplicability
|
||||
get() = minOfOrNull { it.resultingApplicability } ?: ResolutionCandidateApplicability.HIDDEN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PsiElement, String>
|
||||
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 <caret> is missing.")
|
||||
|
||||
Reference in New Issue
Block a user