summaryrefslogtreecommitdiff
path: root/java/java-analysis-impl/src/com/intellij/codeInspection
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-08-21 17:06:11 -0700
committerTor Norbye <tnorbye@google.com>2013-08-21 17:06:22 -0700
commitce0245dfc4d045479a910a98a0f8655e1ed1419a (patch)
tree438440769eaa8f0073f80d90fb47467a9abe03ce /java/java-analysis-impl/src/com/intellij/codeInspection
parentd34b4c8d74407f5b2be1a344e41f2ecdeb25f4fe (diff)
downloadidea-ce0245dfc4d045479a910a98a0f8655e1ed1419a.tar.gz
Snapshot 5755a4daa62e3fe56827696be38afb29f7fa297b from master branch of git://git.jetbrains.org/idea/community.git
5755a4d: 2013-08-21 Bas Leijdekkers - IDEA-112398 (Yellow code is green: Inspection "Overly broad 'catch' clause" and RuntimeException) 21e3c90: 2013-08-21 Gregory.Shrago - EditorImpl-based table cell renderer 8f24e2f: 2013-08-21 Maxim.Mossienko - fix performance regression 0ea191f: 2013-08-21 peter - IDEA-112373 Rectangular selection paste bug e10ed95: 2013-08-21 peter - IDEA-112377 Caret moving problem inside "Find" input e21aa9a: 2013-08-21 peter - allow stubs built from ast be gc'ed 78ecf28: 2013-08-21 peter - IDEA-112358 'Constant Conditions' does not understand non-short-circuit 'or' dbb57c5: 2013-08-21 Roman Shevchenko - Xinerama suppression reverted b81debe: 2013-08-21 Anna Kozlova - NPE c94daa8: 2013-08-21 Anna Kozlova - build graph: cleanup done amount if exception is thrown and logged (IDEA-112290) ac9c969: 2013-08-21 Anna Kozlova - definitions search: allow to provide additional information through search parameters: speed up Ctrl-Shift-I by reduction by type hierarchy (IDEA-109493) 2e10748: 2013-08-21 Maxim.Mossienko - less logging / better comment 6e64688: 2013-08-21 Maxim.Mossienko - NPE 3cd7a98: 2013-08-21 Nadya Zabrodina - Common updateContent method for Merge and UpdateTo dialog moved to HgUiUtil 2bb8b9c: 2013-08-21 Maxim.Mossienko - proper logging 83d01c8: 2013-08-21 Konstantin Bulenkov - fix coverage colors under Darcula Change-Id: I06739ac3637c5ae6459132cc040c874e11244af6
Diffstat (limited to 'java/java-analysis-impl/src/com/intellij/codeInspection')
-rw-r--r--java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java41
1 files changed, 35 insertions, 6 deletions
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
index bf0fc63be2a2..ca214aa5010c 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
@@ -998,14 +998,20 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
}
PsiType type = expression.getType();
if (op == JavaTokenType.ANDAND) {
- generateAndExpression(operands, type);
+ generateAndExpression(operands, type, true);
}
else if (op == JavaTokenType.OROR) {
- generateOrExpression(operands, type);
+ generateOrExpression(operands, type, true);
}
else if (op == JavaTokenType.XOR && PsiType.BOOLEAN.equals(type)) {
generateXorExpression(expression, operands, type);
}
+ else if (op == JavaTokenType.AND && PsiType.BOOLEAN.equals(type)) {
+ generateAndExpression(operands, type, false);
+ }
+ else if (op == JavaTokenType.OR && PsiType.BOOLEAN.equals(type)) {
+ generateOrExpression(operands, type, false);
+ }
else {
generateOther(expression, op, operands, type);
}
@@ -1104,11 +1110,18 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
}
}
- private void generateOrExpression(PsiExpression[] operands, final PsiType exprType) {
+ private void generateOrExpression(PsiExpression[] operands, final PsiType exprType, boolean shortCircuit) {
for (int i = 0; i < operands.length; i++) {
PsiExpression operand = operands[i];
operand.accept(this);
generateBoxingUnboxingInstructionFor(operand, exprType);
+ if (!shortCircuit) {
+ if (i > 0) {
+ combineStackBooleans(false, operand);
+ }
+ continue;
+ }
+
PsiExpression nextOperand = i == operands.length - 1 ? null : operands[i + 1];
if (nextOperand != null) {
addInstruction(new ConditionalGotoInstruction(getStartOffset(nextOperand), true, operand));
@@ -1125,7 +1138,11 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
lExpression.accept(this);
generateBoxingUnboxingInstructionFor(lExpression, exprType);
- ConditionalGotoInstruction toPopAndPushSuccess = new ConditionalGotoInstruction(-1, and, lExpression);
+ combineStackBooleans(and, lExpression);
+ }
+
+ private void combineStackBooleans(boolean and, PsiExpression anchor) {
+ ConditionalGotoInstruction toPopAndPushSuccess = new ConditionalGotoInstruction(-1, and, anchor);
addInstruction(toPopAndPushSuccess);
GotoInstruction overPushSuccess = new GotoInstruction(-1);
addInstruction(overPushSuccess);
@@ -1140,17 +1157,29 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
overPushSuccess.setOffset(pushSuccess.getIndex() + 1);
}
- private void generateAndExpression(PsiExpression[] operands, final PsiType exprType) {
+ private void generateAndExpression(PsiExpression[] operands, final PsiType exprType, boolean shortCircuit) {
List<ConditionalGotoInstruction> branchToFail = new ArrayList<ConditionalGotoInstruction>();
- for (PsiExpression operand : operands) {
+ for (int i = 0; i < operands.length; i++) {
+ PsiExpression operand = operands[i];
operand.accept(this);
generateBoxingUnboxingInstructionFor(operand, exprType);
+ if (!shortCircuit) {
+ if (i > 0) {
+ combineStackBooleans(false, operand);
+ }
+ continue;
+ }
+
ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand);
branchToFail.add(onFail);
addInstruction(onFail);
}
+ if (!shortCircuit) {
+ return;
+ }
+
addInstruction(new PushInstruction(myFactory.getConstFactory().getTrue(), null));
GotoInstruction toSuccess = new GotoInstruction(-1);
addInstruction(toSuccess);