Skip to content

☂️ Idiomatic conversions #612

Closed

Description

@HosseinYousefi
  • 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.

Activity

  1. mahesh-hegde commented on Jun 21, 2023

    @mahesh-hegde
    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.

  2. changed the title [-]☔ Idiomatic conversions[/-] [+]☂️ Idiomatic conversions[/+] on Jul 3, 2023
  3. mit-mit commented on Jan 25, 2024

    @mit-mit
    Member

    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

  4. HosseinYousefi commented on Jan 25, 2024

    @HosseinYousefi
    ContributorAuthor

    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).

  5. moved this from Backlog to Todo in JNIgen trackeron May 22, 2024
  6. modified the milestones: JNI / JNIgen 2025 Q1, on Apr 8, 2025
  7. removed this from the milestone on Oct 10, 2025
  8. liamappelbe commented on Mar 12, 2026

    @liamappelbe
    Contributor

    Now that we've split the collections into an inner layer that's just the raw JNIgen output, and a hand written adapter layer that looks more Darty, there's less incentive to convert [] and []=, since the adapter layer is the one that has these operators. So I'll just do the getter/setter transform for now.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions