mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
[java-typing] String template typing improvements: avoid } duplication; fix at input at EOF
GitOrigin-RevId: 5e2a3509a9300d53c2101d22bf4420fd5e520949
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0d63633751
commit
5a61cfcc6e
@@ -111,6 +111,20 @@ public abstract class AbstractBasicJavaTypedHandler extends TypedHandlerDelegate
|
||||
if (c == ';') {
|
||||
if (handleSemicolon(project, editor, file, fileType)) return Result.STOP;
|
||||
}
|
||||
if (fileType instanceof JavaFileType && c == '}') {
|
||||
// Normal RBrace handler doesn't work with \{}, because braces in string template are not separate tokens
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
|
||||
HighlighterIterator iterator = editor.getHighlighter().createIterator(offset-1);
|
||||
CharSequence sequence = editor.getDocument().getCharsSequence();
|
||||
if (!iterator.atEnd() && iterator.getTokenType() == StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN &&
|
||||
iterator.getEnd() == offset && sequence.subSequence(iterator.getStart(), iterator.getEnd()).toString().equals("\\{")) {
|
||||
if (sequence.length() > offset && sequence.charAt(offset) == '}') {
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
return Result.STOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileType instanceof JavaFileType && c == '{') {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
if (offset == 0) {
|
||||
@@ -130,7 +144,7 @@ public abstract class AbstractBasicJavaTypedHandler extends TypedHandlerDelegate
|
||||
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) != '}') {
|
||||
if (sequence.charAt(offset - 1) == '\\' && (sequence.length() == offset || sequence.charAt(offset) != '}')) {
|
||||
doc.insertString(offset, "{}");
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
return Result.STOP;
|
||||
|
||||
@@ -23,7 +23,7 @@ class JavaStringLiteralLexer extends StringLiteralLexer {
|
||||
@Override
|
||||
public IElementType getTokenType() {
|
||||
IElementType tokenType = super.getTokenType();
|
||||
if (tokenType == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN) {
|
||||
if (tokenType == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN && myBuffer.length() > myStart + 1) {
|
||||
char c = myBuffer.charAt(myStart + 1);
|
||||
if (c == '{' && BasicElementTypes.BASIC_STRING_TEMPLATE_FRAGMENTS.contains(myOriginalLiteralToken)) {
|
||||
// don't highlight \{ in template fragment as bad escape
|
||||
|
||||
Reference in New Issue
Block a user