• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Adding boilerplate codes automatically?

 
Ranch Hand
Posts: 165
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

QUESTION: Does anyone know of any add-ons in Eclipse that would do that for me?

I saw people using other IDEs adding boilerplate codes automatically e.g. the long-winded  getters-setters in FX
I am using Eclipse Version: 2019-03 (4.11.0)
P.S. I was googling and Lombok came up, does anyone have experience with that?
 
Rancher
Posts: 480
6
IntelliJ IDE Spring Fedora
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lombok will automatically put the boilerplate in when it compiles.  Not sure if its when it compiles or not but it wont ever show up in the java file.  
 
Marshal
Posts: 4671
305
IntelliJ IDE Clojure Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like Eclipse already has this feature built in, according to this DZone article anyway: https://dzone.com/articles/generate-rename-and-delete

I'm an Intellij user and it has this feature built in, along with many many other really useful tools that make writing code faster and safer.
 
Tim Cooke
Marshal
Posts: 4671
305
IntelliJ IDE Clojure Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I'm not a fan of Project Lombok for reasons discussed here and have recently removed it from a work project in favour of explicitly writing getters and setters.
 
Marshal
Posts: 7084
491
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

AhFai Chan wrote:
QUESTION: Does anyone know of any add-ons in Eclipse that would do that for me?

I saw people using other IDEs adding boilerplate codes automatically e.g. the long-winded  getters-setters in FX
I am using Eclipse Version: 2019-03 (4.11.0)
P.S. I was googling and Lombok came up, does anyone have experience with that?


Here is google search results. Tim is right, there is built-in feature already. It was about 5 years ago already if I remember correctly.

I'd say avoid Lombok, at least until you have enough experience to understand pros and cons of it.
 
AhFai Chan
Ranch Hand
Posts: 165
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sheriffs: please do not delete this post, I'll come back to it in a couple of day... too many things to do
 
Marshal
Posts: 65465
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't delete posts. Well, we do if they have something wrong with them, but that means offensive language or spam or similar. Otherwise, posts remain visible for ever.
 
AhFai Chan
Ranch Hand
Posts: 165
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:It looks like Eclipse already has this feature built in, according to this DZone article anyway: https://dzone.com/articles/generate-rename-and-delete



Thank-you for the link, it works.
Have to create the first instance with all the fields and field-types defined. The rest is auto. For someone who pecks at the keyboard, its a real relief.

The problem is the data types are different for FX b/c it uses SimpleStringProperty whereas eclipse have them all in String.
 
Campbell Ritchie
Marshal
Posts: 65465
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid abbreviations like b/c which many people aren't familiar with.
I am not sure what happened to the [quote] [‍/quote] tags, but I think I have corrected them.
 
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

AhFai Chan wrote:The problem is the data types are different for FX b/c it uses SimpleStringProperty whereas eclipse have them all in String.


It's true that JavaFX Beans are more complex than regular beans.  You might see something like this:
I don't know of an automatic way to create beans like this.
 
Liutauras Vilda
Marshal
Posts: 7084
491
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:You might see something like this...


In which case Lombok wouldn't handle that either.
 
Liutauras Vilda
Marshal
Posts: 7084
491
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

Have a look at this our colleagues thread, they might are on something. It seems eclipse has plugin to handle it, while for IntelliJ you can create a template or something. Didn't read carefully, you'll have to research yourself.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the way to generate getters and setters in Eclipse after installing the e(fx)clipse is:

* Create your class and add your property fields
* Right-click on the code view pane and select Source (you can't do this from the menu bar for some reason).
* Select Generate JavaFX Getters and Setters
 
Ranch Hand
Posts: 387
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Intellij Idea, you can choose Code | Generate (command+N on Mac) and it can will generate different pieces of code for you like getters/setters, equals and hashcode.  
The generation is JavaFX property aware.

So, if you have:

Then you press command+N on a Mac and choose Generate | Getter and Setter, you get:

There are a bunch of design patterns in the JavaFX property cookbook (worth reading if you haven't seen it, though some of them are slightly outdated, e.g. does not make use of things like ReadOnlyIntegerWrapper for a read only property):
https://wiki.openjdk.java.net/display/OpenJFX/JavaFX+Property+Architecture
They demonstrate some subtlety, especially around things like lazy initialization and read only properties, that aren't provided directly in the generated property code from the IDEs.  For instance, an IDE (at least Idea) won't generate code such as that below for a read only wrapper:

Still, Lombok won't create the appropriate property accessors for JavaFX properties as far as I know.  

So, what I'd recommend for JavaFX development which has a lot of properties, is to just use an IDE, use the quick code generation functions of the IDE to generate some boilerplate code for getters/setters, etc as needed, then examine the generated code and modify it as required to fit the exact accessors and patterns you need for your app (if you use things like read only properties - which you should because reducing the mutability of code makes it easier to understand and debug).
 
 
AhFai Chan
Ranch Hand
Posts: 165
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:So the way to generate getters and setters in Eclipse after installing the e(fx)clipse is:

* Create your class and add your property fields
* Right-click on the code view pane and select Source (you can't do this from the menu bar for some reason).
* Select Generate JavaFX Getters and Setters



That did it.
That generated FX style getter-setters.
Thank-you.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!