mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 06:59:44 +07:00
Declare contract for asSafely method
GitOrigin-RevId: e3797d068110395045e4ffab4b64ef92a5223ac4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4cc5565065
commit
e84b0a31e3
@@ -9,8 +9,14 @@ import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
inline fun <reified T : Any> Any?.asSafely(): @kotlin.internal.NoInfer T? = this as? T
|
||||
inline fun <reified T : Any> Any?.asSafely(): @kotlin.internal.NoInfer T? {
|
||||
contract {
|
||||
returnsNotNull() implies (this@asSafely is T)
|
||||
}
|
||||
return this as? T
|
||||
}
|
||||
|
||||
inline fun <T> runIf(condition: Boolean, block: () -> T): T? = if (condition) block() else null
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
internal fun IElementType.getOperatorType() = when (this) {
|
||||
JavaTokenType.EQ -> UastBinaryOperator.ASSIGN
|
||||
@@ -87,9 +89,14 @@ fun isJava(language: Language?): Boolean {
|
||||
return language == JavaLanguage.INSTANCE
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
internal inline fun <reified T : Any> Any?.asSafely(): @kotlin.internal.NoInfer T? = this as? T
|
||||
|
||||
inline fun <reified T : Any> Any?.asSafely(): @kotlin.internal.NoInfer T? {
|
||||
contract {
|
||||
returnsNotNull() implies (this@asSafely is T)
|
||||
}
|
||||
return this as? T
|
||||
}
|
||||
fun PsiElement?.isSemicolon(): Boolean {
|
||||
if (this !is PsiJavaToken) return false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user