Skip to content

☂️ Idiomatic conversions #612

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

Open
1 of 5 tasks
Tracked by #1171
HosseinYousefi opened this issue Jun 21, 2023 · 3 comments
Open
1 of 5 tasks
Tracked by #1171

☂️ Idiomatic conversions #612

HosseinYousefi opened this issue Jun 21, 2023 · 3 comments

Comments

@HosseinYousefi
Copy link
Member

HosseinYousefi commented Jun 21, 2023

  • T getSomeValue() that returns a private value T someValue with the same type and doesn't get any arguments can be converted to a Dart's getter T get someValue – potentially only under a config flag
  • void setSomeValue(T t) that gets a value of type T and returns void can be converted into a Dart's setter set someValue(T t) – potentially only under a config flag
  • get methods that only get a single argument can be converted to operator [] – potentially only under a config flag
  • put methods that only get two arguments can also be converted to operator []=. We still probably want to generate put because put usually returns the value in Java while []= returns void – potentially only under a config flag
  • equals method can overload operator == and hashCode can override the hash code getter.

More conversions that can make the code more idiomatic to Dart? Feel free to suggest.

@mahesh-hegde
Copy link
Contributor

  • Boolean getters will be often named isField.

Overall this is similar to what most java serialization libraries do with getters / setters. (JSON, ORMs & DB drivers). They try to convert getters and setters into fields / columns.

I actually have a locally drafted proposal about better supporting such PoD (plain old data) types, but I think we are too early in the roadmap to discuss that feature.

@HosseinYousefi HosseinYousefi changed the title ☔ Idiomatic conversions ☂️ Idiomatic conversions Jul 3, 2023
@HosseinYousefi HosseinYousefi transferred this issue from dart-archive/jnigen Nov 17, 2023
@mit-mit
Copy link
Member

mit-mit commented Jan 25, 2024

Big +1 for doing the first two!

That would be similar to what Kotlin to Java interop does: https://kotlinlang.org/docs/java-interop.html#getters-and-setters

@HosseinYousefi
Copy link
Member Author

Big +1 for doing the first two!

That would be similar to what Kotlin to Java interop does: https://kotlinlang.org/docs/java-interop.html#getters-and-setters

Kotlin is doing some other conversions for operators as well but the documentation is somewhat vague about it: https://kotlinlang.org/docs/java-interop.html#operators

For example list[i] turns into list.get(i), and so on... (Similar to the other proposed conversions in this issue).

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

No branches or pull requests

3 participants