Lomboker Eclipse Plugin (Day 2)
This is the second post on my proof-of-concept “Lomboker Eclipse Plugin”
See previous post here
Yesterday, I have shown the first post and the plugin to a fiend of mine, and we had this discussion:
My Friend> is it all Lombok is about?
Me> Well, no. Lombok also has the amazying val and var features, and much more
My Friend> It is not supported in your plugin ?
Me> Well, yes it is true that would be easy to do.
But sorry about that, I only started yesterday and I spent just 3 hours on it...
The longer was to write the post on my github.io
My Friend> Oh! OK! I see... that's not so bad. It is even pretty good.
Isn’t it so encouraging to do the second step ?
Day 2 : Transforming val and var for local variable and foreach
On day 2, I worked again to improve this proof-of-concept plugin, and added ~3 more hours of work.
I have implemented the detections of "SomeLongTypeName localVar = new SomeLongTypeName();", and replacements with lombok "var localVar = new SomeLongTypeName();"
Isn't it true we ALL java developper are fed up typing things like ?? instead of
Of course, Java will continue to evolve (slowly as it always did), and there is some hope with this JEP (http://openjdk.java.net/jeps/286) that it will be built-in in the langage soon:
Back to my plugin development, this was pretty easy, but I had to avoid few nasty cases:
- it is useless to replace already primitive types, and also String type
- when using the jdk8 Diamond syntax, I had to preserve the type from the left hand side declaration, to put it to the right hand side! To my opinion, this is a nasty mistake in java8 syntax, it is more logic for typed-inference langage to be like
- final variable must be replaced by "val", whereas modifiable variable must be replaced by "var"
- for explicitely "final" variable, the keyword modifier "final" must be removed
- I should also detect "effective final" variables (variables that not explicitely marked as final, but bever modified anyway).. I did not implement it yet, so they still are replaced with lombok "var".
Enough speaking ... Demo
Now the settings dialog window has 2 checkboxes:Click on Preview, to see how local variables are transformed
(notice the different cases using primitive, final declaration, diamond syntax ..)
And also the same with foreach loops
Want to see how code is simple ?
Here is an extract of the transformation of foreach "var" ... It is only ~ 50 lines of code only !Conclusion
I am ready, and I would be proud to present it at the great Devoxx France 2017 conference.Maybe somebody will notice it, and this plugin will be improved and added to the excellent Lombok tool suite.
Notice that there was already an official "delomboker" tools, to transform lombok code to plain-old-java code, as required for source-code analyser tools like GWT and Sonar.
Now there would be an official "lomboker" tool.
For the presentation title, I have chosen "Chérie, J'ai Lomboké les Classes" (french translation of "Honey, I Shrunk the Classes"), which is a reference to the film "Honey, I Shrunk the Kids".
Reminder, it is open-source, fork it on GitHub https://github.com/Arnaud-Nauwynck/mytoolbox .. fr.an.eclipse.tools.lombok