use of com.intellij.codeInspection.dataFlow.value.DfaValue in project intellij-community by JetBrains.
the class SwapInstruction method accept.
@Override
public DfaInstructionState[] accept(DataFlowRunner runner, DfaMemoryState stateBefore, InstructionVisitor visitor) {
final DfaValue a = stateBefore.pop();
final DfaValue b = stateBefore.pop();
stateBefore.push(a);
stateBefore.push(b);
Instruction nextInstruction = runner.getInstruction(getIndex() + 1);
return new DfaInstructionState[] { new DfaInstructionState(nextInstruction, stateBefore) };
}
use of com.intellij.codeInspection.dataFlow.value.DfaValue in project intellij-community by JetBrains.
the class EqClass method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("(");
for (int i = 0; i < size(); i++) {
if (i > 0)
buf.append(", ");
int value = get(i);
DfaValue dfaValue = myFactory.getValue(value);
buf.append(dfaValue);
}
buf.append(")");
return buf.toString();
}
use of com.intellij.codeInspection.dataFlow.value.DfaValue in project intellij-community by JetBrains.
the class InstructionVisitor method visitConditionalGoto.
public DfaInstructionState[] visitConditionalGoto(ConditionalGotoInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
DfaValue cond = memState.pop();
DfaValue condTrue;
DfaValue condFalse;
if (instruction.isNegated()) {
condFalse = cond;
condTrue = cond.createNegated();
} else {
condTrue = cond;
condFalse = cond.createNegated();
}
if (condTrue == runner.getFactory().getConstFactory().getTrue()) {
markBranchReachable(instruction, true);
return new DfaInstructionState[] { new DfaInstructionState(runner.getInstruction(instruction.getOffset()), memState) };
}
if (condFalse == runner.getFactory().getConstFactory().getTrue()) {
markBranchReachable(instruction, false);
return nextInstruction(instruction, runner, memState);
}
ArrayList<DfaInstructionState> result = new ArrayList<>();
DfaMemoryState thenState = memState.createCopy();
DfaMemoryState elseState = memState.createCopy();
if (thenState.applyCondition(condTrue)) {
result.add(new DfaInstructionState(runner.getInstruction(instruction.getOffset()), thenState));
markBranchReachable(instruction, true);
}
if (elseState.applyCondition(condFalse)) {
result.add(new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), elseState));
markBranchReachable(instruction, false);
}
return result.toArray(new DfaInstructionState[result.size()]);
}
use of com.intellij.codeInspection.dataFlow.value.DfaValue in project intellij-community by JetBrains.
the class InstructionVisitor method visitNot.
public DfaInstructionState[] visitNot(NotInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
DfaValue dfaValue = memState.pop();
dfaValue = dfaValue.createNegated();
memState.push(dfaValue);
return nextInstruction(instruction, runner, memState);
}
use of com.intellij.codeInspection.dataFlow.value.DfaValue in project intellij-community by JetBrains.
the class DfaUtil method inferMethodNullity.
@NotNull
public static Nullness inferMethodNullity(PsiMethod method) {
final PsiCodeBlock body = method.getBody();
if (body == null || PsiUtil.resolveClassInType(method.getReturnType()) == null) {
return Nullness.UNKNOWN;
}
final AtomicBoolean hasNulls = new AtomicBoolean();
final AtomicBoolean hasNotNulls = new AtomicBoolean();
final AtomicBoolean hasUnknowns = new AtomicBoolean();
final StandardDataFlowRunner dfaRunner = new StandardDataFlowRunner();
final RunnerResult rc = dfaRunner.analyzeMethod(body, new StandardInstructionVisitor() {
@Override
public DfaInstructionState[] visitCheckReturnValue(CheckReturnValueInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
DfaValue returned = memState.peek();
if (memState.isNull(returned)) {
hasNulls.set(true);
} else if (memState.isNotNull(returned)) {
hasNotNulls.set(true);
} else {
hasUnknowns.set(true);
}
return super.visitCheckReturnValue(instruction, runner, memState);
}
});
if (rc == RunnerResult.OK) {
if (hasNulls.get()) {
return InferenceFromSourceUtil.suppressNullable(method) ? Nullness.UNKNOWN : Nullness.NULLABLE;
}
if (hasNotNulls.get() && !hasUnknowns.get()) {
return Nullness.NOT_NULL;
}
}
return Nullness.UNKNOWN;
}
Aggregations