Skip to content

Commit

Permalink
Merge pull request #56 from google/yaraki/processor-issue
Browse files Browse the repository at this point in the history
Support incremental KSP build
  • Loading branch information
yaraki authored Feb 15, 2024
2 parents 6874cb5 + 498256e commit f2ca3c0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ captures
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/deploymentTargetDropDown.xml
.idea/deploymentTargetSelector.xml
.idea/misc.xml
.idea/androidTestResultsUserPreferences.xml
.idea/appInsightsSettings.xml
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app-catalog/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dependencies {
implementation libs.hilt.android
ksp libs.hilt.compiler

// Include all available samples dynamically importend in settings.gradle
// Include all available samples dynamically imported in settings.gradle
gradle.ext.samples.each {
implementation project("$it")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,26 @@ class SampleProcessor(
private val visited = mutableListOf<KSAnnotated>()

override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(Sample::class.java.name)
.filter {
val isValid = it.validate { first, second ->
val (validSymbols, invalidSymbols) = resolver
.getSymbolsWithAnnotation(Sample::class.java.name)
.partition { symbol ->
val isValid = symbol.validate { data, declaration ->
// Skip checking fields of a class since its causing issues with viewBinding
!(first is KSClassDeclaration && second is KSPropertyDeclaration)
!(data is KSClassDeclaration && declaration is KSPropertyDeclaration)
}
if (!isValid) {
logger.warn("Annotated sample is not valid ${it.containingFile?.filePath}")
logger.warn("Annotated sample is not valid ${symbol.containingFile?.filePath}")
}
(it is KSFunctionDeclaration || it is KSClassDeclaration) &&
(symbol is KSFunctionDeclaration || symbol is KSClassDeclaration) &&
isValid &&
it !in visited &&
!it.isAnnotationPresent(Deprecated::class)
symbol !in visited &&
!symbol.isAnnotationPresent(Deprecated::class)
}
for (symbol in symbols) {
for (symbol in validSymbols) {
symbol.accept(visitor, Unit)
}
visited.addAll(symbols)
visited.addAll(validSymbols)

return symbols.toList()
return invalidSymbols
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ internal class SampleVisitor(
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
val target = classDeclaration.getAllSuperTypes().firstNotNullOfOrNull {
val className = it.declaration.qualifiedName?.asString().orEmpty()
logger.warn(className)
when (className) {
"android.app.Activity" -> {
"targetActivity<${classDeclaration.toFullPath()}>()"
Expand Down Expand Up @@ -83,6 +82,7 @@ internal class SampleVisitor(
val file = codeGenerator.createNewFile(
dependencies = Dependencies(
aggregating = true,
functionSample.containingFile!!
),
packageName = packageName,
fileName = "${sampleFile}Module"
Expand Down

0 comments on commit f2ca3c0

Please sign in to comment.