Address JDK8/JDK6 issues with computeIfAbsent

This commit is contained in:
Irene Dea
2021-12-01 14:09:54 -08:00
committed by Dmitriy Novozhilov
parent 374d287d08
commit 3c4989b672
8 changed files with 45 additions and 6 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.util.ConeTypeRegistry
import org.jetbrains.kotlin.util.AttributeArrayOwner
import org.jetbrains.kotlin.util.TypeRegistry
import org.jetbrains.kotlin.types.model.AnnotationMarker
@@ -36,7 +37,7 @@ abstract class ConeAttribute<T : ConeAttribute<T>> : AnnotationMarker {
class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : AttributeArrayOwner<ConeAttribute<*>, ConeAttribute<*>>(),
Iterable<ConeAttribute<*>> {
companion object : TypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() {
companion object : ConeTypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() {
inline fun <reified T : ConeAttribute<T>> attributeAccessor(): ReadOnlyProperty<ConeAttributes, T?> {
@Suppress("UNCHECKED_CAST")
return generateNullableAccessor<ConeAttribute<*>, T>(T::class) as ReadOnlyProperty<ConeAttributes, T?>
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.util
import org.jetbrains.kotlin.util.TypeRegistry
import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KClass
abstract class ConeTypeRegistry<K : Any, V : Any> : TypeRegistry<K, V>() {
override fun <T : K> ConcurrentHashMap<KClass<out K>, Int>.customComputeIfAbsent(
kClass: KClass<T>,
compute: (KClass<out K>) -> Int
): Int {
return this.computeIfAbsent(kClass, compute)
}
}