This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Adding boilerplate codes automatically?

 
Ranch Hand
Posts: 260
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 574
14
IntelliJ IDE Spring Fedora
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5168
322
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5168
322
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8144
572
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 260
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74392
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 260
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74392
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8144
572
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8144
572
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 260
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic