1

According to the following question and response:

How find out static string result concatenation in Intellij Idea without running code?

it is possible to copy result of the String concatenation from IntelliJ into the clipboard.

Let me cite:

just put cursor on the string concatenation
Press alt + enter
Select "Copy String concatenation text into clipboard"
Paste result somewhere.

However, I find out that this solution does not work in case of the String.format.

Is there any workaround or plugin for the IntelliJ that allows to perform this operation?

public class Main {

    public static void main(String[] args) {
        final String one = "want";
        final String two = "copy";
        final String three = "concatenated string";

        // I want to copy whole concatenated string
        String canBeCopiedIntoClipBoard = "I " + one + " to " + two + " whole " + three;
        String cannotCopyResultIntoClipBoard = String.format("I %s to %s whole %s", one, two, three);

        assert canBeCopiedIntoClipBoard.equals(cannotCopyResultIntoClipBoard);
        System.out.println(canBeCopiedIntoClipBoard);
    }
}
matandked
  • 1,527
  • 4
  • 26
  • 51

1 Answers1

0

It cannot be done directly from the IDE because of the simple fact that the variables used in the construction of the result may come from anywhere and may not be known at compile-time, as well as intricacies of the implementation of whichever external class you invoke (think of environment variables that may play a role).

You can do it if you can run to the point of the construction of the result.

  • Put a breakpoint at the line of 'cannotCopyResultIntoClipBoard' and start debug,
  • Select the part that generates the string,
  • Open to the 'Evaluate' panel (Sometimes Alt+F8, always RunEvaluate Expression…),
  • Press enter,
  • In the result panel, right click, Copy Value.
Mark Jeronimus
  • 9,278
  • 3
  • 37
  • 50
  • In my example I use final variables defined in the scope of the current method. So they are known at compile-time. Moreover IntelliJ perfectly know what to copy in the first case. Regarding debugging: thanks for suggestion, but it will be very annoying to compile whole project in case of much more complex code than provided here. – matandked Apr 19 '19 at 14:16