use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class CheckerDispatcher method executeCheckPreStatement.
public boolean executeCheckPreStatement(Instruction instruction) {
this.currentInstruction = instruction;
ProgramState ps;
for (BytecodeSECheck checker : checks) {
ps = checker.checkPreStatement(this, instruction);
if (ps == null) {
return false;
}
explodedGraphWalker.programState = ps;
}
return true;
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class CheckerDispatcher method addTransition.
public void addTransition(ProgramState state) {
ProgramState oldState = explodedGraphWalker.programState;
explodedGraphWalker.programState = state;
currentCheckerIndex++;
executePost();
currentCheckerIndex--;
explodedGraphWalker.programState = oldState;
this.transition = true;
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class RelationalSymbolicValueTest method test_constraint_copy_of_sv_with_no_constraints_is_symmetric.
@Test
public void test_constraint_copy_of_sv_with_no_constraints_is_symmetric() throws Exception {
ProgramState ps = ProgramState.EMPTY_STATE;
SymbolicValue svZero = new SymbolicValue();
ps = Iterables.getOnlyElement(svZero.setConstraint(ps, ZERO));
SymbolicValue sv = new SymbolicValue();
RelationalSymbolicValue neq = new RelationalSymbolicValue(NOT_EQUAL, svZero, sv);
ProgramState psWithNeq = setTrue(ps, neq);
assertThat(psWithNeq.getConstraint(svZero, ZERO.getClass())).isEqualTo(ZERO);
neq = new RelationalSymbolicValue(NOT_EQUAL, sv, svZero);
psWithNeq = setTrue(ps, neq);
assertThat(psWithNeq.getConstraint(svZero, ZERO.getClass())).isEqualTo(ZERO);
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class RelationalSymbolicValueTest method test_conjuction_equal.
@Test
public void test_conjuction_equal() throws Exception {
RelationalSymbolicValue aLEb = relationalSV(Tree.Kind.LESS_THAN_OR_EQUAL_TO, a, b);
RelationalSymbolicValue bLEa = relationalSV(Tree.Kind.LESS_THAN_OR_EQUAL_TO, b, a);
RelationalSymbolicValue aEb = relationalSV(Tree.Kind.EQUAL_TO, a, b);
ProgramState state = Iterables.getOnlyElement(aEb.setConstraint(stateWithRelations(aLEb, bLEa), TRUE));
assertThat(state.getConstraint(aEb, BooleanConstraint.class)).isEqualTo(TRUE);
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class RelationalSymbolicValueTest method test_constraint_copy_of_not_null_constraint.
@Test
public void test_constraint_copy_of_not_null_constraint() throws Exception {
ProgramState ps = ProgramState.EMPTY_STATE;
SymbolicValue svNotNull = new SymbolicValue();
ps = Iterables.getOnlyElement(svNotNull.setConstraint(ps, ObjectConstraint.NOT_NULL));
SymbolicValue sv = new SymbolicValue();
// sv != NOT_NULL
RelationalSymbolicValue neq = new RelationalSymbolicValue(NOT_EQUAL, svNotNull, sv);
ProgramState result = setTrue(ps, neq);
assertNoConstraints(result, sv);
// sv != NULL
neq = new RelationalSymbolicValue(NOT_EQUAL, NULL_LITERAL, sv);
result = setTrue(ps, neq);
assertThat(result.getConstraint(sv, ObjectConstraint.class)).isEqualTo(ObjectConstraint.NOT_NULL);
// sv == NULL
RelationalSymbolicValue eq = new RelationalSymbolicValue(EQUAL, NULL_LITERAL, sv);
result = setTrue(ps, eq);
assertNullConstraint(result, sv);
// sv == NOT_NULL
eq = new RelationalSymbolicValue(METHOD_EQUALS, sv, svNotNull);
result = setTrue(ps, eq);
assertThat(result.getConstraint(sv, ObjectConstraint.class)).isEqualTo(ObjectConstraint.NOT_NULL);
}
Aggregations