mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExpandBracketsIntention: cr fixes (IDEA-CR-43518):
1. changed division expansion to non-integer types only 2. enabled start in write action when only one expansion is possible
This commit is contained in:
+2
@@ -5,6 +5,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiPrecedenceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -146,6 +147,7 @@ class DistributiveExpression extends ExpandableExpression {
|
||||
if (polyadicExpression == null || !JavaTokenType.DIV.equals(polyadicExpression.getOperationTokenType())) return expression;
|
||||
PsiExpression operand = expression.getOperand();
|
||||
if (polyadicExpression.getTokenBeforeOperand(operand) != null) return null;
|
||||
if (TypeConversionUtil.isIntegralNumberType(polyadicExpression.getType())) return null;
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -24,10 +24,13 @@ import java.util.List;
|
||||
|
||||
public class ExpandBracketsIntention extends BaseElementAtCaretIntentionAction {
|
||||
|
||||
private boolean myStartInWriteAction = false;
|
||||
|
||||
private static final Pass<PsiParenthesizedExpression> EXPAND_CALLBACK = new Pass<PsiParenthesizedExpression>() {
|
||||
@Override
|
||||
public void pass(@NotNull PsiParenthesizedExpression expression) {
|
||||
WriteCommandAction.writeCommandAction(expression.getProject(), expression.getContainingFile())
|
||||
.withName(getName())
|
||||
.run(() -> replaceExpression(expression));
|
||||
}
|
||||
};
|
||||
@@ -36,24 +39,30 @@ public class ExpandBracketsIntention extends BaseElementAtCaretIntentionAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
return getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
private static String getName() {
|
||||
return IntentionPowerPackBundle.defaultableMessage("expand.brackets.intention.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
return myStartInWriteAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
List<PsiParenthesizedExpression> possibleInnerExpressions = getPossibleInnerExpressions(element);
|
||||
return possibleInnerExpressions != null && possibleInnerExpressions.size() > 0;
|
||||
if (possibleInnerExpressions == null || possibleInnerExpressions.isEmpty()) return false;
|
||||
myStartInWriteAction = possibleInnerExpressions.size() == 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +74,7 @@ public class ExpandBracketsIntention extends BaseElementAtCaretIntentionAction {
|
||||
|
||||
private static void processInnerExpression(@Nullable Editor editor, @NotNull List<PsiParenthesizedExpression> expressions) {
|
||||
if (expressions.size() == 1) {
|
||||
EXPAND_CALLBACK.pass(expressions.get(0));
|
||||
replaceExpression(expressions.get(0));
|
||||
return;
|
||||
}
|
||||
if (expressions.isEmpty() || editor == null) return;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
class Test {
|
||||
void distributiveTest(int a, int b, int c, int d) {
|
||||
void distributiveTest(int a, int b, int c, int d, double cc) {
|
||||
int e = /*1*/a * (b /*2*/<caret>+ c);
|
||||
int f = -/*1*/a * -/*2*/(b - -/*3*/c<caret>);
|
||||
int g = /*1*/a * (b +<caret> c) * d;
|
||||
@@ -11,7 +11,7 @@ class Test {
|
||||
int m = a | (-c & <caret>b);
|
||||
int n = a & (c | <caret>b);
|
||||
int o = 2 * (3 - -a <caret>/ -/*1*/b * -/*2*/c);
|
||||
int p = (a <caret>+/*1*/ b) /*2*// c;
|
||||
double p = (a <caret>+/*1*/ b) /*2*// cc;
|
||||
}
|
||||
|
||||
void distributiveBooleanTest(boolean a, boolean b, boolean c, boolean d) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
class Test {
|
||||
void distributiveTest(int a, int b, int c, int d) {
|
||||
void distributiveTest(int a, int b, int c, int d, double cc) {
|
||||
/*2*/
|
||||
int e = /*1*/a * b + a * c;
|
||||
/*1*/
|
||||
@@ -21,7 +21,7 @@ class Test {
|
||||
int o = 2 * 3 + 2 * a / b * c;
|
||||
/*1*/
|
||||
/*2*/
|
||||
int p = a / c + b / c;
|
||||
double p = a / cc + b / cc;
|
||||
}
|
||||
|
||||
void distributiveBooleanTest(boolean a, boolean b, boolean c, boolean d) {
|
||||
|
||||
Reference in New Issue
Block a user