
A few weeks back maaartinus asked on stack overflow whether we can get lombok working with Codename One. After a short back and forth it seems that this was as easy as I’d hoped and he was able to get it working without a change.
Personally, I like our approach of property objects more but that’s obviously a matter of taste. Lombok works by processing the bytecode after compilation to convert annotations to terse code. E.g. this Java code using Lombok:
@Getter @Setter @NonNull
private List<Person> members;
Would be similar to this regular Java code:
private List<Person> members;
public Family(final List<Person> members) {
if (members == null) throw new java.lang.NullPointerException("members");
this.members = members;
}
public List<Person> getMembers() {
return members;
}
public void setMembers(final List<Person> members) {
if (members == null) throw new java.lang.NullPointerException("members");
this.members = members;
}
| __ | I took the code sample above from here |
|---|
That’s pretty nice and it has some other features that hide some of the verbosity of Java.
As mentioned in the answer adding Lombok to a Codename One application is pretty easy:
Just add the
lombok.jarto the build path which you can find in the project settings for the native IDEIn the
build.xmlreplacecompiler="modern"withcompiler="extJavac"Add the path to
lombok.jarto the classpath in thebuild.xml(this might not be necessary in NetBeans)
Doing this for Other Things
Lombok is just one of a huge set of bytecode manipulation tools that work statically. I’m sure there are many other tools like that in the wild that would “just work” and we never got around to test them.
If you have a pet tool in your toolbox check it out and see if it works with Codename One. You might be surprised.
Archived Comments
This post was automatically migrated from the legacy Codename One blog. The original comments are preserved below for historical context. New discussion happens in the Discussion section.
Martin Grajcar — November 9, 2018 at 2:05 am (permalink)
Martin Grajcar says:
You’re wrong concerning how Lombok works. It does AST manipulation rather than bytecode manipulation. That’s a black magic necessary as without the stuff generated by Lombok, the code won’t usually compile (and you’d get no bytecode to play with). But this is just a detail, the important thing is that it’s job is done in the compiler.
Shai Almog — November 9, 2018 at 6:48 am (permalink)
Shai Almog says:
I should have phrased it differently. It manipulates the bytecode statically which is the point that matters to us. I don’t really care about the underlying implementation and had no interest in it.
Discussion
Join the conversation via GitHub Discussions.