Bug 150807 - [typing] Code to String concatenation back and forth command designed after 'Comment block' command
Summary: [typing] Code to String concatenation back and forth command designed after '...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-17 10:08 EDT by Maxime Daniel CLA
Modified: 2007-06-26 03:27 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2006-07-17 10:08:21 EDT
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"
  );
}
Comment 1 Dani Megert CLA 2006-07-17 11:06:55 EDT
We will see what we can do for 3.3.
Comment 2 Dani Megert CLA 2006-11-03 06:07:09 EST
Downgrading priority since we will probably not have time for this for 3.3.