Is the Visitor pattern still considered the best a...
# ksp
z
Is the Visitor pattern still considered the best approach for processing multiple separate annotations to build one or more files?
d
My personal opinion is that people run into trouble using the visitor pattern (example here: https://kotlinlang.slack.com/archives/C013BA8EQSE/p1739901958510509?thread_ts=1739890854.058929&cid=C013BA8EQSE). I think a find-transform-write style pipeline works better. One of the best things you can do when you write a processor is checkout some of the code for the famous ones and base your implementation on those, at least at a very high level. Often these will forgo using the visitor pattern. https://github.com/square/moshi/blob/master/moshi-kotlin-codegen/src/main/java/com[…]up/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt https://github.com/evant/kotlin-inject/blob/main/kotlin-inject-compiler/ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/InjectProcessor.kt