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

main.seskar.compiler.diagnostics.RedundantDiagnosticSuppressor.kt Maven / Gradle / Ivy

There is a newer version: 3.32.0
Show newest version
package seskar.compiler.diagnostics

import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
import org.jetbrains.kotlin.js.resolve.diagnostics.ErrorsJs
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor

private const val EXTERNAL_PRIVATE_CONSTRUCTOR = "private member of class"

class RedundantDiagnosticSuppressor : DiagnosticSuppressor {
    override fun isSuppressed(
        diagnostic: Diagnostic,
    ): Boolean =
        false

    override fun isSuppressed(
        diagnostic: Diagnostic,
        bindingContext: BindingContext?,
    ): Boolean {
        bindingContext ?: return false

        val psiElement = diagnostic.psiElement
        val factory = diagnostic.factory

        return when (factory) {
            ErrorsJs.WRONG_EXTERNAL_DECLARATION,
            -> when (psiElement) {
                is KtPrimaryConstructor,
                -> diagnostic.messageParameter == EXTERNAL_PRIVATE_CONSTRUCTOR

                else -> false
            }

            ErrorsJs.NESTED_CLASS_IN_EXTERNAL_INTERFACE,
            -> psiElement is KtObjectDeclaration && psiElement.isCompanion()

            else -> false
        }
    }
}

private val Diagnostic.messageParameter: String?
    get() = when (this) {
        is DiagnosticWithParameters1<*, *> -> a as? String
        else -> null
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy