mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[mod-commands] ModShowConflicts: exclude next step
Simply continue execution of the outer ModCommand GitOrigin-RevId: a4ed40d46114c25f5502305567355b3419b3524e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2770254f2f
commit
c49a062434
+1
-1
@@ -122,7 +122,7 @@ public abstract class MethodThrowsFix extends PsiBasedModCommandAction<PsiMethod
|
||||
return true;
|
||||
});
|
||||
|
||||
return new ModShowConflicts(conflicts, action);
|
||||
return new ModShowConflicts(conflicts).andThen(action);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
+4
-3
@@ -66,9 +66,10 @@ public class ConvertInterfaceToClassIntention extends PsiBasedModCommandAction<P
|
||||
Map<PsiElement, ModShowConflicts.Conflict> map = EntryStream.of(conflicts.entrySet().spliterator())
|
||||
.mapValues(messages -> new ModShowConflicts.Conflict(List.copyOf(messages)))
|
||||
.toMap();
|
||||
return new ModShowConflicts(map, ModCommand.psiUpdate(anInterface,
|
||||
(writableInterface, updater) ->
|
||||
convertInterfaceToClass(writableInterface, inheritors, updater)));
|
||||
return new ModShowConflicts(map)
|
||||
.andThen(ModCommand.psiUpdate(anInterface,
|
||||
(writableInterface, updater) ->
|
||||
convertInterfaceToClass(writableInterface, inheritors, updater)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -69,7 +69,8 @@ public class MakeClassFinalFix extends ModCommandQuickFix {
|
||||
});
|
||||
}
|
||||
ModShowConflicts.Conflict conflict = new ModShowConflicts.Conflict(conflictMessages);
|
||||
return new ModShowConflicts(Map.of(containingClass, conflict), ModCommand.psiUpdate(modifierList, list -> doMakeFinal(list)));
|
||||
return new ModShowConflicts(Map.of(containingClass, conflict))
|
||||
.andThen(ModCommand.psiUpdate(modifierList, list -> doMakeFinal(list)));
|
||||
}
|
||||
|
||||
private static void doMakeFinal(PsiModifierList modifierList) {
|
||||
|
||||
@@ -15,10 +15,8 @@ import java.util.Set;
|
||||
* Not executed in batch; preview shows next step automatically (it must be computed before conflicts are shown).
|
||||
*
|
||||
* @param conflicts conflicts to show
|
||||
* @param nextStep next step to execute if user agrees; not executed if user cancels on conflict view
|
||||
*/
|
||||
public record ModShowConflicts(@NotNull Map<@NotNull PsiElement, @NotNull Conflict> conflicts,
|
||||
@NotNull ModCommand nextStep) implements ModCommand {
|
||||
public record ModShowConflicts(@NotNull Map<@NotNull PsiElement, @NotNull Conflict> conflicts) implements ModCommand {
|
||||
/**
|
||||
* Conflict description
|
||||
* @param messages list of user-readable messages that describe the problem
|
||||
@@ -28,11 +26,6 @@ public record ModShowConflicts(@NotNull Map<@NotNull PsiElement, @NotNull Confli
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return conflicts().isEmpty() && nextStep().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull VirtualFile> modifiedFiles() {
|
||||
return nextStep.modifiedFiles();
|
||||
return conflicts().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -141,9 +141,6 @@ public class ModCommandServiceImpl implements ModCommandService {
|
||||
else if (command instanceof ModChooseMember target) {
|
||||
return getPreview(target.nextCommand().apply(target.defaultSelection()), context);
|
||||
}
|
||||
else if (command instanceof ModShowConflicts showConflicts) {
|
||||
return getPreview(showConflicts.nextStep(), context);
|
||||
}
|
||||
else if (command instanceof ModDisplayMessage message) {
|
||||
if (message.kind() == ModDisplayMessage.MessageKind.ERROR) {
|
||||
return new IntentionPreviewInfo.Html(new HtmlBuilder().append(
|
||||
|
||||
+17
-19
@@ -79,7 +79,7 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
@Override
|
||||
public void executeInteractively(@NotNull ActionContext context, @NotNull ModCommand command, @Nullable Editor editor) {
|
||||
if (!ensureWritable(context.project(), command)) return;
|
||||
doExecuteInteractively(context, command, editor);
|
||||
doExecuteInteractively(context, command, ModCommand.nop(), editor);
|
||||
}
|
||||
|
||||
private static boolean ensureWritable(@NotNull Project project, @NotNull ModCommand command) {
|
||||
@@ -97,7 +97,7 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
|
||||
private BatchExecutionResult doExecuteInBatch(@NotNull ActionContext context, @NotNull ModCommand command) {
|
||||
Project project = context.project();
|
||||
if (command instanceof ModNothing) {
|
||||
if (command.isEmpty()) {
|
||||
return Result.NOTHING;
|
||||
}
|
||||
if (command instanceof ModUpdateFileText upd) {
|
||||
@@ -131,10 +131,7 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
command instanceof ModStartTemplate || command instanceof ModUpdateSystemOptions) {
|
||||
return Result.INTERACTIVE;
|
||||
}
|
||||
if (command instanceof ModShowConflicts showConflicts) {
|
||||
if (showConflicts.conflicts().isEmpty()) {
|
||||
return executeInBatch(context, showConflicts.nextStep());
|
||||
}
|
||||
if (command instanceof ModShowConflicts) {
|
||||
return Result.CONFLICTS;
|
||||
}
|
||||
if (command instanceof ModDisplayMessage message) {
|
||||
@@ -161,7 +158,8 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
return executeInBatch(context, next);
|
||||
}
|
||||
|
||||
private boolean doExecuteInteractively(@NotNull ActionContext context, @NotNull ModCommand command, @Nullable Editor editor) {
|
||||
private boolean doExecuteInteractively(@NotNull ActionContext context, @NotNull ModCommand command, @NotNull ModCommand tail,
|
||||
@Nullable Editor editor) {
|
||||
Project project = context.project();
|
||||
if (command instanceof ModUpdateFileText upd) {
|
||||
return executeUpdate(project, upd);
|
||||
@@ -203,7 +201,7 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
return executeDelete(project, deleteFile);
|
||||
}
|
||||
if (command instanceof ModShowConflicts showConflicts) {
|
||||
return executeShowConflicts(context, showConflicts, editor);
|
||||
return executeShowConflicts(context, showConflicts, editor, tail);
|
||||
}
|
||||
if (command instanceof ModStartTemplate startTemplate) {
|
||||
return executeStartTemplate(context, startTemplate, editor);
|
||||
@@ -356,17 +354,14 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean executeShowConflicts(@NotNull ActionContext context, @NotNull ModShowConflicts conflicts, @Nullable Editor editor) {
|
||||
private boolean executeShowConflicts(@NotNull ActionContext context, @NotNull ModShowConflicts conflicts, @Nullable Editor editor,
|
||||
@NotNull ModCommand tail) {
|
||||
MultiMap<PsiElement, String> conflictData = new MultiMap<>();
|
||||
conflicts.conflicts().forEach((e, c) -> conflictData.put(e, c.messages()));
|
||||
if (!conflictData.isEmpty()) {
|
||||
var conflictsDialog =
|
||||
new ConflictsDialog(context.project(), conflictData, () -> doExecuteInteractively(context, conflicts.nextStep(), editor));
|
||||
if (!conflictsDialog.showAndGet()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return doExecuteInteractively(context, conflicts.nextStep(), editor);
|
||||
if (conflictData.isEmpty()) return true;
|
||||
var conflictsDialog =
|
||||
new ConflictsDialog(context.project(), conflictData, () -> doExecuteInteractively(context, tail, ModCommand.nop(), editor));
|
||||
return conflictsDialog.showAndGet();
|
||||
}
|
||||
|
||||
private static boolean executeCopyToClipboard(@NotNull ModCopyToClipboard clipboard) {
|
||||
@@ -641,8 +636,11 @@ public class ModCommandExecutorImpl implements ModCommandExecutor {
|
||||
}
|
||||
|
||||
private boolean executeComposite(@NotNull ActionContext context, ModCompositeCommand cmp, @Nullable Editor editor) {
|
||||
for (ModCommand command : cmp.commands()) {
|
||||
if (!doExecuteInteractively(context, command, editor)) {
|
||||
List<@NotNull ModCommand> commands = cmp.commands();
|
||||
int size = commands.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
ModCommand command = commands.get(i);
|
||||
if (!doExecuteInteractively(context, command, new ModCompositeCommand(commands.subList(i + 1, size)), editor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user