Evaluating many expressions at once in Intellij Idea

后端 未结 4 1165
囚心锁ツ
囚心锁ツ 2021-01-13 04:12

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 →

相关标签:
4条回答
  • 2021-01-13 04:34

    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());
    
    0 讨论(0)
  • 2021-01-13 04:42

    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.

    0 讨论(0)
  • 2021-01-13 04:44

    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".

    enter image description here

    enter image description here

    Then you can switch back anytime using "Expression mode" button.

    0 讨论(0)
  • 2021-01-13 04:56

    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 ⇧⏎ to switch to the multi-line Code fragment view and back.

    https://www.jetbrains.com/help/idea/evaluating-expressions.html

    0 讨论(0)
提交回复
热议问题