Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug a custom annotation in Lombok?

Tags:

lombok

I am trying to extend Lombok by creating my own annotation.

I managed to have LombokizedEclipse.launch created by ant, and I have written before and after files.

ant test fails on my annotation (which is expected) and now I would like to debug my Handle* classes.

I am on a Mac, eclipse Luna 4.4 and java 1.8 update 45.

How can I do that? Please let me know if you need further info.

Thanks in advance!

like image 358
zxxz Avatar asked Jun 28 '15 22:06

zxxz


1 Answers

I now understand that Lombok can be debugged in 2 different ways:

  1. Debug through Lombok JUnit tests(Thanks Roel Spilker)
  2. Debug in a second Eclipse instance started by the first instance

After cloning the lombok repository, those are the steps I followed to achieve both methods:

Debug through Lombok JUnit tests(Thanks Roel Spilker)

  1. $ ant eclipse
  2. Import the (existing) project in Eclipse
  3. $ ant setupJavaOracle8TestEnvironment
  4. $ ant dist
  5. $ java -jar dist/lombok.jar
  6. Make sure the JDK8 configured in Eclipse is called JavaSE-1.8. Go to Eclipse -> Preferences -> Java -> Installed JREs to change it
  7. Refresh Eclipse project (just press F5)
  8. Right click the newly created Launch Configuration RunLombokTests OracleJDK8.launch and Run/Debug
  9. RunAllTests is executed: Runs: 455/454 (1 skipped), Errors: 0, Failures: 89
  10. $ ant test runs RunAllTests successfully: Tests run: 455, Failures: 0, Errors: 0, Skipped: 1
  11. NOTE: setting a breakpoint in e.g. HandleGetter.handle works I don't know why in Eclipse (step 9.) 89 tests fail in TestWithEcj, although the remaining 54 (and 1 skipped) pass.

Debug in a second Eclipse instance started by the first instance

  1. $ ant dist
  2. $ ant eclipseForDebugging
  3. Type in your eclipse installation (hint: it's the parent folder of the directory plugins)
  4. Start Eclipse and refresh the project
  5. Right click the newly created Launch Configuration LombokizedEclipse.launch and Run/Debug
  6. Create a new project in the second Eclipse instance
  7. Add your custom lombok.jar to the classpath
  8. Annotate with Lombok (or your custom) annotation
  9. The first Eclipse instance should take over if debugging (and if there are breakpoints)
like image 175
zxxz Avatar answered Oct 22 '22 02:10

zxxz