mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
guava type migration: quick fix for FluentIterable chain: replace in write-action
This commit is contained in:
+15
-10
@@ -18,6 +18,7 @@ package com.intellij.refactoring.typeMigration.inspections;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.undo.UndoUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -253,12 +254,11 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
public void invoke(@NotNull final Project project,
|
||||
@NotNull final PsiFile file,
|
||||
@Nullable("is null when called from inspection") Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
|
||||
try {
|
||||
final PsiMethodCallExpression expr = (PsiMethodCallExpression)startElement;
|
||||
@@ -269,13 +269,18 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
|
||||
final TypeConversionDescriptorBase conversion =
|
||||
rules.findConversion(myInitialType, myTargetType, expr.resolveMethod(), expr, new TypeMigrationLabeler(rules));
|
||||
LOG.assertTrue(conversion != null);
|
||||
PsiElement replacedExpression = TypeMigrationReplacementUtil.replaceExpression(expr, project, conversion);
|
||||
if (isIterableAssignment) {
|
||||
final String expressionText = replacedExpression.getText() + ".collect(java.util.stream.Collectors.toList())";
|
||||
replacedExpression = replacedExpression.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(expressionText, replacedExpression));
|
||||
}
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replacedExpression);
|
||||
UndoUtil.markPsiFileForUndo(file);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PsiElement replacedExpression = TypeMigrationReplacementUtil.replaceExpression(expr, project, conversion);
|
||||
if (isIterableAssignment) {
|
||||
final String expressionText = replacedExpression.getText() + ".collect(java.util.stream.Collectors.toList())";
|
||||
replacedExpression = replacedExpression.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(expressionText, replacedExpression));
|
||||
}
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replacedExpression);
|
||||
UndoUtil.markPsiFileForUndo(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
|
||||
Reference in New Issue
Block a user