mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[mod-command] InvertIfConditionAction: ModCommandAction
GitOrigin-RevId: 328140468ee5e5370d3c87835c72a06841dc1d22
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f12056a05
commit
91afaf57ef
+13
-13
@@ -1,10 +1,10 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.codeInspection.EditorUpdater;
|
||||
import com.intellij.codeInspection.PsiUpdateModCommandAction;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
@@ -23,13 +23,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
public class InvertIfConditionAction extends PsiUpdateModCommandAction<PsiElement> {
|
||||
private static final Logger LOG = Logger.getInstance(InvertIfConditionAction.class);
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public InvertIfConditionAction() {
|
||||
super(PsiElement.class);
|
||||
}
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
@Override
|
||||
protected @Nullable Presentation getPresentation(@NotNull ActionContext context, @NotNull PsiElement element) {
|
||||
return isAvailable(element, context.offset()) ? Presentation.of(getFamilyName()) : null;
|
||||
}
|
||||
|
||||
private static boolean isAvailable(@NotNull PsiElement element, int offset) {
|
||||
final PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class);
|
||||
if (ifStatement == null) return false;
|
||||
final PsiExpression condition = ifStatement.getCondition();
|
||||
@@ -68,12 +74,6 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
return startThenOffset >= 0 && afterIfOffset >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -81,7 +81,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
protected void invoke(@NotNull ActionContext context, @NotNull PsiElement element, @NotNull EditorUpdater updater) {
|
||||
PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class);
|
||||
|
||||
LOG.assertTrue(ifStatement != null);
|
||||
|
||||
@@ -9,7 +9,7 @@ class A {
|
||||
if (!b) {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user