use of org.sonar.java.se.symbolicvalues.RelationalSymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_learned_constraint_binary_SV.
@Test
public void test_learned_constraint_binary_SV() {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
RelationalSymbolicValue relation = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.EQUAL);
SymbolicValueTestUtil.computedFrom(relation, sv1, sv2);
ProgramState parent = ProgramState.EMPTY_STATE;
ProgramState child = ProgramState.EMPTY_STATE.addConstraint(relation, BooleanConstraint.TRUE);
Set<LearnedConstraint> learnedConstraints = child.learnedConstraints(parent);
assertThat(learnedConstraints).hasSize(1);
Constraint relationConstraint = Iterables.getOnlyElement(learnedConstraints).constraint();
assertThat(relationConstraint).isEqualTo(BooleanConstraint.TRUE);
}
use of org.sonar.java.se.symbolicvalues.RelationalSymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_setting_constraint_on_relational_sv.
@Test
public void test_setting_constraint_on_relational_sv() throws Exception {
RelationalSymbolicValue rel = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.EQUAL);
SymbolicValueTestUtil.computedFrom(rel, new SymbolicValue(), new SymbolicValue());
assertThatThrownBy(() -> ProgramState.EMPTY_STATE.addConstraint(rel, BooleanConstraint.FALSE)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Relations stored in PS should always use TRUE constraint");
}
use of org.sonar.java.se.symbolicvalues.RelationalSymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_adding_constraint_transitively.
@Test
public void test_adding_constraint_transitively() throws Exception {
ProgramState ps = ProgramState.EMPTY_STATE;
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
RelationalSymbolicValue relSV = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.EQUAL);
SymbolicValueTestUtil.computedFrom(relSV, sv1, sv2);
ps = ps.addConstraint(relSV, BooleanConstraint.TRUE);
UnclosedResourcesCheck.ResourceConstraint constraint = UnclosedResourcesCheck.ResourceConstraint.OPEN;
ps = ps.addConstraintTransitively(sv1, constraint);
assertThat(ps.getConstraint(sv2, constraint.getClass())).isEqualTo(constraint);
}
use of org.sonar.java.se.symbolicvalues.RelationalSymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createRelationalSymbolicValue.
private static RelationalSymbolicValue createRelationalSymbolicValue(Kind kind, List<ProgramState.SymbolicValueSymbol> computedFrom) {
RelationalSymbolicValue result = new RelationalSymbolicValue(kind);
result.computedFrom(computedFrom);
return result;
}
use of org.sonar.java.se.symbolicvalues.RelationalSymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createMethodSymbolicValue.
public SymbolicValue createMethodSymbolicValue(MethodInvocationTree syntaxNode, List<ProgramState.SymbolicValueSymbol> values) {
SymbolicValue result;
if (ExplodedGraphWalker.EQUALS_METHODS.anyMatch(syntaxNode)) {
result = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.METHOD_EQUALS);
ProgramState.SymbolicValueSymbol leftOp = values.get(1);
ProgramState.SymbolicValueSymbol rightOp = values.get(0);
result.computedFrom(ImmutableList.of(rightOp, leftOp));
} else {
result = createDefaultSymbolicValue();
}
return result;
}
Aggregations