mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: support (i)++ (IDEA-146805)
This commit is contained in:
+24
-25
@@ -1217,7 +1217,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateBoxingUnboxingInstructionFor(PsiExpression expression, PsiType expectedType) {
|
||||
private void generateBoxingUnboxingInstructionFor(@NotNull PsiExpression expression, PsiType expectedType) {
|
||||
if (expectedType == PsiType.VOID) return;
|
||||
|
||||
PsiType exprType = expression.getType();
|
||||
@@ -1617,23 +1617,18 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
@Override public void visitPostfixExpression(PsiPostfixExpression expression) {
|
||||
startElement(expression);
|
||||
|
||||
PsiExpression operand = expression.getOperand();
|
||||
operand.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(operand, PsiType.INT);
|
||||
PsiExpression operand = PsiUtil.skipParenthesizedExprDown(expression.getOperand());
|
||||
if (operand != null) {
|
||||
operand.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(operand, PsiType.INT);
|
||||
} else {
|
||||
pushUnknown();
|
||||
}
|
||||
|
||||
addInstruction(new PopInstruction());
|
||||
pushUnknown();
|
||||
|
||||
if (operand instanceof PsiReferenceExpression) {
|
||||
PsiVariable psiVariable = DfaValueFactory.resolveUnqualifiedVariable((PsiReferenceExpression)expression.getOperand());
|
||||
if (psiVariable != null) {
|
||||
DfaVariableValue dfaVariable = myFactory.getVarFactory().createVariableValue(psiVariable, false);
|
||||
addInstruction(new FlushVariableInstruction(dfaVariable));
|
||||
if (psiVariable instanceof PsiField) {
|
||||
addInstruction(new FlushVariableInstruction(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
flushIncrementedValue(operand);
|
||||
|
||||
finishElement(expression);
|
||||
}
|
||||
@@ -1643,7 +1638,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
|
||||
DfaValue dfaValue = myFactory.createValue(expression);
|
||||
if (dfaValue == null) {
|
||||
PsiExpression operand = expression.getOperand();
|
||||
PsiExpression operand = PsiUtil.skipParenthesizedExprDown(expression.getOperand());
|
||||
|
||||
if (operand == null) {
|
||||
pushUnknown();
|
||||
@@ -1660,16 +1655,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
addInstruction(new PopInstruction());
|
||||
pushUnknown();
|
||||
|
||||
if (operand instanceof PsiReferenceExpression) {
|
||||
PsiVariable psiVariable = DfaValueFactory.resolveUnqualifiedVariable((PsiReferenceExpression)operand);
|
||||
if (psiVariable != null) {
|
||||
DfaVariableValue dfaVariable = myFactory.getVarFactory().createVariableValue(psiVariable, false);
|
||||
addInstruction(new FlushVariableInstruction(dfaVariable));
|
||||
if (psiVariable instanceof PsiField) {
|
||||
addInstruction(new FlushVariableInstruction(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
flushIncrementedValue(operand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1680,6 +1666,19 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
finishElement(expression);
|
||||
}
|
||||
|
||||
private void flushIncrementedValue(@Nullable PsiExpression operand) {
|
||||
if (operand instanceof PsiReferenceExpression) {
|
||||
PsiVariable psiVariable = DfaValueFactory.resolveUnqualifiedVariable((PsiReferenceExpression)operand);
|
||||
if (psiVariable != null) {
|
||||
DfaVariableValue dfaVariable = myFactory.getVarFactory().createVariableValue(psiVariable, false);
|
||||
addInstruction(new FlushVariableInstruction(dfaVariable));
|
||||
if (psiVariable instanceof PsiField) {
|
||||
addInstruction(new FlushVariableInstruction(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
startElement(expression);
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 30; (i)++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,6 +245,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testDoubleCCEWarning() { doTest(); }
|
||||
public void testLongCircuitOperations() { doTest(); }
|
||||
public void testUnconditionalForLoop() { doTest(); }
|
||||
public void testIncrementParenthesized() { doTest(); }
|
||||
public void testAnonymousMethodIndependence() { doTest(); }
|
||||
public void testAnonymousFieldIndependence() { doTest(); }
|
||||
public void testNoConfusionWithAnonymousConstantInitializer() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user