Skip to content

Commit

Permalink
move constants in KotlinSymbolProcessingExtension to companion
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Feb 24, 2021
1 parent f73e28b commit 43af71c
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions,
lateinit var cleanFilenames: Set<String>
lateinit var codeGenerator: CodeGeneratorImpl
var rounds = 0
private val multipleRoundThreshold = 100
companion object {
private const val KSP_PACKAGE_NAME = "com.google.devtools.ksp"
private const val MULTI_ROUND_THRESHOLD = 100
}

override fun doAnalysis(
project: Project,
Expand All @@ -92,7 +95,7 @@ abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions,
componentProvider: ComponentProvider
): AnalysisResult? {
rounds++
if (rounds > multipleRoundThreshold) {
if (rounds > MULTI_ROUND_THRESHOLD) {
logger.warn("Current processing rounds exceeds 100, check processors for potential infinite rounds")
}
val psiManager = PsiManager.getInstance(project)
Expand Down Expand Up @@ -139,10 +142,13 @@ abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions,
}
initialized = true
}
processors.forEach {
processors.forEach processing@{
handleException {
deferredSymbols[it] = it.process(resolver)
}
if (logger.hasError()) {
return@processing
}
if (!deferredSymbols.containsKey(it) || deferredSymbols[it]!!.isEmpty()) {
deferredSymbols.remove(it)
}
Expand Down Expand Up @@ -175,7 +181,9 @@ abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions,
if (deferredSymbols.isNotEmpty()) {
deferredSymbols.map { entry -> logger.warn("Unable to process:${entry.key::class.qualifiedName}: ${entry.value.map { it.toString() }.joinToString(";")}") }
}
incrementalContext.updateCachesAndOutputs(dirtyFiles, codeGenerator.outputs, codeGenerator.sourceToOutputs)
if (!logger.hasError()) {
incrementalContext.updateCachesAndOutputs(dirtyFiles, codeGenerator.outputs, codeGenerator.sourceToOutputs)
}
}
}
if (finished) {
Expand Down Expand Up @@ -221,7 +229,7 @@ abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions,
call()
} catch (e: Exception) {
// Throws KSP exceptions
if (e.stackTrace.first().className.startsWith("com.google.devtools.ksp")) {
if (e.stackTrace.first().className.startsWith(KSP_PACKAGE_NAME)) {
throw e
} else {
val sw = StringWriter()
Expand Down

0 comments on commit 43af71c

Please sign in to comment.