
org.jetbrains.kotlin.backend.common.CommonBackendErrors.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2023 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.backend.common
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.EXPECT_ACTUAL_ANNOTATION_INCOMPATIBILITY
import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.INCOMPATIBILITY
import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.SYMBOL_OWNER_DECLARATION_FQ_NAME
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.diagnostics.*
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
import org.jetbrains.kotlin.diagnostics.rendering.Renderers.MODULE_WITH_PLATFORM
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.classFqName
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualAnnotationsIncompatibilityType
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
object CommonBackendErrors {
val NO_ACTUAL_FOR_EXPECT by error2()
val MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED by error2()
val MANY_IMPL_MEMBER_NOT_IMPLEMENTED by error2()
val INCOMPATIBLE_MATCHING by error3>()
val ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT by warning3>()
val EVALUATION_ERROR by error1()
init {
RootDiagnosticRendererFactory.registerFactory(KtDefaultCommonBackendErrorMessages)
}
}
object KtDefaultCommonBackendErrorMessages : BaseDiagnosticRendererFactory() {
override val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
map.put(
CommonBackendErrors.NO_ACTUAL_FOR_EXPECT,
"Expected {0} has no actual declaration in module {1}",
STRING,
MODULE_WITH_PLATFORM,
)
map.put(
CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED,
"{0} must override {1} because it inherits multiple interface methods of it",
STRING,
STRING,
)
map.put(
CommonBackendErrors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED,
"{0} must override {1} because it inherits many implementations of it",
STRING,
STRING,
)
map.put(
CommonBackendErrors.INCOMPATIBLE_MATCHING,
"Expect declaration `{0}` doesn''t match actual `{1}` because {2}",
STRING,
STRING,
INCOMPATIBILITY
)
map.put(
CommonBackendErrors.ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT,
"{2}.\n" +
"All annotations from expect `{0}` must be present with the same arguments on actual `{1}`, otherwise they might behave incorrectly.",
SYMBOL_OWNER_DECLARATION_FQ_NAME,
SYMBOL_OWNER_DECLARATION_FQ_NAME,
EXPECT_ACTUAL_ANNOTATION_INCOMPATIBILITY,
)
map.put(
CommonBackendErrors.EVALUATION_ERROR,
"Cannot evaluate constant expression: {0}",
STRING,
)
}
}
object BackendDiagnosticRenderers {
val INCOMPATIBILITY = Renderer> {
it.reason ?: ""
}
val SYMBOL_OWNER_DECLARATION_FQ_NAME = Renderer {
(it.owner as? IrDeclarationWithName)?.fqNameWhenAvailable?.asString() ?: "unknown name"
}
val EXPECT_ACTUAL_ANNOTATION_INCOMPATIBILITY =
Renderer { incompatibilityType: ExpectActualAnnotationsIncompatibilityType ->
val expectAnnotationFqName = incompatibilityType.expectAnnotation.type.classFqName ?: ""
val reason = when (incompatibilityType) {
is ExpectActualAnnotationsIncompatibilityType.MissingOnActual -> "is missing on actual declaration"
is ExpectActualAnnotationsIncompatibilityType.DifferentOnActual -> "has different arguments on actual declaration"
}
"Annotation `$expectAnnotationFqName` $reason"
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy