use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class ParameterNullnessCheck method checkPreStatement.
@Override
public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) {
ProgramState state = context.getState();
if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) syntaxNode;
checkParameters(mit, mit.symbol(), mit.arguments(), state);
} else if (syntaxNode.is(Tree.Kind.NEW_CLASS)) {
NewClassTree nct = (NewClassTree) syntaxNode;
checkParameters(nct, nct.constructorSymbol(), nct.arguments(), state);
}
return state;
}
use of org.sonar.java.se.ProgramState 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;
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class RelationalSymbolicValue method copyConstraintFromTo.
private List<ProgramState> copyConstraintFromTo(SymbolicValue from, SymbolicValue to, ProgramState programState, Set<RelationalSymbolicValue> knownRelations) {
List<ProgramState> states = new ArrayList<>();
states.add(programState);
ConstraintsByDomain leftConstraints = programState.getConstraints(from);
if (leftConstraints == null) {
return states;
}
leftConstraints.forEach((d, c) -> {
Constraint constraint = c.copyOver(kind);
if (constraint != null) {
List<ProgramState> newStates = applyConstraint(constraint, to, states, knownRelations);
states.clear();
states.addAll(newStates);
}
});
return states;
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class RelationalSymbolicValue method getNewProgramStates.
private static List<ProgramState> getNewProgramStates(ProgramState initialProgramState, Set<RelationalSymbolicValue> newRelations, Set<RelationalSymbolicValue> knownRelations) {
List<ProgramState> programStates = new ArrayList<>();
programStates.add(initialProgramState);
for (RelationalSymbolicValue relationalSymbolicValue : newRelations) {
List<ProgramState> intermediateStates = new ArrayList<>();
for (ProgramState programState : programStates) {
intermediateStates.addAll(relationalSymbolicValue.copyAllConstraints(programState, knownRelations));
}
programStates = intermediateStates;
}
return programStates;
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class HappyPathYield method statesAfterInvocation.
@Override
public Stream<ProgramState> statesAfterInvocation(List<SymbolicValue> invocationArguments, List<Type> invocationTypes, ProgramState programState, Supplier<SymbolicValue> svSupplier) {
Stream<ProgramState> results = parametersAfterInvocation(invocationArguments, invocationTypes, programState);
// applied all constraints from parameters, stack return value
SymbolicValue sv;
if (resultIndex < 0 || resultIndex == invocationArguments.size()) {
// if returnIndex is the size of invocationArguments : returning vararg parameter on a call with no elements specified
sv = svSupplier.get();
} else {
// returned SV is the same as one of the arguments.
sv = invocationArguments.get(resultIndex);
}
// sv can be null if method is void
if (sv != null) {
results = results.map(s -> s.stackValue(sv));
if (resultConstraint != null) {
results = results.map(s -> s.addConstraints(sv, resultConstraint));
}
}
return results.distinct();
}
Aggregations