mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Java: allow "invert if" in more places and cases
GitOrigin-RevId: f3d942d13ed72b7f94e189bb9d155b64c4603a97
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f2b4d42e14
commit
e39764dd13
@@ -8,7 +8,6 @@ import com.intellij.modcommand.Presentation;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.controlFlow.*;
|
||||
@@ -43,10 +42,6 @@ public final class InvertIfConditionAction extends PsiUpdateModCommandAction<Psi
|
||||
final PsiExpression condition = ifStatement.getCondition();
|
||||
if (condition == null) return false;
|
||||
if (ifStatement.getThenBranch() == null) return false;
|
||||
if (SyntaxTraverser.psiTraverser(condition)
|
||||
.filter(PsiPrefixExpression.class)
|
||||
.filter(prefixExpr -> PsiUtil.skipParenthesizedExprDown(prefixExpr.getOperand()) == null)
|
||||
.first() != null) return false;
|
||||
if (element instanceof PsiKeyword keyword) {
|
||||
if (element.getParent() != ifStatement) {
|
||||
return false;
|
||||
@@ -57,8 +52,8 @@ public final class InvertIfConditionAction extends PsiUpdateModCommandAction<Psi
|
||||
}
|
||||
}
|
||||
else {
|
||||
final TextRange condTextRange = condition.getTextRange();
|
||||
if (condTextRange == null || !condTextRange.contains(offset)) {
|
||||
PsiJavaToken parenth = ifStatement.getRParenth();
|
||||
if (parenth == null || offset > parenth.getTextOffset() + 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
|
||||
class ExpressionExptected {
|
||||
public String validate(boolean b) {
|
||||
if (() || !b) {
|
||||
return null;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
|
||||
class ExpressionExptected {
|
||||
public String validate(boolean b) {
|
||||
if <caret>(!() && b) {
|
||||
return "";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user