[FIR] Consolidate SYNTAX and SYNTAX_WITH_MESSAGE diagnostics
This commit is contained in:
committed by
Space Team
parent
871a148529
commit
bdf0b41026
-6
@@ -5083,12 +5083,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirSyntaxErrors.SYNTAX) { firDiagnostic ->
|
||||
SyntaxImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirSyntaxErrors.SYNTAX_WITH_MESSAGE) { firDiagnostic ->
|
||||
SyntaxWithMessageImpl(
|
||||
firDiagnostic.a,
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
|
||||
-4
@@ -3539,10 +3539,6 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
abstract class Syntax : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = Syntax::class
|
||||
}
|
||||
|
||||
abstract class SyntaxWithMessage : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = SyntaxWithMessage::class
|
||||
abstract val message: String
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -4279,13 +4279,8 @@ internal class WrongOperationWithDynamicImpl(
|
||||
) : KtFirDiagnostic.WrongOperationWithDynamic(), KtAbstractFirDiagnostic<KtElement>
|
||||
|
||||
internal class SyntaxImpl(
|
||||
override val message: String,
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtFirDiagnostic.Syntax(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
internal class SyntaxWithMessageImpl(
|
||||
override val message: String,
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtFirDiagnostic.SyntaxWithMessage(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
|
||||
+1
-2
@@ -13,8 +13,7 @@ import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticL
|
||||
@OptIn(PrivateForInline::class)
|
||||
object SYNTAX_DIAGNOSTIC_LIST : DiagnosticList("FirSyntaxErrors") {
|
||||
val Syntax by object : DiagnosticGroup("Syntax") {
|
||||
val SYNTAX by error<PsiElement>()
|
||||
val SYNTAX_WITH_MESSAGE by error<PsiElement>() {
|
||||
val SYNTAX by error<PsiElement> {
|
||||
parameter<String>("message")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -102,6 +102,7 @@ private fun ConeDiagnostic.toKtDiagnostic(
|
||||
|
||||
is ConeSimpleDiagnostic -> when {
|
||||
source.kind is KtFakeSourceElementKind && source.kind != KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess -> null
|
||||
kind == DiagnosticKind.Syntax -> FirSyntaxErrors.SYNTAX.createOn(qualifiedAccessSource ?: source, reason)
|
||||
else -> this.getFactory(source).createOn(qualifiedAccessSource ?: source)
|
||||
}
|
||||
|
||||
@@ -486,7 +487,6 @@ private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType a
|
||||
|
||||
private fun ConeSimpleDiagnostic.getFactory(source: KtSourceElement): KtDiagnosticFactory0 {
|
||||
return when (kind) {
|
||||
DiagnosticKind.Syntax -> FirSyntaxErrors.SYNTAX
|
||||
DiagnosticKind.ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED
|
||||
DiagnosticKind.NotAFunctionLabel -> FirErrors.NOT_A_FUNCTION_LABEL
|
||||
DiagnosticKind.UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL
|
||||
@@ -532,6 +532,7 @@ private fun ConeSimpleDiagnostic.getFactory(source: KtSourceElement): KtDiagnost
|
||||
DiagnosticKind.UnresolvedSupertype,
|
||||
DiagnosticKind.UnresolvedExpandedType,
|
||||
DiagnosticKind.Other -> FirErrors.OTHER_ERROR
|
||||
DiagnosticKind.Syntax -> error("Must not be called on `Syntax` because a message is required.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -90,11 +90,12 @@ class DeclarationsConverter(
|
||||
|
||||
override fun reportSyntaxError(node: LighterASTNode) {
|
||||
val message = PsiBuilderImpl.getErrorMessage(node)
|
||||
if (message == null) {
|
||||
diagnosticsReporter?.reportOn(node.toFirSourceElement(), FirSyntaxErrors.SYNTAX, diagnosticContext!!)
|
||||
} else {
|
||||
diagnosticsReporter?.reportOn(node.toFirSourceElement(), FirSyntaxErrors.SYNTAX_WITH_MESSAGE, message, diagnosticContext!!)
|
||||
}
|
||||
diagnosticsReporter?.reportOn(
|
||||
node.toFirSourceElement(),
|
||||
FirSyntaxErrors.SYNTAX,
|
||||
message ?: "Unspecified",
|
||||
diagnosticContext!!,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -16,8 +16,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||
|
||||
object FirSyntaxErrors {
|
||||
// Syntax
|
||||
val SYNTAX by error0<PsiElement>()
|
||||
val SYNTAX_WITH_MESSAGE by error1<PsiElement, String>()
|
||||
val SYNTAX by error1<PsiElement, String>()
|
||||
|
||||
init {
|
||||
RootDiagnosticRendererFactory.registerFactory(FirSyntaxErrorsDefaultMessages)
|
||||
|
||||
+2
-4
@@ -6,14 +6,12 @@
|
||||
package org.jetbrains.kotlin.fir.builder
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.TO_STRING
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.OPTIONAL_COLON_TO_STRING
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||
|
||||
@Suppress("unused")
|
||||
object FirSyntaxErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
override val MAP = KtDiagnosticFactoryToRendererMap("FIR").also { map ->
|
||||
map.put(FirSyntaxErrors.SYNTAX, "Syntax error")
|
||||
map.put(FirSyntaxErrors.SYNTAX_WITH_MESSAGE, "Syntax error: {0}", TO_STRING)
|
||||
map.put(FirSyntaxErrors.SYNTAX, "Syntax error{0}", OPTIONAL_COLON_TO_STRING)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ object KtDiagnosticRenderers {
|
||||
element.toString()
|
||||
}
|
||||
|
||||
val OPTIONAL_COLON_TO_STRING = Renderer { element: Any? ->
|
||||
val string = element.toString()
|
||||
if (string.isNotEmpty()) ": $string" else ""
|
||||
}
|
||||
|
||||
val EMPTY = Renderer { _: Any? -> "" }
|
||||
|
||||
val VISIBILITY = Renderer { visibility: Visibility ->
|
||||
|
||||
+14
-10
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import com.intellij.lang.impl.PsiBuilderImpl
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory0
|
||||
@@ -106,7 +107,7 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
) {
|
||||
val metaInfos = if (firFile.psi != null) {
|
||||
AnalyzingUtils.getSyntaxErrorRanges(firFile.psi!!).flatMap {
|
||||
FirSyntaxErrors.SYNTAX.on(KtRealPsiSourceElement(it), positioningStrategy = null)
|
||||
FirSyntaxErrors.SYNTAX.on(KtRealPsiSourceElement(it), it.errorDescription, positioningStrategy = null)
|
||||
.toMetaInfos(
|
||||
module,
|
||||
testFile,
|
||||
@@ -118,15 +119,18 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
}
|
||||
} else {
|
||||
collectLightTreeSyntaxErrors(firFile).flatMap { sourceElement ->
|
||||
FirSyntaxErrors.SYNTAX.on(sourceElement, positioningStrategy = null)
|
||||
.toMetaInfos(
|
||||
module,
|
||||
testFile,
|
||||
globalMetadataInfoHandler1 = globalMetadataInfoHandler,
|
||||
lightTreeEnabled,
|
||||
lightTreeComparingModeEnabled,
|
||||
forceRenderArguments,
|
||||
)
|
||||
FirSyntaxErrors.SYNTAX.on(
|
||||
sourceElement,
|
||||
PsiBuilderImpl.getErrorMessage(sourceElement.lighterASTNode) ?: "Syntax error",
|
||||
positioningStrategy = null
|
||||
).toMetaInfos(
|
||||
module,
|
||||
testFile,
|
||||
globalMetadataInfoHandler1 = globalMetadataInfoHandler,
|
||||
lightTreeEnabled,
|
||||
lightTreeComparingModeEnabled,
|
||||
forceRenderArguments,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user