Debug breakpoint on partial statement

Hey all,

I've got a question concerning breakpoints. I'm new to IntelliJ. Is it possible to put a breakpoint in the middle of a statement, when this statement is split over several lines? I'm used to this feature in other IDE's, so i'm really eager to find out if this is also possible in the IntelliJ debugger too. Since the use of the builder pattern is gaining more and more interest, this feature is very important. Then you could debug in statements like this:

Builder b = new Builder()
     .step1()
     .step2()
     .step3();

without having to assign the intermediate results to a variable. Until now, I haven't been able to do this. Maybe another debugger is needed? Or another compilation is needed? Or instrumentation code has to be added, which isn't retained by default....

Thanks in advance, this would really help.

Linus

6 comments
Comment actions Permalink

Hi There,

If you wanted to set a breakpoint on "step2()", just set a breakpoint on  the last line of code in the step2 method and use SHIFT-F8 immediately  when it triggers.

If you want see what happens to variable b as you go through the "step" methods, first split your declaration and builder steps onto separate lines.

        Builder b = new Builder();
        b.step1().step2().step3();

Then break on the second line and use F7 (step into) and SHIFT-F8 (step out) to advance through the builder steps. You will see variable b updates in the Debugger Variables pane.

Hope this helps.
Steve

0
Comment actions Permalink

Hi Linus,

You can do the following then:

  1. Set break point at the first call string;
  2. Wait for break point hit;
  3. Press 'Shift + F7' ('Main Menu -> Run -> Smart Step Into') - you will be asked about method to go into;


Regards, Denis

0
Comment actions Permalink

afaik, if you use the eclipse compiler, you can set breakpoints at any line where anything is executed or passed to another method.

0
Comment actions Permalink

The alternatives you guys are offering are not quite what I expect. First of all, I have to change the source code, alter the arrangement, and even assign the result to an intermediate variable. This is not always possible, if I want to debug in 3rd party code for example. The other option requires me to put a breakpoint in advance, before going into the builder methods. This is also inconvenient, I'd like to put my breakpoint anywhere; not somewhere close, and then step-into untill I reach the code I'm interested in.

Eclipse is indeed smart enough to allow a breakpoint about anywhere in the code. I'm hoping IntelliJ has this feature too, somewhere hidden... :-) Anyone?

0
Comment actions Permalink

you answered to my message, but you didn't seem to read it properly. it's not eclipse itself that allows you to put breakpoints at the "partial statement lines". it's the compiler that wrote the necessary debug-information in the class file. if you configure idea to use the eclipse compiler (you can do so in the compiler settings), you'll be able to put break points at "partial statement lines".
the other way round, if a thrid party jar has been compiled using the sun compiler, eclipse won't be able to stop at these lines.

it's a featre of the compiler, not the ide.

0
Comment actions Permalink

Okay, now I understand what you mean by 'use the eclipse compiler' :-) This is great information Hamster, Thanks!

0

Please sign in to leave a comment.