[analysis api] fix ISE: No conversion was found for SYNTAX
^KT-51786 fixed
This commit is contained in:
+3
-3
@@ -15,8 +15,8 @@ import java.nio.file.Path
|
|||||||
object DiagnosticClassGenerator {
|
object DiagnosticClassGenerator {
|
||||||
fun generate(rootPath: Path, diagnosticList: DiagnosticList, packageName: String) {
|
fun generate(rootPath: Path, diagnosticList: DiagnosticList, packageName: String) {
|
||||||
val path = getGenerationPath(rootPath.toFile(), packageName)
|
val path = getGenerationPath(rootPath.toFile(), packageName)
|
||||||
KtDiagnosticClassRenderer.render(path.resolve("KtFirDiagnostics.kt"), diagnosticList, packageName)
|
KtDiagnosticClassRenderer.render(path.resolve("KtFirDiagnostics.kt"), diagnosticList, packageName, emptySet())
|
||||||
KtDiagnosticClassImplementationRenderer.render(path.resolve("KtFirDiagnosticsImpl.kt"), diagnosticList, packageName)
|
KtDiagnosticClassImplementationRenderer.render(path.resolve("KtFirDiagnosticsImpl.kt"), diagnosticList, packageName, emptySet())
|
||||||
FirDiagnosticToKtDiagnosticConverterRenderer.render(path.resolve("KtFirDataClassConverters.kt"), diagnosticList, packageName)
|
FirDiagnosticToKtDiagnosticConverterRenderer.render(path.resolve("KtFirDataClassConverters.kt"), diagnosticList, packageName, emptySet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -8,9 +8,12 @@ package org.jetbrains.kotlin.analysis.api.fir.generator
|
|||||||
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST
|
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST
|
||||||
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST
|
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import org.jetbrains.kotlin.analysis.api.fir.generator.DiagnosticClassGenerator.generate
|
||||||
|
import org.jetbrains.kotlin.fir.builder.SYNTAX_DIAGNOSTIC_LIST
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val rootPath = Paths.get("analysis/analysis-api-fir/src").toAbsolutePath()
|
val rootPath = Paths.get("analysis/analysis-api-fir/src").toAbsolutePath()
|
||||||
val packageName = "org.jetbrains.kotlin.analysis.api.fir.diagnostics"
|
val packageName = "org.jetbrains.kotlin.analysis.api.fir.diagnostics"
|
||||||
DiagnosticClassGenerator.generate(rootPath, DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST, packageName)
|
val diagnostics = DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST + SYNTAX_DIAGNOSTIC_LIST
|
||||||
|
generate(rootPath, diagnostics, packageName)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import java.io.File
|
|||||||
import kotlin.reflect.KType
|
import kotlin.reflect.KType
|
||||||
|
|
||||||
abstract class AbstractDiagnosticsDataClassRenderer : DiagnosticListRenderer() {
|
abstract class AbstractDiagnosticsDataClassRenderer : DiagnosticListRenderer() {
|
||||||
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String) {
|
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String, starImportsToAdd: Set<String>) {
|
||||||
val hlDiagnosticsList = HLDiagnosticConverter.convert(diagnosticList)
|
val hlDiagnosticsList = HLDiagnosticConverter.convert(diagnosticList)
|
||||||
file.writeToFileUsingSmartPrinterIfFileContentChanged { render(hlDiagnosticsList, packageName) }
|
file.writeToFileUsingSmartPrinterIfFileContentChanged { render(hlDiagnosticsList, packageName) }
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -4441,4 +4441,10 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirSyntaxErrors.SYNTAX) { firDiagnostic ->
|
||||||
|
SyntaxImpl(
|
||||||
|
firDiagnostic as KtPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -3088,4 +3088,8 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = JavaSamInterfaceConstructorReference::class
|
override val diagnosticClass get() = JavaSamInterfaceConstructorReference::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class Syntax : KtFirDiagnostic<PsiElement>() {
|
||||||
|
override val diagnosticClass get() = Syntax::class
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -3734,3 +3734,8 @@ internal class JavaSamInterfaceConstructorReferenceImpl(
|
|||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
) : KtFirDiagnostic.JavaSamInterfaceConstructorReference(), KtAbstractFirDiagnostic<PsiElement>
|
) : KtFirDiagnostic.JavaSamInterfaceConstructorReference(), KtAbstractFirDiagnostic<PsiElement>
|
||||||
|
|
||||||
|
internal class SyntaxImpl(
|
||||||
|
override val firDiagnostic: KtPsiDiagnostic,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.Syntax(), KtAbstractFirDiagnostic<PsiElement>
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import org.jetbrains.kotlin.fir.builder.SYNTAX_DIAGNOSTIC_LIST
|
||||||
|
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.ErrorListDiagnosticListRenderer
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val arguments = args.toList()
|
val arguments = args.toList()
|
||||||
@@ -93,9 +95,11 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val jvmGenerationPath = File(arguments.getOrElse(1) { "compiler/fir/checkers/checkers.jvm/gen" })
|
val jvmGenerationPath = File(arguments.getOrElse(1) { "compiler/fir/checkers/checkers.jvm/gen" })
|
||||||
|
val rawFirGenerationPath = File("compiler/fir/raw-fir/raw-fir.common/gen")
|
||||||
|
|
||||||
generateDiagnostics(generationPath, "$basePackage.diagnostics", DIAGNOSTICS_LIST)
|
generateDiagnostics(generationPath, "$basePackage.diagnostics", DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE))
|
||||||
generateDiagnostics(jvmGenerationPath, "$basePackage.diagnostics.jvm", JVM_DIAGNOSTICS_LIST)
|
generateDiagnostics(jvmGenerationPath, "$basePackage.diagnostics.jvm", JVM_DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE))
|
||||||
|
generateDiagnostics(rawFirGenerationPath, "org.jetbrains.kotlin.fir.builder", SYNTAX_DIAGNOSTIC_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.fir.builder
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||||
|
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticList
|
||||||
|
|
||||||
|
@Suppress("UNUSED_VARIABLE", "LocalVariableName", "ClassName", "unused")
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
|
object SYNTAX_DIAGNOSTIC_LIST : DiagnosticList("FirSyntaxErrors") {
|
||||||
|
val Syntax by object : DiagnosticGroup("Syntax") {
|
||||||
|
val SYNTAX by error<PsiElement>()
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -8,11 +8,12 @@ package org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model
|
|||||||
import org.jetbrains.kotlin.fir.checkers.generator.getGenerationPath
|
import org.jetbrains.kotlin.fir.checkers.generator.getGenerationPath
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun generateDiagnostics(rootPath: File, packageName: String, diagnosticList: DiagnosticList) {
|
fun generateDiagnostics(rootPath: File, packageName: String, diagnosticList: DiagnosticList, starImportsToAdd: Set<String>) {
|
||||||
val generationPath = getGenerationPath(rootPath, packageName)
|
val generationPath = getGenerationPath(rootPath, packageName)
|
||||||
ErrorListDiagnosticListRenderer.render(
|
ErrorListDiagnosticListRenderer.render(
|
||||||
generationPath.resolve("${diagnosticList.objectName}.kt"),
|
generationPath.resolve("${diagnosticList.objectName}.kt"),
|
||||||
diagnosticList,
|
diagnosticList,
|
||||||
packageName
|
packageName,
|
||||||
|
starImportsToAdd,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -8,5 +8,10 @@ package org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class DiagnosticListRenderer {
|
abstract class DiagnosticListRenderer {
|
||||||
abstract fun render(file: File, diagnosticList: DiagnosticList, packageName: String)
|
abstract fun render(
|
||||||
|
file: File,
|
||||||
|
diagnosticList: DiagnosticList,
|
||||||
|
packageName: String,
|
||||||
|
starImportsToAdd: Set<String>,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-14
@@ -18,20 +18,29 @@ import kotlin.reflect.KType
|
|||||||
import kotlin.reflect.KTypeProjection
|
import kotlin.reflect.KTypeProjection
|
||||||
|
|
||||||
object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() {
|
object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() {
|
||||||
private const val BASE_PACKAGE = "org.jetbrains.kotlin.fir.analysis.diagnostics"
|
const val BASE_PACKAGE = "org.jetbrains.kotlin.fir.analysis.diagnostics"
|
||||||
private const val DIAGNOSTICS_PACKAGE = "org.jetbrains.kotlin.diagnostics"
|
const val DIAGNOSTICS_PACKAGE = "org.jetbrains.kotlin.diagnostics"
|
||||||
|
|
||||||
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String) {
|
override fun render(
|
||||||
|
file: File,
|
||||||
|
diagnosticList: DiagnosticList,
|
||||||
|
packageName: String,
|
||||||
|
starImportsToAdd: Set<String>
|
||||||
|
) {
|
||||||
file.writeToFileUsingSmartPrinterIfFileContentChanged {
|
file.writeToFileUsingSmartPrinterIfFileContentChanged {
|
||||||
render(diagnosticList, packageName)
|
render(diagnosticList, packageName, starImportsToAdd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SmartPrinter.render(diagnosticList: DiagnosticList, packageName: String) {
|
private fun SmartPrinter.render(
|
||||||
|
diagnosticList: DiagnosticList,
|
||||||
|
packageName: String,
|
||||||
|
starImportsToAdd: Set<String>,
|
||||||
|
) {
|
||||||
printCopyright()
|
printCopyright()
|
||||||
println("package $packageName")
|
println("package $packageName")
|
||||||
println()
|
println()
|
||||||
collectAndPrintImports(diagnosticList, packageName)
|
collectAndPrintImports(diagnosticList, packageName, starImportsToAdd)
|
||||||
printGeneratedMessage()
|
printGeneratedMessage()
|
||||||
printErrorsObject(diagnosticList)
|
printErrorsObject(diagnosticList)
|
||||||
}
|
}
|
||||||
@@ -116,19 +125,22 @@ object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SmartPrinter.collectAndPrintImports(diagnosticList: DiagnosticList, packageName: String) {
|
private fun SmartPrinter.collectAndPrintImports(diagnosticList: DiagnosticList, packageName: String, starImportsToAdd: Set<String>) {
|
||||||
val imports = collectImports(diagnosticList, packageName)
|
val imports = collectImports(diagnosticList, packageName, starImportsToAdd)
|
||||||
printImports(imports)
|
printImports(imports)
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
private fun collectImports(diagnosticList: DiagnosticList, packageName: String): Collection<String> = buildSet {
|
private fun collectImports(
|
||||||
if (packageName != BASE_PACKAGE) {
|
diagnosticList: DiagnosticList,
|
||||||
add("$BASE_PACKAGE.*")
|
packageName: String,
|
||||||
}
|
starImportsToAdd: Set<String>
|
||||||
if (packageName != DIAGNOSTICS_PACKAGE) {
|
): Collection<String> = buildSet {
|
||||||
add("$DIAGNOSTICS_PACKAGE.*")
|
for (starImport in starImportsToAdd) {
|
||||||
|
if (starImport != packageName) {
|
||||||
|
add("$starImport.*")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
diagnosticList.allDiagnostics.forEach { diagnostic ->
|
diagnosticList.allDiagnostics.forEach { diagnostic ->
|
||||||
for (typeArgument in diagnostic.getAllTypeArguments()) {
|
for (typeArgument in diagnostic.getAllTypeArguments()) {
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
"main" { projectDefault() }
|
"main" {
|
||||||
|
projectDefault()
|
||||||
|
java.srcDir("gen")
|
||||||
|
}
|
||||||
"test" { none() }
|
"test" { none() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.fir.builder
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.diagnostics.*
|
||||||
|
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file was generated automatically
|
||||||
|
* DO NOT MODIFY IT MANUALLY
|
||||||
|
*/
|
||||||
|
|
||||||
|
object FirSyntaxErrors {
|
||||||
|
// Syntax
|
||||||
|
val SYNTAX by error0<PsiElement>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
RootDiagnosticRendererFactory.registerFactory(FirSyntaxErrorsDefaultMessages)
|
||||||
|
}
|
||||||
|
}
|
||||||
-13
@@ -5,24 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.builder
|
package org.jetbrains.kotlin.fir.builder
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||||
import org.jetbrains.kotlin.diagnostics.error0
|
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
|
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
|
||||||
|
|
||||||
object FirSyntaxErrors {
|
|
||||||
|
|
||||||
val SYNTAX by error0<PsiElement>()
|
|
||||||
|
|
||||||
init {
|
|
||||||
RootDiagnosticRendererFactory.registerFactory(FirSyntaxErrorsDefaultMessages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user