Skip to content

Commit d2a9780

Browse files
committed
Expose logger statistics
1 parent b9dca93 commit d2a9780

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-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+
var errorCount: Int
26+
var warningCount: Int
27+
var infoCount: Int
28+
var loggingCount: Int
29+
var 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

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

36+
override var errorCount = 0
37+
override var warningCount = 0
38+
override var infoCount = 0
39+
override var loggingCount = 0
40+
override var exceptionCount = 0
41+
3642
private fun convertMessage(message: String, symbol: KSNode?): String =
3743
when (val location = symbol?.location) {
3844
is FileLocation -> "$PREFIX${location.filePath}:${location.lineNumber}: $message"
3945
is NonExistLocation, null -> "$PREFIX$message"
4046
}
4147

4248
override fun logging(message: String, symbol: KSNode?) {
49+
loggingCount++
4350
messageCollector.report(CompilerMessageSeverity.LOGGING, convertMessage(message, symbol))
4451
}
4552

4653
override fun info(message: String, symbol: KSNode?) {
54+
infoCount++
4755
messageCollector.report(CompilerMessageSeverity.INFO, convertMessage(message, symbol))
4856
}
4957

5058
override fun warn(message: String, symbol: KSNode?) {
59+
warningCount++
5160
messageCollector.report(CompilerMessageSeverity.WARNING, convertMessage(message, symbol))
5261
}
5362

5463
override fun error(message: String, symbol: KSNode?) {
64+
errorCount++
5565
messageCollector.report(CompilerMessageSeverity.ERROR, convertMessage(message, symbol))
5666
}
5767

5868
override fun exception(e: Throwable) {
69+
exceptionCount++
5970
val writer = StringWriter()
6071
e.printStackTrace(PrintWriter(writer))
6172
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)