Community
Participate
Working Groups
Per our discussion during JDT Summit. The basic idea is to propose a command as easy as 'Toggle Comment' (shortcut Ctrl-Shift-/) to transform the lines that are spanned by the current selection between two representations, one being plain (code) text, the other being a String concatenation that, passed as a parameter to System.out.print(), would yield the original text. I believe that the action should behave as the 'Toggle Comment' in all possible respects, so as to look very familiar to users. Since we are talking about string concatenation instead of comments, the following caveats are implied: - the literal contents should be quoted wherever needed (aka '"' must be coded as '\"'); - end of line characters must be added; '\n' seems to be the most natural candidate here; - Unicode character escapes should be avoided when not absolutely necessary, unless they are explicitly present in the original text; - the determination of the limit between external indentation and internal indentation may be done using surrounding literals if any, the left most non whitespace char else (can't think of better way of doing that for now); - the tool should be resilient to syntax errors in both representations. One example, for which the selection would span the three lines starting with class X: void testCase { test( class X { void foo(){} } ); } void testCase { test( "class X {\n" + " void foo(){}\n" + "}\n" ); } Note that in the suggested example, the plain text representation is not a fragment of a Java conforming program, while the String concatenation expression is such a fragment. To elaborate on the indentation, if the selection spans the line of bar below, the result could use the context to get the appropriate indentation: void testCase { test( "class X {\n" + " void foo(){}\n" + boolean bar() {return false;} "}\n" ); } void testCase { test( "class X {\n" + " void foo(){}\n" + " boolean bar() {return false;}\n" "}\n" ); } A refinement would be to detect that we are inserting into an existing concatenation and to infer the + sign from that, getting: void testCase { test( "class X {\n" + " void foo(){}\n" + " boolean bar() {return false;}\n" + "}\n" ); }
We will see what we can do for 3.3.
Downgrading priority since we will probably not have time for this for 3.3.