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

generate hasFOO() for boolean fields named 'hasFOO' instead of 'isHasFOO' #77

Closed
lombokissues opened this Issue Jul 14, 2015 · 9 comments

Comments

Projects
None yet
6 participants
@lombokissues
Collaborator

lombokissues commented Jul 14, 2015

Migrated from Google Code (issue 4)

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 reinierz   🕗 Jul 24, 2009 at 04:17 UTC

What steps will reproduce the problem?

  1. Create a class with a field named 'hasX', typed 'boolean'.
  2. Put a @ Data annotation on it.
  3. Get annoyed by the 'isHasX()' name. 'hasX()' is most likely far more appropriate.

Fix: If boolean field and the field name starts with 'has', use the field name as method name.

Collaborator

lombokissues commented Jul 14, 2015

👤 reinierz   🕗 Jul 24, 2009 at 04:17 UTC

What steps will reproduce the problem?

  1. Create a class with a field named 'hasX', typed 'boolean'.
  2. Put a @ Data annotation on it.
  3. Get annoyed by the 'isHasX()' name. 'hasX()' is most likely far more appropriate.

Fix: If boolean field and the field name starts with 'has', use the field name as method name.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 r.spilker   🕗 Jul 24, 2009 at 11:04 UTC

Also, we might want to check if any of the is/has/get methods exists befor creating
one.

Collaborator

lombokissues commented Jul 14, 2015

👤 r.spilker   🕗 Jul 24, 2009 at 11:04 UTC

Also, we might want to check if any of the is/has/get methods exists befor creating
one.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 r.spilker   🕗 Jul 25, 2009 at 21:10 UTC

If the field starts with "is" we don't want to prepend another "is". We need to make
sure that "is" or "has" is not the start of a longer word. So the next character has to
be title case. This ensures that a boolean field called hashCodeCalculated would get a
getter named isHashCodeCalculated instead of hasHCodeCalculated.

Collaborator

lombokissues commented Jul 14, 2015

👤 r.spilker   🕗 Jul 25, 2009 at 21:10 UTC

If the field starts with "is" we don't want to prepend another "is". We need to make
sure that "is" or "has" is not the start of a longer word. So the next character has to
be title case. This ensures that a boolean field called hashCodeCalculated would get a
getter named isHashCodeCalculated instead of hasHCodeCalculated.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 reinierz   🕗 Jul 26, 2009 at 07:19 UTC

Implemented all suggested changes in commit a9d2989.

NB: Roel, I haven't tested all borderline cases on this one!

Collaborator

lombokissues commented Jul 14, 2015

👤 reinierz   🕗 Jul 26, 2009 at 07:19 UTC

Implemented all suggested changes in commit a9d2989.

NB: Roel, I haven't tested all borderline cases on this one!

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 reinierz   🕗 Jul 26, 2009 at 07:30 UTC

Test ﹟1: Make boolean fields named 'isFoo', 'getBar', 'hasBaz' and 'hashFlooble'. This must generate methods
'isFoo(), hasBaz, getBar, and isHashFlooble.

On eclipse: Correct on all counts.

On javac: Correct on all counts.

Test ﹟2: Make boolean fields named 'isFoo', 'bar'. Then make methods named 'hasFoo', and 'getBar', and make
sure that neither field gets an auto-generated getter, and that both fields get a warning that no getter is
being made, with the alternate name stated in the warning message.

on eclipse: correct on all counts.

on javac: correct on all counts.

Thus, I'm verifying the change.

Collaborator

lombokissues commented Jul 14, 2015

👤 reinierz   🕗 Jul 26, 2009 at 07:30 UTC

Test ﹟1: Make boolean fields named 'isFoo', 'getBar', 'hasBaz' and 'hashFlooble'. This must generate methods
'isFoo(), hasBaz, getBar, and isHashFlooble.

On eclipse: Correct on all counts.

On javac: Correct on all counts.

Test ﹟2: Make boolean fields named 'isFoo', 'bar'. Then make methods named 'hasFoo', and 'getBar', and make
sure that neither field gets an auto-generated getter, and that both fields get a warning that no getter is
being made, with the alternate name stated in the warning message.

on eclipse: correct on all counts.

on javac: correct on all counts.

Thus, I'm verifying the change.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

End of migration

Collaborator

lombokissues commented Jul 14, 2015

End of migration

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
Issue #77
added validation of @Singular Field Type

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
Issue #77
added test class data from lombok project

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
Issue #77
added more validation for @Singular

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
#77
improved delombok code generation for @Singular Builder (generic parameters)

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
#77
improved delombok code generation for @Singular Builder (build Method and guava collections)

Tradunsky pushed a commit to Tradunsky/lombok that referenced this issue Aug 19, 2015

Michail Plushnikov
#77
improved delombok code generation for @Singular Builder (build Method)
@Ghedeon

This comment has been minimized.

Show comment
Hide comment
@Ghedeon

Ghedeon May 18, 2017

Sorry, I see that it's an old thread, but do I miss something or was it reverted? Because it generates isHasFoo() for the field named hasFoo in v1.16.16.

Ghedeon commented May 18, 2017

Sorry, I see that it's an old thread, but do I miss something or was it reverted? Because it generates isHasFoo() for the field named hasFoo in v1.16.16.

@Maaartinus

This comment has been minimized.

Show comment
Hide comment
@Maaartinus

Maaartinus May 18, 2017

Contributor

@Ghedeon IIRC this has indeed been reverted. It makes the names sound better, but it's another "prefix-shedding", incompatible with javabeans and not very systematic. There (at least) following possibilities:

  • javabeans compatible
  • no prefix
  • always get/set (never "is")
Contributor

Maaartinus commented May 18, 2017

@Ghedeon IIRC this has indeed been reverted. It makes the names sound better, but it's another "prefix-shedding", incompatible with javabeans and not very systematic. There (at least) following possibilities:

  • javabeans compatible
  • no prefix
  • always get/set (never "is")
@bmmpt

This comment has been minimized.

Show comment
Hide comment
@bmmpt

bmmpt May 25, 2017

Why not give the developer the ability so set the exact getter/setter name they what to use?

For instance I have a Boolean getter I would like to call canAdd... rather than isAdd or hadAdd.

Something like the following would be nice:

@getter(name="canAdd")
@setter(name="setCanAdd")
private Boolean thisNameDoesNotMatter;

bmmpt commented May 25, 2017

Why not give the developer the ability so set the exact getter/setter name they what to use?

For instance I have a Boolean getter I would like to call canAdd... rather than isAdd or hadAdd.

Something like the following would be nice:

@getter(name="canAdd")
@setter(name="setCanAdd")
private Boolean thisNameDoesNotMatter;

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