Search in sources :

Example 1 with RelationalSymbolicValue

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);
}
Also used : ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) Constraint(org.sonar.java.se.constraint.Constraint) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Example 2 with RelationalSymbolicValue

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");
}
Also used : RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Example 3 with RelationalSymbolicValue

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);
}
Also used : UnclosedResourcesCheck(org.sonar.java.se.checks.UnclosedResourcesCheck) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Example 4 with RelationalSymbolicValue

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;
}
Also used : RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)

Example 5 with RelationalSymbolicValue

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;
}
Also used : ProgramState(org.sonar.java.se.ProgramState) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue)

Aggregations

RelationalSymbolicValue (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)10 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)7 Test (org.junit.Test)6 ProgramState (org.sonar.java.se.ProgramState)5 BooleanConstraint (org.sonar.java.se.constraint.BooleanConstraint)4 Constraint (org.sonar.java.se.constraint.Constraint)4 ObjectConstraint (org.sonar.java.se.constraint.ObjectConstraint)4 Instruction (org.sonar.java.bytecode.cfg.Instruction)3 ProgramPoint (org.sonar.java.se.ProgramPoint)3 TypedConstraint (org.sonar.java.se.constraint.TypedConstraint)3 BinarySymbolicValue (org.sonar.java.se.symbolicvalues.BinarySymbolicValue)3 UnclosedResourcesCheck (org.sonar.java.se.checks.UnclosedResourcesCheck)1 ConstraintsByDomain (org.sonar.java.se.constraint.ConstraintsByDomain)1