Problems compiling AutoValue library example project - java

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.

Related

Dagger2 Set up in Java with Ant in Eclipse

I am having trouble in setting up Dagger 2 sample cofee app in Eclipse using Ant. We have huge source code built using Ant so we cannot switch to maven. And I can find no sources anywhere which explains how to do that.
I have created a sample project, included all the dependencies and compiled. But, how do I generate the auto generated code of Dagger and reference it.
For example when I do
CoffeeShop coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build();
Compiler in eclipse complains that DaggerCoffeeApp_CoffeeShop cannot be found.
Can somebody please help with providing me a way to set up Dagger2 with Ant?
Thanks.

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.

Get IntelliJ to recognize classes generated by AnnotationProcessor

I'm using a java annotation processor to generates additional classes at compile time. It works fine when building with gradle, but I can't get IntelliJ to recognize the generated classes. Whenever I try to build the project in IntelliJ, it errors saying that it can't find the symbols that refer to the generated class. In the same vein, since it doesn't know about the classes, it's not giving me any help in writing code that uses the classes, and just highlights it all as an error.
I have two sibling modules: the "processor" module implements the annotation processor and defines the annotations. The "demo" module is just some JUnit tests to try out the annotation processor. I can build the "processor" module in IntelliJ fine, but the "demo" one gives me the errors as described above. I've got "processor" as a dependency of the "demo" module, at the "Test" scope (I've also tried "Compile" scope).
How can I get IntelliJ to recognize the classes automatically?
Update
I've been able to get it to build by creating a new profile under "Annotation Processors" in the settings dialog, moving the "demo" module under that profile, enabling annotation processing for that profile, and specifying the FQCN of the annotation processor under the "Annotation Processors" list box.
However, the live code help still isn't working, the editor just tells me it can't find the class, which is really more important (because I could always build from gradle).
In IntelliJ, find the folder that the generated code goes in. This is controlled by settings on the same dialog as where you set up the annotation processing. Right click on that folder, find "Mark Directory As" in the context menu, and choose "Generated Sources Root".
After doing this, IntelliJ will recognize and handle the generated classes normally. It will also give a compile warning that an output path intersects with a source root, but that's reasonably ignorable. I haven't been able to find a way to get rid of that warning without also leaving the generated classes unrecognized.
You can go on pom/gradle file and Reload it again, it will work.
example :
pom.xml(right-click)-> Maven-> Reload

netbeans find usages does not seem to scan xml files

Can anyone confirm this, or do I miss a check in a checkbox somewhere?
Example: When I go to a Java class and do a "Find Usages", it does not find a referance to the class, though it exists in a spring related xml-context file.
Can confirm this for Netbeans 7.2. And that's why some prefer Java spring config.
Try with this plugin: JohnBaker FindUsages, Spring Support for Find usages. Stock "find usages" from Netbeans doesn't support Spring.
There is also a generic Netbeans-Spring plugin.
Personally I use Eclipse with STS.

Categories

Resources