Search in sources :

Example 1 with BooleanConstraint

use of org.sonar.java.se.constraint.BooleanConstraint in project sonar-java by SonarSource.

the class RelationalSymbolicValue method addNullConstraintsForBooleanWrapper.

private List<ProgramState> addNullConstraintsForBooleanWrapper(ProgramState initialProgramState, List<ProgramState> copiedConstraints) {
    BooleanConstraint leftConstraint = initialProgramState.getConstraint(leftOp, BooleanConstraint.class);
    BooleanConstraint rightConstraint = initialProgramState.getConstraint(rightOp, BooleanConstraint.class);
    if (leftConstraint != null && rightConstraint == null && !isEquality()) {
        List<ProgramState> nullConstraints = copiedConstraints.stream().flatMap(ps -> rightOp.setConstraint(ps, ObjectConstraint.NULL).stream()).map(ps -> ps.removeConstraintsOnDomain(rightOp, BooleanConstraint.class)).collect(Collectors.toList());
        return ImmutableList.<ProgramState>builder().addAll(copiedConstraints).addAll(nullConstraints).build();
    }
    return copiedConstraints;
}
Also used : ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) LESS_THAN(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.LESS_THAN) ProgramState(org.sonar.java.se.ProgramState) Set(java.util.Set) Deque(java.util.Deque) ConstraintsByDomain(org.sonar.java.se.constraint.ConstraintsByDomain) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) GREATER_THAN_OR_EQUAL(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.GREATER_THAN_OR_EQUAL) HashSet(java.util.HashSet) METHOD_EQUALS(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.METHOD_EQUALS) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) Constraint(org.sonar.java.se.constraint.Constraint) ArrayDeque(java.util.ArrayDeque) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) Symbol(org.sonar.plugins.java.api.semantic.Symbol) Nullable(javax.annotation.Nullable) EQUAL(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.EQUAL) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) ProgramState(org.sonar.java.se.ProgramState)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 ProgramState (org.sonar.java.se.ProgramState)1 BooleanConstraint (org.sonar.java.se.constraint.BooleanConstraint)1 Constraint (org.sonar.java.se.constraint.Constraint)1 ConstraintsByDomain (org.sonar.java.se.constraint.ConstraintsByDomain)1 ObjectConstraint (org.sonar.java.se.constraint.ObjectConstraint)1 EQUAL (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.EQUAL)1 GREATER_THAN_OR_EQUAL (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue.Kind.GREATER_THAN_OR_EQUAL)1