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

org.jetbrains.kotlin.psi2ir.PsiErrorBuilder.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2020 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.psi2ir

import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.util.render
import kotlin.reflect.KClass

class PsiErrorBuilder(
    private val psiSourceManager: PsiSourceManager,
    private val diagnosticSink: DiagnosticSink
) {

    fun  at(irDeclaration: IrDeclaration, psiElementClass: KClass): Location =
        Location(
            psiSourceManager.findPsiElement(irDeclaration, psiElementClass)
                ?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irDeclaration.render()}'")
        )

    fun at(irDeclaration: IrDeclaration): Location =
        Location(
            psiSourceManager.findPsiElement(irDeclaration)
                ?: throw AssertionError("No PsiElement found for '${irDeclaration.render()}'")
        )

    fun  at(psiElement: E) = Location(psiElement)

    fun  at(irElement: IrElement, irDeclaration: IrDeclaration, psiElementClass: KClass): Location =
        Location(
            psiSourceManager.findPsiElement(irElement, irDeclaration, psiElementClass)
                ?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irElement.render()}'")
        )

    fun at(irElement: IrElement, irDeclaration: IrDeclaration): Location =
        Location(
            psiSourceManager.findPsiElement(irElement, irDeclaration)
                ?: throw AssertionError("No PsiElement found for '${irElement.render()}'")
        )

    fun  at(irElement: IrElement, irFile: IrFile, psiElementClass: KClass): Location =
        Location(
            psiSourceManager.findPsiElement(irElement, irFile, psiElementClass)
                ?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irElement.render()}'")
        )

    fun at(irElement: IrElement, irFile: IrFile): Location =
        Location(
            psiSourceManager.findPsiElement(irElement, irFile)
                ?: throw AssertionError("No PsiElement found for '${irElement.render()}'")
        )

    inner class Location(private val psiElement: E) {

        fun report(diagnosticFactory: DiagnosticFactory0) {
            diagnosticSink.report(diagnosticFactory.on(psiElement))
        }

        fun  report(diagnosticFactory: DiagnosticFactory1, a: A) {
            diagnosticSink.report(diagnosticFactory.on(psiElement, a))
        }

        fun  report(diagnosticFactory: DiagnosticFactory2, a: A, b: B) {
            diagnosticSink.report(diagnosticFactory.on(psiElement, a, b))
        }

        fun  report(diagnosticFactory: DiagnosticFactory3, a: A, b: B, c: C) {
            diagnosticSink.report(diagnosticFactory.on(psiElement, a, b, c))
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy