[java-typing] IDEA-333179 "}" not added automatically after typing "\{" in interpolated string

GitOrigin-RevId: 5e8c790eb6422a25705806cdcb94c252c92883b3
This commit is contained in:
Tagir Valeev
2023-09-28 10:42:19 +02:00
committed by intellij-monorepo-bot
parent d7160411f2
commit c09b082016
10 changed files with 45 additions and 0 deletions

View File

@@ -125,6 +125,17 @@ public abstract class AbstractBasicJavaTypedHandler extends TypedHandlerDelegate
return Result.CONTINUE;
}
Document doc = editor.getDocument();
if (!iterator.atEnd() &&
(iterator.getTokenType() == StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN ||
iterator.getTokenType() == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN) &&
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) { // "\{}" in strings
CharSequence sequence = doc.getCharsSequence();
if (sequence.length() > offset && sequence.charAt(offset - 1) == '\\' && sequence.charAt(offset) != '}') {
doc.insertString(offset, "{}");
editor.getCaretModel().moveToOffset(offset + 1);
return Result.STOP;
}
}
PsiDocumentManager.getInstance(project).commitDocument(doc);
final PsiElement leaf = file.findElementAt(offset);
if (BasicJavaAstTreeUtil.getParentOfType(leaf, BASIC_ARRAY_INITIALIZER_EXPRESSION, false,

View File

@@ -118,6 +118,14 @@ public abstract class AbstractBasicJavaTypingTest extends BasePlatformTestCase {
public void testQuestionAfterPolyadicBoolean() { doTest('?'); }
public void testStartStringTemplate() { doTest('{'); }
public void testStartStringTemplateNoClosingQuote() { doTest('{'); }
public void testStartStringTemplateTextBlock() { doTest('{'); }
public void testStartStringTemplateAlreadyBrace() { doTest('{'); }
protected void doTest(char c) {
myFixture.configureByFile(getTestName(true) + "_before.java");
myFixture.type(c);

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\{<caret>}"
}

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\<caret>}"
}

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\{<caret>}
}

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\<caret>
}

View File

@@ -0,0 +1,4 @@
class X {
String str = STR."""
hello\{<caret>}
}

View File

@@ -0,0 +1,4 @@
class X {
String str = STR."""
hello\<caret>
}

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\{<caret>}"
}

View File

@@ -0,0 +1,3 @@
class X {
String str = STR."hello\<caret>"
}