[FIR-IDE] Avoid clashes between diagnostic and it's parameter with same short names
This commit is contained in:
+12
-2
@@ -9,10 +9,14 @@ import org.jetbrains.kotlin.util.SmartPrinter
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
|
||||
internal fun SmartPrinter.printTypeWithShortNames(type: KType) {
|
||||
internal fun SmartPrinter.printTypeWithShortNames(type: KType, shouldRenderFqName: (KType) -> Boolean = { false }) {
|
||||
fun typeConversion(type: KType): String {
|
||||
val nullableSuffix = if (type.isMarkedNullable) "?" else ""
|
||||
val simpleName = (type.classifier as KClass<*>).simpleName!!
|
||||
val simpleName = if (shouldRenderFqName(type)) {
|
||||
type.qualifiedName
|
||||
} else {
|
||||
type.simpleName
|
||||
}
|
||||
return if (type.arguments.isEmpty()) simpleName + nullableSuffix
|
||||
else simpleName + type.arguments.joinToString(separator = ", ", prefix = "<", postfix = ">") {
|
||||
when (val typeArgument = it.type) {
|
||||
@@ -23,3 +27,9 @@ internal fun SmartPrinter.printTypeWithShortNames(type: KType) {
|
||||
}
|
||||
print(typeConversion(type))
|
||||
}
|
||||
|
||||
val KType.simpleName: String
|
||||
get() = (classifier as KClass<*>).simpleName!!
|
||||
|
||||
val KType.qualifiedName: String
|
||||
get() = (classifier as KClass<*>).qualifiedName!!
|
||||
|
||||
+6
@@ -15,8 +15,10 @@ import org.jetbrains.kotlin.fir.tree.generator.util.writeToFileUsingSmartPrinter
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.generator.HLDiagnosticConverter
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.generator.HLDiagnosticList
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.generator.HLDiagnosticParameter
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.generator.simpleName
|
||||
import org.jetbrains.kotlin.util.SmartPrinter
|
||||
import java.io.File
|
||||
import kotlin.reflect.KType
|
||||
|
||||
abstract class AbstractDiagnosticsDataClassRenderer : DiagnosticListRenderer() {
|
||||
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String) {
|
||||
@@ -49,6 +51,10 @@ abstract class AbstractDiagnosticsDataClassRenderer : DiagnosticListRenderer() {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun HLDiagnosticList.containsClashingBySimpleNameType(type: KType): Boolean {
|
||||
return diagnostics.any { it.className == type.simpleName }
|
||||
}
|
||||
|
||||
protected abstract fun collectImportsForDiagnosticParameter(diagnosticParameter: HLDiagnosticParameter): Collection<String>
|
||||
|
||||
protected abstract fun SmartPrinter.render(diagnosticList: HLDiagnosticList, packageName: String)
|
||||
|
||||
+9
-7
@@ -22,15 +22,15 @@ object KtDiagnosticClassImplementationRenderer : AbstractDiagnosticsDataClassRen
|
||||
|
||||
private fun SmartPrinter.printDiagnosticClassesImplementation(diagnosticList: HLDiagnosticList) {
|
||||
for (diagnostic in diagnosticList.diagnostics) {
|
||||
printDiagnosticImplementation(diagnostic)
|
||||
printDiagnosticImplementation(diagnostic, diagnosticList)
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
private fun SmartPrinter.printDiagnosticImplementation(diagnostic: HLDiagnostic) {
|
||||
private fun SmartPrinter.printDiagnosticImplementation(diagnostic: HLDiagnostic, diagnosticList: HLDiagnosticList) {
|
||||
println("internal class ${diagnostic.implClassName}(")
|
||||
withIndent {
|
||||
printParameters(diagnostic)
|
||||
printParameters(diagnostic, diagnosticList)
|
||||
}
|
||||
print(") : KtFirDiagnostic.${diagnostic.className}(), KtAbstractFirDiagnostic<")
|
||||
printTypeWithShortNames(diagnostic.original.psiType)
|
||||
@@ -40,17 +40,19 @@ object KtDiagnosticClassImplementationRenderer : AbstractDiagnosticsDataClassRen
|
||||
}
|
||||
}
|
||||
|
||||
private fun SmartPrinter.printParameters(diagnostic: HLDiagnostic) {
|
||||
private fun SmartPrinter.printParameters(diagnostic: HLDiagnostic, diagnosticList: HLDiagnosticList) {
|
||||
for (parameter in diagnostic.parameters) {
|
||||
printParameter(parameter)
|
||||
printParameter(parameter, diagnosticList)
|
||||
}
|
||||
println("firDiagnostic: FirPsiDiagnostic,")
|
||||
println("override val token: ValidityToken,")
|
||||
}
|
||||
|
||||
private fun SmartPrinter.printParameter(parameter: HLDiagnosticParameter) {
|
||||
private fun SmartPrinter.printParameter(parameter: HLDiagnosticParameter, diagnosticList: HLDiagnosticList) {
|
||||
print("override val ${parameter.name}: ")
|
||||
printTypeWithShortNames(parameter.type)
|
||||
printTypeWithShortNames(parameter.type) {
|
||||
diagnosticList.containsClashingBySimpleNameType(it)
|
||||
}
|
||||
println(",")
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -20,26 +20,28 @@ object KtDiagnosticClassRenderer : AbstractDiagnosticsDataClassRenderer() {
|
||||
private fun SmartPrinter.printDiagnosticClasses(diagnosticList: HLDiagnosticList) {
|
||||
inBracketsWithIndent("sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI>") {
|
||||
for (diagnostic in diagnosticList.diagnostics) {
|
||||
printDiagnosticClass(diagnostic)
|
||||
printDiagnosticClass(diagnostic, diagnosticList)
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun SmartPrinter.printDiagnosticClass(diagnostic: HLDiagnostic) {
|
||||
private fun SmartPrinter.printDiagnosticClass(diagnostic: HLDiagnostic, diagnosticList: HLDiagnosticList) {
|
||||
print("abstract class ${diagnostic.className} : KtFirDiagnostic<")
|
||||
printTypeWithShortNames(diagnostic.original.psiType)
|
||||
print(">()")
|
||||
inBracketsWithIndent {
|
||||
println("override val diagnosticClass get() = ${diagnostic.className}::class")
|
||||
printDiagnosticParameters(diagnostic)
|
||||
printDiagnosticParameters(diagnostic, diagnosticList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun SmartPrinter.printDiagnosticParameters(diagnostic: HLDiagnostic) {
|
||||
private fun SmartPrinter.printDiagnosticParameters(diagnostic: HLDiagnostic, diagnosticList: HLDiagnosticList) {
|
||||
diagnostic.parameters.forEach { parameter ->
|
||||
print("abstract val ${parameter.name}: ")
|
||||
printTypeWithShortNames(parameter.type)
|
||||
printTypeWithShortNames(parameter.type) { type ->
|
||||
diagnosticList.containsClashingBySimpleNameType(type)
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -552,7 +552,7 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract class OverrideDeprecation : KtFirDiagnostic<KtNamedDeclaration>() {
|
||||
override val diagnosticClass get() = OverrideDeprecation::class
|
||||
abstract val overridenSymbol: KtSymbol
|
||||
abstract val deprecationInfo: Deprecation
|
||||
abstract val deprecationInfo: org.jetbrains.kotlin.resolve.deprecation.Deprecation
|
||||
}
|
||||
|
||||
abstract class AnnotationOnSuperclassError : KtFirDiagnostic<KtAnnotationEntry>() {
|
||||
|
||||
+1
-1
@@ -879,7 +879,7 @@ internal class DeprecatedSinceKotlinOutsideKotlinSubpackageImpl(
|
||||
|
||||
internal class OverrideDeprecationImpl(
|
||||
override val overridenSymbol: KtSymbol,
|
||||
override val deprecationInfo: Deprecation,
|
||||
override val deprecationInfo: org.jetbrains.kotlin.resolve.deprecation.Deprecation,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.OverrideDeprecation(), KtAbstractFirDiagnostic<KtNamedDeclaration> {
|
||||
|
||||
Reference in New Issue
Block a user