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