mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
'Convert String to multiline' honor existing escapes
This commit is contained in:
@@ -1115,7 +1115,7 @@
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.ConvertStringToMultilineIntention</className>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.strings.ConvertStringToMultilineIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
|
||||
+1
-7
@@ -135,7 +135,7 @@ public class ConvertConcatenationToGstringIntention extends Intention {
|
||||
if (multiline) {
|
||||
final int position = builder.length();
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "$", "'\"", builder);
|
||||
fixAllTripleQuotes(builder, position);
|
||||
GrStringUtil.fixAllTripleDoubleQuotes(builder, position);
|
||||
}
|
||||
else {
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "$\"", "'", builder);
|
||||
@@ -152,12 +152,6 @@ public class ConvertConcatenationToGstringIntention extends Intention {
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixAllTripleQuotes(StringBuilder builder, int position) {
|
||||
for (int i = builder.indexOf("\"\"\"", position); i >= 0; i = builder.indexOf("\"\"\"", i)) {
|
||||
builder.replace(i + 2, i + 3, "\\\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* append text to builder if the operand is 'something'.toString()
|
||||
*/
|
||||
|
||||
+1
-7
@@ -156,17 +156,11 @@ public class ConvertGStringToStringIntention extends Intention {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
if (text.indexOf('\n') >= 0) {
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "", "\"$", buffer);
|
||||
fixAllTripleQuotes(buffer, 0);
|
||||
GrStringUtil.fixAllTripleQuotes(buffer, 0);
|
||||
}
|
||||
else {
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "'", "\"$", buffer);
|
||||
}
|
||||
return GrStringUtil.addQuotes(buffer.toString(), false);
|
||||
}
|
||||
|
||||
private static void fixAllTripleQuotes(StringBuilder builder, int position) {
|
||||
for (int i = builder.indexOf("'''", position); i >= 0; i = builder.indexOf("'''", i)) {
|
||||
builder.replace(i + 2, i + 3, "\\'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-10
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.intentions.conversions;
|
||||
package org.jetbrains.plugins.groovy.intentions.conversions.strings;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -93,17 +93,15 @@ public class ConvertStringToMultilineIntention extends Intention {
|
||||
}
|
||||
|
||||
private static void appendSimpleStringValue(PsiElement element, StringBuilder buffer, String quote) {
|
||||
final Object value = ((GrLiteralImpl)element).getValue();
|
||||
if (value instanceof String) {
|
||||
if ("'''".equals(quote)) {
|
||||
GrStringUtil.escapeStringCharacters(((String)value).length(), (String)value, "", false, true, buffer);
|
||||
}
|
||||
else {
|
||||
GrStringUtil.escapeSymbolsForGString((CharSequence)value, false, false, buffer);
|
||||
}
|
||||
final String text = GrStringUtil.removeQuotes(element.getText());
|
||||
final int position = buffer.length();
|
||||
if ("'''".equals(quote)) {
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "", "'n", buffer);
|
||||
GrStringUtil.fixAllTripleQuotes(buffer, position);
|
||||
}
|
||||
else {
|
||||
buffer.append(GrStringUtil.removeQuotes(element.getText()));
|
||||
GrStringUtil.escapeAndUnescapeSymbols(text, "", "\"n", buffer);
|
||||
GrStringUtil.fixAllTripleDoubleQuotes(buffer, position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,8 +361,15 @@ public class GrStringUtil {
|
||||
if (escaped) {
|
||||
if (toUnescape.indexOf(ch) < 0) {
|
||||
builder.append('\\');
|
||||
builder.append(ch);
|
||||
}
|
||||
else {
|
||||
if (ch=='n') builder.append('\n');
|
||||
else if (ch=='b') builder.append('\b');
|
||||
else if (ch=='t') builder.append('\t');
|
||||
else if (ch=='f') builder.append('\r');
|
||||
else builder.append(ch);
|
||||
}
|
||||
builder.append(ch);
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
@@ -858,4 +865,16 @@ public class GrStringUtil {
|
||||
builder.append(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixAllTripleQuotes(StringBuilder builder, int position) {
|
||||
for (int i = builder.indexOf("'''", position); i >= 0; i = builder.indexOf("'''", i)) {
|
||||
builder.replace(i + 2, i + 3, "\\'");
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixAllTripleDoubleQuotes(StringBuilder builder, int position) {
|
||||
for (int i = builder.indexOf("\"\"\"", position); i >= 0; i = builder.indexOf("\"\"\"", i)) {
|
||||
builder.replace(i + 2, i + 3, "\\\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ package org.jetbrains.plugins.groovy.intentions
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase
|
||||
import org.jetbrains.plugins.groovy.intentions.conversions.ConvertStringToMultilineIntention
|
||||
import org.jetbrains.plugins.groovy.intentions.conversions.strings.ConvertStringToMultilineIntention
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
|
||||
Reference in New Issue
Block a user