mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
invert condition: wrap with parenthesis according to precedence order (IDEA-98952)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if ((!a || !b) && !c) {
|
||||
System.out.println(1);
|
||||
}
|
||||
else {
|
||||
System.out.println(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if (!a || !b || !c) {
|
||||
System.out.println(1);
|
||||
}
|
||||
else {
|
||||
System.out.println(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if ((!a && !b) || !c) {
|
||||
System.out.println(1);
|
||||
}
|
||||
else {
|
||||
System.out.println(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if (a &<caret>& b || c) {
|
||||
System.out.println(0);
|
||||
} else {
|
||||
System.out.println(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if (a &<caret>& b && c) {
|
||||
System.out.println(0);
|
||||
} else {
|
||||
System.out.println(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Invert If Condition" "true"
|
||||
class Inversion {
|
||||
public void context(boolean a, boolean b, boolean c) {
|
||||
if ((a |<caret>| b) && c) {
|
||||
System.out.println(0);
|
||||
} else {
|
||||
System.out.println(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,15 @@ public class CodeInsightServicesUtil {
|
||||
expression.getTokenBeforeOperand(op).replace(createOperationToken(factory, ourTokenMap[i + (i % 2 == 0 ? 1 : -1)]));
|
||||
}
|
||||
if (tokenType == JavaTokenType.OROR || tokenType == JavaTokenType.ANDAND) {
|
||||
op.replace(invertCondition(op));
|
||||
PsiExpression inverted = invertCondition(op);
|
||||
op.replace(inverted);
|
||||
}
|
||||
}
|
||||
if (tokenType == JavaTokenType.ANDAND && booleanExpression.getParent() instanceof PsiExpression) {
|
||||
final PsiParenthesizedExpression parth = (PsiParenthesizedExpression)factory.createExpressionFromText("(a)", expression);
|
||||
parth.getExpression().replace(expression);
|
||||
return parth;
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user