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

Allow generating where clauses for complex type constraints #1494

Open
metarag opened this issue Mar 14, 2023 · 4 comments
Open

Allow generating where clauses for complex type constraints #1494

metarag opened this issue Mar 14, 2023 · 4 comments

Comments

@metarag
Copy link

metarag commented Mar 14, 2023

Is your feature request related to a problem? Please describe.
Kotlin supports where clauses which can make complex type-constraints more readable. For example,

class GenericPerson<Self, Builder> where
Self : GenericPerson<Self, Builder>,
Builder: GenericPersonBuilder<Builder, Self>

class GenericPersonBuilder<Self, Built> where
Self : GenericPersonBuilder<Self, Built>,
Built : GenericPerson<Built, Self>

Describe the solution you'd like
It would be nice if KotlinPoet allowed generating APIs like that. I'm not sure what the best way to go about this is.

Perhaps, TypeSpec.classBuilder("...").useWhereClauseForTypeConstraints(true).build()?

Describe alternatives you've considered
I'm just using the existing APIs to declare the type constraints inline for now.

Additional context
N/A

@JakeWharton
Copy link
Member

In general we are opposed to functionality which lets the user change the formatting of the output. I would be much more supportive of a simple rule that applies globally. We do similar things for when to wrap function parameters onto multiple lines, for example.

@metarag
Copy link
Author

metarag commented Mar 14, 2023 via email

@JakeWharton
Copy link
Member

I was thinking:

  • Has any type parameters with more than one bound, or
  • Has two+ type parameters any of which has a bound

@metarag
Copy link
Author

metarag commented Mar 14, 2023

Yep. That looks better :)

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

No branches or pull requests

2 participants