[FIR] Add implicit type counter to html dump

This commit is contained in:
Dmitriy Novozhilov
2019-12-04 15:14:19 +03:00
parent e58711cde3
commit 088a949403
3 changed files with 33 additions and 7 deletions
@@ -82,6 +82,12 @@ body.dark {
.dark .error-counter { .dark .error-counter {
color: #ff1010; color: #ff1010;
padding-left: 15px;
}
.dark .implicit-counter {
color: aqua;
padding-left: 15px;
} }
.dark .diagnostic-hover { .dark .diagnostic-hover {
@@ -72,6 +72,12 @@
.white .error-counter { .white .error-counter {
color: #f00; color: #f00;
padding-left: 15px;
}
.white .implicit-counter {
color: aqua;
padding-left: 15px;
} }
.white .diagnostic-hover { .white .diagnostic-hover {
@@ -79,6 +79,7 @@ private class PackageInfo(val fqName: FqName, val moduleInfo: ModuleInfo) {
it.mkdirs() it.mkdirs()
} }
val errors = mutableMapOf<String, Int>().withDefault { 0 } val errors = mutableMapOf<String, Int>().withDefault { 0 }
val implicits = mutableMapOf<String, Int>().withDefault { 0 }
} }
private class ModuleInfo(val name: String, outputRoot: File) { private class ModuleInfo(val name: String, outputRoot: File) {
@@ -89,6 +90,9 @@ private class ModuleInfo(val name: String, outputRoot: File) {
val errors: Map<FqName, Int> by lazy { val errors: Map<FqName, Int> by lazy {
packages.mapValues { (_, packageInfo) -> packageInfo.errors.values.sum() }.withDefault { 0 } packages.mapValues { (_, packageInfo) -> packageInfo.errors.values.sum() }.withDefault { 0 }
} }
val implicits: Map<FqName, Int> by lazy {
packages.mapValues { (_, packageInfo) -> packageInfo.implicits.values.sum() }.withDefault { 0 }
}
} }
private class SupplementaryGenerator(val outputRoot: File) { private class SupplementaryGenerator(val outputRoot: File) {
@@ -118,7 +122,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
) { ) {
+packageInfo.fqName.asString() +packageInfo.fqName.asString()
} }
addErrors(moduleInfo.errors.getValue(packageInfo.fqName)) addErrors(moduleInfo.errors.getValue(packageInfo.fqName), moduleInfo.implicits.getValue(packageInfo.fqName))
} }
} }
} }
@@ -126,10 +130,13 @@ private class SupplementaryGenerator(val outputRoot: File) {
} }
} }
fun LI.addErrors(errors: Int) { fun LI.addErrors(errors: Int, implicits: Int) {
if (errors > 0) { if (errors > 0) {
span(classes = "error-counter") { +(errors.toString()) } span(classes = "error-counter") { +(errors.toString()) }
} }
if (implicits > 0) {
span(classes = "implicit-counter") { +(implicits.toString()) }
}
} }
fun linkToIndex(moduleInfo: ModuleInfo, from: File): String { fun linkToIndex(moduleInfo: ModuleInfo, from: File): String {
@@ -167,7 +174,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
for (file in packageInfo.contents) { for (file in packageInfo.contents) {
li { li {
a(href = "./$file.fir.html", classes = "container-ref") { +file } a(href = "./$file.fir.html", classes = "container-ref") { +file }
addErrors(packageInfo.errors.getValue(file)) addErrors(packageInfo.errors.getValue(file), packageInfo.implicits.getValue(file))
} }
} }
} }
@@ -190,7 +197,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
for (module in modules) { for (module in modules) {
li { li {
a(href = linkToIndex(module, outputRoot), classes = "container-ref") { +module.name } a(href = linkToIndex(module, outputRoot), classes = "container-ref") { +module.name }
addErrors(module.errors.values.sum()) addErrors(module.errors.values.sum(), module.implicits.values.sum())
} }
} }
} }
@@ -296,6 +303,7 @@ class MultiModuleHtmlFirDump(private val outputRoot: File) {
dumpOutput.writeText(builder.toString()) dumpOutput.writeText(builder.toString())
packageForFile(file).apply { packageForFile(file).apply {
errors[file.name] = dumper.errors errors[file.name] = dumper.errors
implicits[file.name] = dumper.implicits
} }
} }
@@ -395,12 +403,15 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
var errors: Int = 0 var errors: Int = 0
private set private set
fun generate(element: FirFile, builder: StringBuilder): Int { var implicits: Int = 0
private set
fun generate(element: FirFile, builder: StringBuilder) {
errors = 0 errors = 0
implicits = 0
builder.appendHTML().html { builder.appendHTML().html {
generate(element) generate(element)
} }
return errors
} }
private fun FlowContent.keyword(text: String) { private fun FlowContent.keyword(text: String) {
@@ -794,7 +805,10 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
when (typeRef) { when (typeRef) {
is FirErrorTypeRef -> error { +typeRef.diagnostic.reason } is FirErrorTypeRef -> error { +typeRef.diagnostic.reason }
is FirResolvedTypeRef -> generate(typeRef.type) is FirResolvedTypeRef -> generate(typeRef.type)
is FirImplicitTypeRef -> unresolved { keyword("<implicit>") } is FirImplicitTypeRef -> unresolved {
implicits++
keyword("<implicit>")
}
is FirUserTypeRef -> unresolved { is FirUserTypeRef -> unresolved {
generateList(typeRef.qualifier, separator = ".") { generateList(typeRef.qualifier, separator = ".") {
simpleName(it.name) simpleName(it.name)