void (@NotNull ImperativeCommand.Environment env, @NotNull VirtualFile file) { List<PsiPolyadicExpression> concatenations = ContainerUtil.filter(PsiTreeUtil.findChildrenOfType(getPsiManager().findFile(file), PsiPolyadicExpression.class), e -> e.getType() != null && e.getType().equalsToText(JAVA_LANG_STRING)); if (concatenations.isEmpty()) return; myFixture.openFileInEditor(file); MigrationInvoker migrationInvoker = new MigrationInvoker(); BackwardMigrationInvoker backwardMigrationInvoker = new BackwardMigrationInvoker(); for (PsiPolyadicExpression concatenation : concatenations) { if (SuppressionUtil.isSuppressed(concatenation, MigrationInvoker.getToolId()) || SuppressionUtil.isSuppressed(concatenation, BackwardMigrationInvoker.getToolId())) { continue; } PsiExpression[] operands = concatenation.getOperands(); if (operands.length < 2) continue; env.logMessage("Tweaking concatenation at " + concatenation.getTextRange()); List<Pair<PsiElement, TextRange>> injected = InjectedLanguageManager.getInstance(getProject()).getInjectedPsiFiles(operands[0]); // IDEA-224671 if (injected != null && !injected.isEmpty()) continue; String expected = getConcatenationText(operands); if (expected == null || countNewLines(expected) < 2 && getQuoteIndex(expected) == -1) continue; expected = replaceUnescapedSpaces(expected); Computable<PsiElement> replaceAction = () -> { PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); PsiExpression newExpression = factory.createExpressionFromText("(" + concatenation.getText() + ")", null); return concatenation.replace(newExpression); }; PsiExpression parent = (PsiExpression)WriteCommandAction.runWriteCommandAction(concatenation.getProject(), replaceAction); PsiPolyadicExpression replaced = (PsiPolyadicExpression)PsiUtil.skipParenthesizedExprDown(parent); invokeIntention(replaced, myFixture, migrationInvoker); PsiLiteralExpression textBlock = (PsiLiteralExpression)PsiUtil.skipParenthesizedExprDown(parent); invokeIntention(textBlock, myFixture, backwardMigrationInvoker); PsiElement element = PsiUtil.skipParenthesizedExprDown(parent); PsiExpression[] operandsAfter = getOperands(element); String actual = Objects.requireNonNull(getConcatenationText(operandsAfter)); assertEquals("concatenation content", expected, actual); } }