RSL: convert invalid line separators (IDEA-190959)

This commit is contained in:
Anna.Kozlova
2018-04-25 19:33:37 +02:00
parent 2b26d30895
commit a2717a8087
5 changed files with 19 additions and 5 deletions
@@ -75,7 +75,7 @@ public class ConvertStringLiteralToRawAction implements IntentionAction, LowPrio
String additionalQuotes = PsiRawStringLiteralUtil.getAdditionalTics(textTicsTrimmed, "`");
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
CodeStyleManager.getInstance(project).reformat(
elementToReplace.replace(elementFactory.createExpressionFromText(prefix + '`' + additionalQuotes + textTicsTrimmed + additionalQuotes + '`' + suffix, null)));
elementToReplace.replace(elementFactory.createExpressionFromText(prefix + '`' + additionalQuotes + StringUtil.convertLineSeparators(textTicsTrimmed) + additionalQuotes + '`' + suffix, null)));
}
}
}
@@ -62,7 +62,7 @@ public class RawStringLiteralPasteProcessor implements PasteProvider {
int ticsLength = PsiRawStringLiteralUtil.getLeadingTicsSequence(literalText);
String quotes = literalText.substring(0, ticsLength);
String additionalQuotes = PsiRawStringLiteralUtil.getAdditionalTics(text, quotes);
insertAtCaret(text, additionalQuotes, stringLiteral, editor, prefix, suffix);
insertAtCaret(StringUtil.convertLineSeparators(text), additionalQuotes, stringLiteral, editor, prefix, suffix);
}
@Override
@@ -0,0 +1,5 @@
class A {
{
String s = "a<caret>\r";
}
}
@@ -36,9 +36,8 @@ public class LightAdvRawStringLiteralsTest extends LightCodeInsightFixtureTestCa
doTestIntention(QuickFixBundle.message("convert.to.string.text"));
}
public void testStringToRawTransformation() {
doTestIntention(QuickFixBundle.message("convert.to.raw.string.text"));
}
public void testStringToRawTransformation() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); }
public void testStringToRawTransformationWithWrongSeparators() { doTestIntention(QuickFixBundle.message("convert.to.raw.string.text")); }
public void testStringToRawTransformationLeadingTics() {
doTestIntention(QuickFixBundle.message("convert.to.raw.string.text"));
@@ -57,6 +56,10 @@ public class LightAdvRawStringLiteralsTest extends LightCodeInsightFixtureTestCa
doTestPaste("class A {{String s = `q<caret>`;}}", "a\nb`\nc", "class A {{String s = ``qa\nb`\nc``;}}");
}
public void testPasteInRawStringLiteralWrongLineSeparator() {
doTestPaste("class A {{String s = `<caret>a`;}}", "\r", "class A {{String s = `\na`;}}");
}
public void testPasteInRawStringStaringWithTics() {
doTestPaste("class A {{String s = `<caret>q`;}}", "``a\n``b", "class A {{String s = \"``\" + `a\n" + "``bq`;}}");
}