Result (@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull Ref<Integer> caretOffsetRef, final @NotNull Ref<Integer> caretAdvanceRef, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) { final Language language = EnterHandler.getLanguage(dataContext); if (language == null) return Result.Continue; int caretOffset = caretOffsetRef.get().intValue(); final JavaLikeQuoteHandler quoteHandler = getJavaLikeQuoteHandler(editor, file); if (!isInStringLiteral(editor, quoteHandler, caretOffset)) { return Result.Continue; } PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument()); PsiElement psiAtOffset = file.findElementAt(caretOffset); if (psiAtOffset != null && psiAtOffset.getTextOffset() < caretOffset) { Document document = editor.getDocument(); if (quoteHandler.canBeConcatenated(psiAtOffset)) { ASTNode token = psiAtOffset.getNode(); CharSequence text = document.getText(); TextRange range = token.getTextRange(); final char literalStart = token.getText().charAt(0); final StringLiteralLexer lexer = new StringLiteralLexer(literalStart, token.getElementType()); lexer.start(text, range.getStartOffset(), range.getEndOffset()); while (lexer.getTokenType() != null) { if (lexer.getTokenStart() < caretOffset && caretOffset < lexer.getTokenEnd()) { if (StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(lexer.getTokenType())) { caretOffset = lexer.getTokenEnd(); } break; } lexer.advance(); } if (quoteHandler.needParenthesesAroundConcatenation(psiAtOffset)) { document.insertString(psiAtOffset.getTextRange().getEndOffset(), ")"); document.insertString(psiAtOffset.getTextRange().getStartOffset(), "("); caretOffset++; } final String insertedFragment = literalStart + " " + quoteHandler.getStringConcatenationOperatorRepresentation(); document.insertString(caretOffset, insertedFragment + " " + literalStart); caretOffset += insertedFragment.length(); int caretAdvance = 1; if (CodeStyle.getLanguageSettings(file).BINARY_OPERATION_SIGN_ON_NEXT_LINE) { caretOffset -= 1; caretAdvance = 3; } caretOffsetRef.set(caretOffset); caretAdvanceRef.set(caretAdvance); return Result.DefaultForceIndent; } } return Result.Continue; }