Reputation: 4942
In IntelliJ IDEA, I'm looking for a way to evaluate many expressions in debug mode with one command.
Normally I can evaluate single command with Right Click → Evaluate Expression
(ALT+F8). I would like to have possibility to evaluate a bunch of expressions like:
System.out.println(myVar1);
System.out.println(myVar2);
In Eclipse this is possible to execute such "script of expressions", but I can not find a solution in IntelliJ IDEA.
Upvotes: 8
Views: 5221
Reputation: 1784
You can either click the small fullscreen arrows button to the right of the Expression box, or press shift
+enter
.
If you want to edit a multi-line expression or a code fragment, click Expand in the Expression field or press ⇧Shift↩Enter to switch to the multi-line Code fragment view and back.
💁♂️ Evaluate expressions in a dedicated dialog
Upvotes: 6
Reputation: 1467
well i was also struggling a lot with this, until i figured out that in the code it needs fully qualified paths for classes (for classes outside of java.*)
for example in this code below , i needed to find out , xml string representation from the document object (doc is my document object)
so i had to put this code into evaluate tab , which you can open from run window -after putting in below expression and clicking on evaluate - my xml string was printed in console
javax.xml.transform.TransformerFactory tf = javax.xml.transform.TransformerFactory.newInstance();
javax.xml.transform.Transformer transformer = tf.newTransformer();
java.io.StringWriter writer = new java.io.StringWriter();
transformer.transform(new javax.xml.transform.dom.DOMSource(doc), new javax.xml.transform.stream.StreamResult(writer));
System.out.println(writer.getBuffer().toString());
Upvotes: 0
Reputation: 1144
You can evaluate such expressions in Evaluate window
System.out.println(myVar1);
System.out.println(myVar2);
The only thing here is that your whole result (not last) will appear not in the same window but in a console.
Upvotes: 0
Reputation: 17075
You have to click "Code fragment mode" in the evaluate expression dialog (Alt+F8) and you can enter as many lines as you want instead of single line - which is default - "Expression mode".
Then you can switch back anytime using "Expression mode" button.
Upvotes: 11