Skip to content

Idiomatic setters/getters #13

@MattSturgeon

Description

@MattSturgeon

Kotlin and Groovy both have some built-in coersion of getters and setters into plain object properties.

In Groovy, a getters and setters form what we call a "property", and offers a shortcut notation for accessing and setting such properties.
~Groovy Style guide: Getters and Setters

Methods that follow the Java conventions for getters and setters (no-argument methods with names starting with get and single-argument methods with names starting with set) are represented as properties in Kotlin
~Calling Java from Kotlin

I believe kotlin's implementation may be incompatible with lombok's default is prefix for boolean methods.

If this is the only issue, it may be fixed by setting lombok.getter.noIsPrefix = true in a lombok.config file.

You can create lombok.config files in any directory and put configuration directives in it. These apply to all source files in this directory and all child directories.
~Configure lombok features


This would need some experimentation, I've noticed when playing around in kotlin codebases that some classes get synthetic properties while others don't.

Examples

E.g. GHRepository.getFullName() works:

image

So does GitHub:

image

While some stuff on File works:

image

And other stuff just doesn't:

image

Maybe this is because setReadOnly() isn't actually setting a field, instead it's probably doing filesystem IO.


I believe this would be best as a breaking change, since it'd be a pain to introduce idiomatic setters while still maintaining the existing API. That said, it should be possible and may not be too bad if you think it's worth it...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions