krasa / StringManipulation

IntelliJ plugin - https://plugins.jetbrains.com/plugin/2162
Apache License 2.0
694 stars 81 forks source link

Feature Request - Wrap/unwrap Java string literal #226

Closed viliam-durina closed 6 months ago

viliam-durina commented 6 months ago

Sometimes you have a text in a Java String literal, which you want to copy-paste somewhere else, as if the text was printed. For example, you have the following Java String literal:

"SELECT * \n"
    + "FROM emp\n"
    + "JOIN dept USING (deptno)";

You want to convert it to:

SELECT *
FROM emp
JOIN dept USING (deptno)

We often have very long queries or pieces of HTML in String literals. Conversion in both ways would be useful, I don't know of another way how to do it automatically.

Unwrapping should fail if there's anything else other than a single + character and whitespace between individual string literals. Escaped characters should be unescaped.

The usefulness will be slightly reduced after Java 15 which introduced multi-line string literals, I suppose IntelliJ has a conversion to this literal type, but many projects are stuck with older versions (mine are too).

Perhaps the current Quote/unquote feature can be replaced with this behavior, it's pretty useless IMO, it doesn't even escape/unescape the characters within the text.

The conversion might be useful for other languages too, but it should not be determined by the file type in the editor - most often I copy SQL queries to SQL console where I want to unwrap.

krasa commented 6 months ago

IntelliJ already has that. Alt+enter : obrazek

viliam-durina commented 6 months ago

I was googling for it and couldn't find it... But IMO it's broken, it adds newlines if the concatenation is broken into multiple lines, but this is already reported and it's disputed, whether it's a bug or feature.