Replace usages of addToStdlib.firstNotNullResult with firstNotNullOfOrNull
This commit is contained in:
committed by
TeamCityServer
parent
24b6c5df56
commit
d114913cd2
+1
-2
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
|
||||
import org.jetbrains.kotlin.utils.ReportLevel
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class AnnotationTypeQualifierResolver(storageManager: StorageManager, private val javaTypeEnhancementState: JavaTypeEnhancementState) {
|
||||
class TypeQualifierWithApplicability(
|
||||
@@ -59,7 +58,7 @@ class AnnotationTypeQualifierResolver(storageManager: StorageManager, private va
|
||||
private fun computeTypeQualifierNickname(classDescriptor: ClassDescriptor): AnnotationDescriptor? {
|
||||
if (!classDescriptor.annotations.hasAnnotation(TYPE_QUALIFIER_NICKNAME_FQNAME)) return null
|
||||
|
||||
return classDescriptor.annotations.firstNotNullResult(this::resolveTypeQualifierAnnotation)
|
||||
return classDescriptor.annotations.firstNotNullOfOrNull(this::resolveTypeQualifierAnnotation)
|
||||
}
|
||||
|
||||
private fun resolveTypeQualifierNickname(classDescriptor: ClassDescriptor): AnnotationDescriptor? {
|
||||
|
||||
+3
-4
@@ -57,7 +57,6 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import org.jetbrains.kotlin.utils.ifEmpty
|
||||
import java.util.*
|
||||
|
||||
@@ -288,7 +287,7 @@ class LazyJavaClassMemberScope(
|
||||
getterName: String,
|
||||
functions: (Name) -> Collection<SimpleFunctionDescriptor>
|
||||
): SimpleFunctionDescriptor? {
|
||||
return functions(Name.identifier(getterName)).firstNotNullResult factory@{ descriptor ->
|
||||
return functions(Name.identifier(getterName)).firstNotNullOfOrNull factory@{ descriptor ->
|
||||
if (descriptor.valueParameters.size != 0) return@factory null
|
||||
|
||||
descriptor.takeIf { KotlinTypeChecker.DEFAULT.isSubtypeOf(descriptor.returnType ?: return@takeIf false, type) }
|
||||
@@ -298,7 +297,7 @@ class LazyJavaClassMemberScope(
|
||||
private fun PropertyDescriptor.findSetterOverride(
|
||||
functions: (Name) -> Collection<SimpleFunctionDescriptor>
|
||||
): SimpleFunctionDescriptor? {
|
||||
return functions(Name.identifier(JvmAbi.setterName(name.asString()))).firstNotNullResult factory@{ descriptor ->
|
||||
return functions(Name.identifier(JvmAbi.setterName(name.asString()))).firstNotNullOfOrNull factory@{ descriptor ->
|
||||
if (descriptor.valueParameters.size != 1) return@factory null
|
||||
|
||||
if (!KotlinBuiltIns.isUnit(descriptor.returnType ?: return@factory null)) return@factory null
|
||||
@@ -448,7 +447,7 @@ class LazyJavaClassMemberScope(
|
||||
): SimpleFunctionDescriptor? {
|
||||
if (!descriptor.isSuspend) return null
|
||||
|
||||
return functions(descriptor.name).firstNotNullResult { overrideCandidate ->
|
||||
return functions(descriptor.name).firstNotNullOfOrNull { overrideCandidate ->
|
||||
overrideCandidate.createSuspendView()?.takeIf { suspendView -> suspendView.doesOverride(descriptor) }
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
|
||||
import org.jetbrains.kotlin.utils.ReportLevel
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class SignatureEnhancement(
|
||||
@@ -461,7 +460,7 @@ class SignatureEnhancement(
|
||||
areImprovementsEnabled: Boolean,
|
||||
typeParameterBounds: Boolean
|
||||
): NullabilityQualifierWithMigrationStatus? =
|
||||
this.firstNotNullResult { extractNullability(it, areImprovementsEnabled, typeParameterBounds) }
|
||||
this.firstNotNullOfOrNull { extractNullability(it, areImprovementsEnabled, typeParameterBounds) }
|
||||
|
||||
private fun computeIndexedQualifiersForOverride(): (Int) -> JavaTypeQualifiers {
|
||||
|
||||
|
||||
@@ -93,11 +93,16 @@ fun <T : Any> constant(calculator: () -> T): T {
|
||||
private val constantMap = ConcurrentHashMap<Function0<*>, Any>()
|
||||
|
||||
fun String.indexOfOrNull(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): Int? =
|
||||
indexOf(char, startIndex, ignoreCase).takeIf { it >= 0 }
|
||||
indexOf(char, startIndex, ignoreCase).takeIf { it >= 0 }
|
||||
|
||||
fun String.lastIndexOfOrNull(char: Char, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int? =
|
||||
lastIndexOf(char, startIndex, ignoreCase).takeIf { it >= 0 }
|
||||
lastIndexOf(char, startIndex, ignoreCase).takeIf { it >= 0 }
|
||||
|
||||
@Deprecated(
|
||||
message = "Use firstNotNullOfOrNull from stdlib instead",
|
||||
replaceWith = ReplaceWith("firstNotNullOfOrNull(transform)"),
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
inline fun <T, R : Any> Iterable<T>.firstNotNullResult(transform: (T) -> R?): R? {
|
||||
for (element in this) {
|
||||
val result = transform(element)
|
||||
@@ -106,14 +111,6 @@ inline fun <T, R : Any> Iterable<T>.firstNotNullResult(transform: (T) -> R?): R?
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun <T, R : Any> Array<T>.firstNotNullResult(transform: (T) -> R?): R? {
|
||||
for (element in this) {
|
||||
val result = transform(element)
|
||||
if (result != null) return result
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
|
||||
var sum: Long = 0
|
||||
for (element in this) {
|
||||
@@ -126,7 +123,7 @@ inline fun <T, C : Collection<T>, O> C.ifNotEmpty(body: C.() -> O?): O? = if (is
|
||||
|
||||
inline fun <T, O> Array<out T>.ifNotEmpty(body: Array<out T>.() -> O?): O? = if (isNotEmpty()) this.body() else null
|
||||
|
||||
inline fun <T> measureTimeMillisWithResult(block: () -> T) : Pair<Long, T> {
|
||||
inline fun <T> measureTimeMillisWithResult(block: () -> T): Pair<Long, T> {
|
||||
val start = System.currentTimeMillis()
|
||||
val result = block()
|
||||
return Pair(System.currentTimeMillis() - start, result)
|
||||
|
||||
Reference in New Issue
Block a user