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
@NavigationNode(route = "screen_with_optional_arguments", args = arrayOf("id", "name"), | |
optionalArgs = arrayOf("age","nickName") | |
) | |
@Composable | |
fun ScreenWithOptionalArguments( | |
id: String, | |
name: String, | |
nickName: String?, | |
age: String? | |
) { |
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
NavHost(navController, startDestination = SimpleScreenGraphNode.route) { | |
composable(SimpleScreenGraphNode.route) { | |
SimpleScreen(navController = navController) | |
} | |
composable(ScreenWithArgumentGraphNode.route) {backStackEntry -> | |
val id = checkNotNull(backStackEntry.arguments?.getString(ScreenWithArgumentGraphNode.ARG_id)) | |
val name = checkNotNull(backStackEntry.arguments?.getString(ScreenWithArgumentGraphNode.ARG_name)) | |
ScreenWithArgument(navController = navController, id, name) |
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
private fun generateFunction(): FunSpec { | |
val funBuilder = FunSpec.builder("testFunction") | |
funBuilder.addParameter("something", String::class.asTypeName()) | |
val code = buildString { | |
append("val somethingelse = something {\n") | |
append("}\n") | |
append("return somethingElse") | |
} |
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
typeBuilder.addProperty( | |
PropertySpec.builder("rawRoute", String::class).initializer("%S", route).addModifiers( | |
KModifier.PUBLIC).build() | |
) |
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
private fun generateCode(symbol: KSFunctionDeclaration, route: String, args: ArrayList<String>, | |
optionalArgs: ArrayList<String>) { | |
val functionName = symbol.simpleName.asString() | |
val packageName = symbol.packageName.asString() | |
val fileName = "${functionName}GraphNode" | |
val typeBuilder = TypeSpec.objectBuilder(fileName) | |
// add properties and functions to typeBuilder |
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
class NodeProcessor( | |
private val logger: KSPLogger, | |
private val codeGenerator: CodeGenerator | |
): SymbolProcessor { | |
override fun process(resolver: Resolver): List<KSAnnotated> { | |
logger.info("NodeProcessor was invoked.") | |
val symbols = resolver.getSymbolsWithAnnotation(NavigationNode::class.qualifiedName!!) | |
val ret = mutableListOf<KSAnnotated>() | |
symbols.forEach { symbol -> | |
if (symbol is KSFunctionDeclaration && symbol.validate()) { |
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
class NodeProcessorProvider : SymbolProcessorProvider { | |
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { | |
return NodeProcessor( | |
logger = environment.logger, | |
codeGenerator = environment.codeGenerator | |
) | |
} | |
} |
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
public enum class AnnotationRetention { | |
/** Annotation isn't stored in binary output */ | |
SOURCE, | |
/** Annotation is stored in binary output, but invisible for reflection */ | |
BINARY, | |
/** Annotation is stored in binary output and visible for reflection (default retention) */ | |
RUNTIME | |
} |
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
[versions] | |
navigationCompose = "2.7.7" | |
symbolProcessing = "2.0.0-1.0.21" | |
kotlinpoet = "1.16.0" | |
[libraries] | |
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" } | |
symbol-processing = { group = "com.google.devtools.ksp" , name = "symbol-processing-api", version.ref = "symbolProcessing"} | |
kotlinpoet = { group = "com.squareup" , name = "kotlinpoet-ksp" , version.ref = "kotlinpoet"} |
NewerOlder