How to see lombok source code in NetBeans? - java

I have the Lombok plugin setup in NetBeans IDE and my code builds fine. I can see the Lombok generated methods in the structure view. What I want is some way to actually see the source Lombok generates for each of the methods. I realize I can delombok the file, but I'm wondering if there is some way I can flip a switch to show or hide the Lombok generated code (How to delombok in NetBeans?).
Procedure to see the source code of Lombok methods.

Related

How to get lombok generated source to be visible in eclipse/maven?

I am attempting to use lombok (https://projectlombok.org/) to help with "boilerplate" code generation. I have added the maven dependency and have also added the lombok maven plugin to the <build> element in the POM.
One of the things I was also told to do was to place the lombok-annotated code in src/main/lombok instead of src/main/java. I assume that I keep the package directory structure the same as in src/main/java.
This seems a little odd, but I did this and lombok did generate source files with all the getter/setter/equals/hashCode etc methods. They are placed in e.g. target/generated-sources/lombok/x/y/z/MyClass.java. This is kind of what I would expect having used other code generation tools like XJC.
My question is: how do I get this generated source to be "visible" to eclipse and the compile environment? I'm getting compile errors all over the place because it can't "see" the generated code. This occurs in eclipse as well as when I attempt to do a mvn clean install.
UPDATE:
I have already tried installing lombok into eclipse. It generates the getters/setters/etc, but there is a bug introduced somewhere that breaks the auto-complete feature of eclipse. I removed it from eclipse and am just trying to get maven to do the generation (or delombok-ing).
I've just installed Lombok (after a while) in my new Eclipse (STS) installation, and i was a bit "annoyed" by the lack of generated sources.
I found a hint however on this page that the generated structure is visible in the "Outline" view. (Look for the screenshots)
If you don't have Outline view open yet, enable it in the menu: Window / Show view / Outline.
Download Lombok jar (https://projectlombok.org/download) and execute it java -jar lombok.jar and select your eclipse installed folder.Restart eclipse and rebuild project.
To verify Lombok installation, please check Help -> About eclipse. Lombok entry show show at bottom.
You have to enable annotation processing for Eclipse to be able to pick up generated code.
Right-click on the project and select Properties.
Open Java Compiler and then Annotation Processing. Check Enable
annotation processing.
Open Java Compiler -> Annotation Processing -> Factory Path. Check
Enable project specific settings. Add your Lombok JAR file to the list.
Clean and build the project.
My problem was using full namespace annotation: #lombok.Getter, and I resolved it by doing import lombok.Getter and do #Getter

Why IntelliJ needs Lombok plugin?

As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods.
With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like #Getter, #Setter.
However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in IntelliJ, but it still requires Lombok Plugin to avoid false errors.
Is it some kind of bug? Error in workflow? Or maybe Lombok is using not only Annotation Processors, but some other stuff I didn't know and that's why IntelliJ + javac cannot figure out how to deal with it? It would be strange as javac itself compiles those files without errors
I know there are many questions "I have errors while using Lombok" and answers like "use the plugin". I'm not asking if I should use plugin, but why I should use it, why IntelliJ cannot handle it without plugin while javac does
IntelliJ's code analysis engine does not use javac or run annotation processors. Instead, IntelliJ uses its own Java parser and reference resolution logic, and builds its own code model. The Lombok plugin extends the code model to provide information about declarations generated by the Lombok annotation processor.
It's because IDEA syntax highlighter uses internal Java parser. If IDEA used just javac, then it wouldn't be able to highlight syntax errors as you type. It also gives much better hints about wrong code, so each Java construct, feature or annotation must be implemented by JetBrains team or there's plugin for it like in this case.
Annotation processing option is just for building project which is done via javac, but it's not for syntax highlighting.
Ale IDEs use lombok plugin be it intelij-idea or eclipse.
javac works fine with it - but remember that it works when for example you build you project with mvn clean package.
Then when you have your IDE - it works differntly - the code is not processed like in build task.
The plugin make it know to IDE what is this annotation and what code it generates underhood without need of javac.

Problems compiling AutoValue library example project

I just discovered google's AutoValue library, which seems great.
I'm trying to compile the example project which I downloaded from here
But the project doesn't compile.
The compiler complains about the AutoValue_ constructor symbol not being recognized.
Can someone explain what I am doing wrong?
I am using auto-value-1.3.jar
Thanks
IntelliJ does not enable annotation processors by default.
You can follow the official guide. You need to go to the Annotation Processors page and click + to create a new profile. Then you have to associate your module with this profile. In the end you only need to enable annotation processing for this profile and everything should work.
The IntelliJ editor might not find the generated class files though and still display the name red. But it should not affect the build.

Why Eclipse needs to be configure for Lombok?

In my Java project, i use Lombok tool to generate getter and setter.
It works perfectly with Maven, without any configuration.
For what reason i need to configure Eclipse for Lombok ?
I already know how to configure Eclipse : https://projectlombok.org/download.html
Why i have to add the following line in my eclipse.ini ?
-javaagent:lombok.jar
The Lombok site states:
Lombok copies your source files to another directory,
replacing all lombok annotations with their desugared form.
So configuring is done just because of source code modification. Without "javaagent" would be difficult.
Lombok uses Java annotation processor. So, irrespective of which IDE you use, if Lombok's jar is available for javac, your getters and setters get generated and all other functionality of Lombok works as expected.
Maven adds dependent jars (including Lombok's) to -classpath parameter of javac, so you wouldn't need a Java agent to instrument the code for you.

Tool for creating Dynamically Generated Code in Java (In Eclipse)

In Visual Studio land, I used to be able to define a structure in an XSD file and add a special attribute to it which would cause it to be dynamically compiled and available to use with intellisense in the other C# files in the application. I am not sure exactly what the term for this is, perhaps "dynamic code generation."
I am trying to accomplish the same in Java using Eclipse IDE. Basically what I am looking for is a tool that will allow me to specify some template and generate Java code from it in a "hot folder" that will allow me code complete in the other static Java files.
Does anyone know of a solution for this? I know it is possible in Visual Studio, but I can't seem to find anything for Eclipse.
Ok, here is exactly what I want to do.
Step 1. I create a folder called templates
Step 2. I create a file called HelloWord.ibes
Step 3. Code it automatically generated in my src folder HelloWorld.java
I want to be able to do this in eclipse easily.
You may create an ant build file that does the source generation for you. Then you are free to use any code generator you like. Ant support is part of the eclipse IDE. If you prefer maven, there's a nice eclipse pluging available (that's what I actually use for source code generation based on jaxb, javacc and xdoclet...).
Technically spoken, you just add another eclipse builder which is invoked anytime eclipse detects a change in your code base.
If you already have a code generator in mind, just 'ask' the internet if there's a plugin available.
Edit
On how to install a builder: This is done automatically. For maven, you just install the maven plugin (m2eclipse) and enable maven dependencies for a project. Then if you look at the projects properties pages (Builder section), you find a second entry in the list of builders.
It's similiar with ant, even easier, because ant is already integrated. "enable" ant for a project and the builder is added to the list of builders for the project. You can deselect it at any time if it kills performance or switch of automatic building (I don't know by heart how to enable ant builds for a project, but I remember that the eclipse help had sufficiant informations).
All about ant can be found here: Apache Ant
Creating a new builder is difficult, as it has to be coded in java and added to eclipse as a plugin. I bet you don't want to follow that track ;)
I'm not sure whether you have seen the code template option?
Preferences.Java, Code Style then Code Templates
How
to add code templates
Useful
code templates

Categories

Resources