-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for @excludes in Glide's KSP processor.
- Loading branch information
Showing
5 changed files
with
421 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
annotation/ksp/src/main/kotlin/com/bumptech/glide/annotation/ksp/ModuleParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.bumptech.glide.annotation.ksp | ||
|
||
import com.google.devtools.ksp.symbol.KSClassDeclaration | ||
import com.google.devtools.ksp.symbol.KSNode | ||
|
||
object ModuleParser { | ||
|
||
internal data class GlideModules( | ||
val appModules: List<KSClassDeclaration>, | ||
val libraryModules: List<KSClassDeclaration>, | ||
) | ||
|
||
internal fun extractGlideModules(annotatedModules: List<KSNode>): GlideModules { | ||
val appAndLibraryModuleNames = listOf(APP_MODULE_QUALIFIED_NAME, LIBRARY_MODULE_QUALIFIED_NAME) | ||
val modulesBySuperType: Map<String?, List<KSClassDeclaration>> = | ||
annotatedModules.filterIsInstance<KSClassDeclaration>().groupBy { classDeclaration -> | ||
appAndLibraryModuleNames.singleOrNull { classDeclaration.hasSuperType(it) } | ||
} | ||
|
||
val (appModules, libraryModules) = | ||
appAndLibraryModuleNames.map { modulesBySuperType[it] ?: emptyList() } | ||
return GlideModules(appModules, libraryModules) | ||
} | ||
|
||
private fun KSClassDeclaration.hasSuperType(superTypeQualifiedName: String) = | ||
superTypes | ||
.map { superType -> superType.resolve().declaration.qualifiedName!!.asString() } | ||
.contains(superTypeQualifiedName) | ||
|
||
private const val APP_MODULE_QUALIFIED_NAME = "com.bumptech.glide.module.AppGlideModule" | ||
private const val LIBRARY_MODULE_QUALIFIED_NAME = "com.bumptech.glide.module.LibraryGlideModule" | ||
} |
Oops, something went wrong.