org.jetbrains.kotlin.fir.visitors.CompositeTransformResult.kt Maven / Gradle / Ivy
/*
* Copyright 2000-2018 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.visitors
import org.jetbrains.kotlin.fir.FirElement
sealed class CompositeTransformResult {
class Single(val _single: T) : CompositeTransformResult()
class Multiple(val _list: List) : CompositeTransformResult()
companion object {
fun empty() = Multiple(emptyList())
fun single(t: T) = Single(t)
fun many(l: List) = Multiple(l)
}
@Suppress("UNCHECKED_CAST")
val list: List
get() = when (this) {
is Multiple<*> -> _list as List
else -> error("!")
}
@Suppress("UNCHECKED_CAST")
val single: T
get() = when (this) {
is Single<*> -> _single as T
else -> error("!")
}
val isSingle
get() = this is Single<*>
val isEmpty
get() = this is Multiple<*> && this.list.isEmpty()
}
@Suppress("NOTHING_TO_INLINE")
inline fun T.compose() = CompositeTransformResult.single(this)