Comments (9)
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;
from lombok.
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
.
from lombok.
đ¤ reinierz  đ Jul 24, 2009 at 04:17 UTC
What steps will reproduce the problem?
- Create a class with a field named 'hasX', typed 'boolean'.
- Put a @ Data annotation on it.
- 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.
from lombok.
đ¤ 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.
from lombok.
đ¤ 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.
from lombok.
đ¤ 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!
from lombok.
đ¤ 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.
from lombok.
End of migration
from lombok.
@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")
from lombok.
Related Issues (20)
- [FEATURE] Add configuration key `lombok.copyableAnnotations.onMethod` and/or add swagger's `@Hidden` to the list of `COPY_TO_SETTER_ANNOTATIONS`
- [BUG] java.lang.NoSuchMethodError: 'void org.eclipse.jdt.internal.compiler.ast.CaseStatement.<init>(org.eclipse.jdt.internal.compiler.ast.Expression, int, int)' HOT 1
- [FEATURE] Default Value Support in Lombok HOT 2
- [BUG] Using @StandardException and @AllArgConstructor on a class with two non-primitive fields creates ambiguous constructor HOT 2
- [BUG] @SuperBuilder/@Builder generates names(Collection<? extends String > names)-method, but String is final HOT 3
- [FEATURE] finish the job and make generating `@lombok.Generated` default behaviour HOT 1
- Jakarta Generated support HOT 3
- Support extension method autocomplete HOT 2
- [FEATURE] Add more flexibility to declare copyable annotations
- sorry it was mistake
- [BUG] Javadoc generation fails because of @Builder
- [BUG] Delombok fails on unnamed patterns in Java 22 HOT 1
- [BUG] UtilityClass nested in an enum does not work after upgrading to Java 21
- [BUG] @Delegate does not respect --source and --target HOT 1
- [BUG] Installer Throws a Bunch of Errors
- [BUG][REG 1.18.32] A required class was missing while executing org.eclipse.tycho:tycho-compiler-plugin:4.0.7:compile: org/eclipse/jdt/internal/compiler/parser/Parser
- [FEATURE] @FieldNameConstants Easier overwrite for generated fields HOT 2
- @FieldDefaults: Keep the global setting experimental, make the annotation permanent.
- [FEATURE] Allow to easily add interfaces to Builders
- [BUG] Support for Eclipse 2024-06 (4.32) HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lombok.