mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86160 Constant conditions & exceptions: no highlighting when one is expected
This commit is contained in:
@@ -1075,38 +1075,33 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
startElement(expression);
|
||||
|
||||
DfaValue dfaValue = myFactory.create(expression);
|
||||
if (dfaValue != null) {
|
||||
addInstruction(new PushInstruction(dfaValue, expression));
|
||||
}
|
||||
else {
|
||||
PsiExpression condition = expression.getCondition();
|
||||
PsiExpression condition = expression.getCondition();
|
||||
|
||||
PsiExpression thenExpression = expression.getThenExpression();
|
||||
PsiExpression elseExpression = expression.getElseExpression();
|
||||
PsiExpression thenExpression = expression.getThenExpression();
|
||||
PsiExpression elseExpression = expression.getElseExpression();
|
||||
|
||||
final int elseOffset = elseExpression == null ? getEndOffset(expression) - 1 : getStartOffset(elseExpression);
|
||||
if (thenExpression != null) {
|
||||
condition.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(condition, PsiType.BOOLEAN);
|
||||
PsiType type = expression.getType();
|
||||
addInstruction(new ConditionalGotoInstruction(elseOffset, true, condition));
|
||||
thenExpression.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(thenExpression,type);
|
||||
final int elseOffset = elseExpression == null ? getEndOffset(expression) - 1 : getStartOffset(elseExpression);
|
||||
if (thenExpression != null) {
|
||||
condition.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(condition, PsiType.BOOLEAN);
|
||||
PsiType type = expression.getType();
|
||||
addInstruction(new ConditionalGotoInstruction(elseOffset, true, condition));
|
||||
thenExpression.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(thenExpression,type);
|
||||
|
||||
addInstruction(new GotoInstruction(getEndOffset(expression)));
|
||||
addInstruction(new GotoInstruction(getEndOffset(expression)));
|
||||
|
||||
if (elseExpression != null) {
|
||||
elseExpression.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(elseExpression,type);
|
||||
}
|
||||
else {
|
||||
pushUnknown();
|
||||
}
|
||||
if (elseExpression != null) {
|
||||
elseExpression.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(elseExpression,type);
|
||||
}
|
||||
else {
|
||||
pushUnknown();
|
||||
}
|
||||
}
|
||||
else {
|
||||
pushUnknown();
|
||||
}
|
||||
|
||||
finishElement(expression);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class Foo {
|
||||
public void foo() {
|
||||
final boolean flag = true;
|
||||
|
||||
bar(<warning descr="Condition 'flag' is always 'true'">flag</warning> ? "a" : "b",
|
||||
<warning descr="Condition 'flag' is always 'true'">flag</warning> ? new String[]{"aa"} : new String[]{"bb"}
|
||||
);
|
||||
}
|
||||
|
||||
void bar(String b, String[] a) {
|
||||
}
|
||||
}
|
||||
@@ -62,5 +62,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
|
||||
public void testIDEA84489() throws Throwable { doTest(); }
|
||||
public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); }
|
||||
public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user