All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.resolve.multiplatform.OptionalAnnotationUtil.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * 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.resolve.multiplatform

import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.module

object OptionalAnnotationUtil {
    val OPTIONAL_EXPECTATION_FQ_NAME = FqName("kotlin.OptionalExpectation")

    @JvmStatic
    fun shouldGenerateExpectClass(descriptor: ClassDescriptor): Boolean {
        assert(descriptor.isExpect) { "Not an expected class: $descriptor" }

        if (isOptionalAnnotationClass(descriptor)) {
            with(ExpectedActualResolver) {
                return descriptor.findCompatibleActualForExpected(descriptor.module).isEmpty()
            }
        }

        return false
    }

    @JvmStatic
    fun isOptionalAnnotationClass(descriptor: DeclarationDescriptor): Boolean =
        descriptor is ClassDescriptor &&
                descriptor.kind == ClassKind.ANNOTATION_CLASS &&
                descriptor.isExpect &&
                descriptor.annotations.hasAnnotation(OPTIONAL_EXPECTATION_FQ_NAME)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy