Skip to content

Commit 23b1c1c

Browse files
committed
Expose logger statistics
1 parent 34a3e1d commit 23b1c1c

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

api/src/main/kotlin/com/google/devtools/ksp/processing/KSPLogger.kt

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import com.google.devtools.ksp.symbol.KSNode
2222

2323
interface KSPLogger {
2424

25+
val errorCount: Int
26+
val warningCount: Int
27+
val infoCount: Int
28+
val loggingCount: Int
29+
val exceptionCount: Int
30+
2531
fun logging(message: String, symbol: KSNode? = null)
2632
fun info(message: String, symbol: KSNode? = null)
2733
fun warn(message: String, symbol: KSNode? = null)

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import com.google.devtools.ksp.symbol.*
3737
import com.google.devtools.ksp.symbol.impl.KSObjectCacheManager
3838
import com.google.devtools.ksp.symbol.impl.java.KSFileJavaImpl
3939
import com.google.devtools.ksp.symbol.impl.kotlin.KSFileImpl
40-
import org.jetbrains.kotlin.incremental.isJavaFile
41-
import org.jetbrains.kotlin.incremental.isKotlinFile
4240
import org.jetbrains.kotlin.psi.KtFile
4341
import org.jetbrains.kotlin.resolve.BindingContext
4442
import org.jetbrains.kotlin.resolve.BindingTrace

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/MessageCollectorBasedKSPLogger.kt

+20
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,49 @@ class MessageCollectorBasedKSPLogger(private val messageCollector: MessageCollec
3333
const val PREFIX = "[ksp] "
3434
}
3535

36+
override var errorCount = 0
37+
private set
38+
39+
override var warningCount = 0
40+
private set
41+
42+
override var infoCount = 0
43+
private set
44+
45+
override var loggingCount = 0
46+
private set
47+
48+
override var exceptionCount = 0
49+
private set
50+
3651
private fun convertMessage(message: String, symbol: KSNode?): String =
3752
when (val location = symbol?.location) {
3853
is FileLocation -> "$PREFIX${location.filePath}:${location.lineNumber}: $message"
3954
is NonExistLocation, null -> "$PREFIX$message"
4055
}
4156

4257
override fun logging(message: String, symbol: KSNode?) {
58+
loggingCount++
4359
messageCollector.report(CompilerMessageSeverity.LOGGING, convertMessage(message, symbol))
4460
}
4561

4662
override fun info(message: String, symbol: KSNode?) {
63+
infoCount++
4764
messageCollector.report(CompilerMessageSeverity.INFO, convertMessage(message, symbol))
4865
}
4966

5067
override fun warn(message: String, symbol: KSNode?) {
68+
warningCount++
5169
messageCollector.report(CompilerMessageSeverity.WARNING, convertMessage(message, symbol))
5270
}
5371

5472
override fun error(message: String, symbol: KSNode?) {
73+
errorCount++
5574
messageCollector.report(CompilerMessageSeverity.ERROR, convertMessage(message, symbol))
5675
}
5776

5877
override fun exception(e: Throwable) {
78+
exceptionCount++
5979
val writer = StringWriter()
6080
e.printStackTrace(PrintWriter(writer))
6181
messageCollector.report(CompilerMessageSeverity.EXCEPTION, writer.toString())

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/ErrorTypeProcessor.kt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ErrorTypeProcessor : AbstractTestProcessor() {
3232
}
3333

3434
override fun process(resolver: Resolver) {
35+
3536
val classC = resolver.getClassDeclarationByName(resolver.getKSNameFromString("C"))!!
3637
val errorAtTop = classC.declarations.single { it.simpleName.asString() == "errorAtTop" } as KSPropertyDeclaration
3738
val errorInComponent = classC.declarations.single { it.simpleName.asString() == "errorInComponent" } as KSPropertyDeclaration

0 commit comments

Comments
 (0)