Skip to content
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

Add support for context receivers and/or code block in FileSpec #1243

Closed
seriouslyhypersonic opened this issue Apr 27, 2022 · 2 comments
Closed

Comments

@seriouslyhypersonic
Copy link
Contributor

seriouslyhypersonic commented Apr 27, 2022

Hello,

I am writing a library that has multiple annotation processors and also uses KotlinPoet (thank's for the awesome work!). However, I am stuck on a very specific issue due to a new language feature which is essential for this library.

  1. Kotlin 1.6.20 added context receivers. I currently need to declare a property that has multiple implicit receivers. It seems this will require an update to KotlinPoet.
  2. These waiting could be avoided if there was a way to add a custom block at file spec level something like:
FileSpec
    .builder(packageName, fileName)
    .addCode("context(TypeA, TypeB)") // As a workaround 
    .addProperty(propertySpec)
    .build()

Is there a way to achieve this that I am not aware of?

Thanks in advance

@JakeWharton
Copy link
Member

Context receivers were tracked by #1232 and support is merged. Arbitrary code addition isn't an appealing feature here because we do not guarantee the order that you add items to a spec builder is the output order.

@seriouslyhypersonic
Copy link
Contributor Author

@JakeWharton Thanks for the feedback! Arbitrary code addition doesn't indeed sound appealing under those circumstances. I'll move on to a snapshot version until it's officially released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants