-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support assisted injections + consolidate and clean up APIs #236
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have quite a few questions around CircuitSymbolProcessorProvider
but i'll ask them in Slack instead.
codeBlock = | ||
when (factoryType) { | ||
FactoryType.PRESENTER -> | ||
CodeBlock.of( | ||
"%M·{·%M()·}", | ||
"%M·{·%M(%L)·}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that %L
is assistedParams and that comes from fd
which is a KSFunctionDeclarationbut what is that? And what is
fd` short hand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fd
is just shorter to write than functionDeclaration
. A KSFunctionDeclaration
is KSP's modeling of a kotlin function. A %L
template is for literals in kotlinpoet: https://square.github.io/kotlinpoet/#l-for-literals. assistedParams
is a CodeBlock
of any assisted parameters we're passing on to the factory/constructor/function like (screen = screen, navigator = navigator
)
@Suppress("unused") public annotation class CircuitInject<out Screen> | ||
|
||
public annotation class CircuitScope(val scope: KClass<*>) | ||
public annotation class CircuitInject( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the kdoc for this now since this PR puts this in a pretty complete state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override fun create(screen: Screen, circuitConfig: CircuitConfig): ScreenUi? { | ||
if (screen is HomeScreen) { | ||
return ScreenUi(homeUi()) | ||
@CircuitInject(screen = HomeScreen::class, scope = AppScope::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:chefs-kiss:
@@ -103,21 +128,27 @@ private class CircuitSymbolProcessor( | |||
return emptyList() | |||
} | |||
|
|||
@OptIn(KspExperimental::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have the file opt in at the top do we need this one here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it as it wasn't necessary in the file level 9f36407
extracted the annotations to a separate project so we keep |
} | ||
|
||
private inline fun <reified T> Resolver.loadOptionalKSType(): KSType? { | ||
return getClassDeclarationByName(getKSNameFromString(T::class.java.canonicalName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there's a lint warning here about T::class.java.canonicalName
being nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird..I'm still seeing it. canonicalName
is an unannotated java method that returns a String, which supports the lint warning I'm seeing about expecting String but found String?
circuit-codegen/src/main/kotlin/com/slack/circuit/codegen/CircuitSymbolProcessorProvider.kt
Show resolved
Hide resolved
circuit-codegen/src/main/kotlin/com/slack/circuit/codegen/CircuitSymbolProcessorProvider.kt
Show resolved
Hide resolved
circuit-codegen/src/main/kotlin/com/slack/circuit/codegen/CircuitSymbolProcessorProvider.kt
Outdated
Show resolved
Hide resolved
* [Ui.Factory] classes generated for them. | ||
* | ||
* **Presenter** | ||
* ```kotlin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is ```kotlin for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as it is in github markdown!
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
public annotation class CircuitInject( | ||
val screen: KClass<out Screen>, | ||
val scope: KClass<*>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't the scope just be of type KClass.
What is the purpose of the generic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't write raw types in kotlin like you can in Java. For example, in Java it's legal to write List foo = ...
, but in Kotlin you must write the generic, even if it's just a star. val foo: List = ...
isn't legal syntax
samples/star/src/main/kotlin/com/slack/circuit/star/petdetail/PetDetail.kt
Outdated
Show resolved
Hide resolved
threshold: 120 | ||
NestedBlockDepth: | ||
threshold: 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matches our internal config, detekt's defaults are a bit iffy. Especially with ktfmt
circuit-codegen/src/main/kotlin/com/slack/circuit/codegen/CircuitSymbolProcessorProvider.kt
Outdated
Show resolved
Hide resolved
...t-codegen-annotations/src/main/kotlin/com/slack/circuit/codegen/annotations/CircuitInject.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggested change related to presenter package, and that lint warning regarding use of canonicalName. Looks good otherwise
…uitSymbolProcessorProvider.kt
…codegen/annotations/CircuitInject.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay for code gen!
Followup from #235 and more for #13
This adds support for assisted injections for common types (screen, navigator, config) and consolidates the Anvil APIs back into the same artifact for now as it really didn't end up being very useful to define it separately.
Final bit was moving remaining star sample factories to this, result was quite nice