How to debug lombok objects

Kohei TAMURA :

Does anyone know how to set a breakpoint in the following Person.toString() when using Eclipse or IntelliJ IDEA?

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

@ToString
@AllArgsConstructor
@Data
public class Person {
    private String lastName;
    private String firstName;
}

EDIT:

If possible, I want to stop only when toString() is called.

maaartinus :

You're asking about both Eclipse and IntelliJ IDEA, and the answers are very different:

  • In Eclipse, right click on the method in the Members view and use "Toggle method breakpoint".
  • In IDEA, there is no solution, but there are good workarounds (see below) and there's a solution described in the comment by @PeterVerhas.

Umm, If possible, I don't want to change source code.

You're surely using version control, so nothing can go wrong, right? If not, then please start using it ASAP as I can't imagine any work without it.

The workaround is very easy despite having several steps:

  1. First, use version control to make sure you don't lose the current state (I usually just move everything down using "Rescan" and "Stage Changed" in git-gui).
  2. Do "Refactor" -> "Delombok" -> "@ToString" (IDEA only) and any other changes you want for debugging.
  3. Debug.
  4. Undo the changes in editor (if possible).
  5. Last, use version control to view the state of the working tree ("Rescan" in git-gui) and possibly to revert the unwanted changes ("Commit" -> "Revert changes" in git-gui) and/or to verify the state of the working tree.

Apart from debugging, which usually takes rather long, each of the steps takes one or two seconds. So there's hardly any overhead. Trust me, I do temporary code changes a few times a day.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=440724&siteId=1