Search in sources :

Example 1 with NOT_CONSUMED

use of org.sonar.java.se.checks.StreamConsumedCheck.StreamPipelineConstraint.NOT_CONSUMED in project sonar-java by SonarSource.

the class StreamNotConsumedCheck method checkEndOfExecutionPath.

@Override
public void checkEndOfExecutionPath(CheckerContext context, ConstraintManager constraintManager) {
    if (context.getState().exitValue() instanceof SymbolicValue.ExceptionalSymbolicValue) {
        // don't report when exiting on exception
        return;
    }
    ProgramState state = context.getState();
    List<SymbolicValue> notConsumed = state.getValuesWithConstraints(NOT_CONSUMED);
    notConsumed.forEach(sv -> {
        Set<Flow> flows = FlowComputation.flow(context.getNode(), Collections.singleton(sv), NOT_CONSUMED::equals, NOT_CONSUMED::equals, Collections.singletonList(StreamConsumedCheck.StreamPipelineConstraint.class), Collections.emptySet());
        Flow flow = flows.iterator().next();
        JavaFileScannerContext.Location location = flow.elements().get(0);
        reportIssue(location.syntaxNode, "Refactor the code so this stream pipeline is used.");
    });
}
Also used : NOT_CONSUMED(org.sonar.java.se.checks.StreamConsumedCheck.StreamPipelineConstraint.NOT_CONSUMED) JavaFileScannerContext(org.sonar.plugins.java.api.JavaFileScannerContext) ProgramState(org.sonar.java.se.ProgramState) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Flow(org.sonar.java.se.Flow)

Aggregations

Flow (org.sonar.java.se.Flow)1 ProgramState (org.sonar.java.se.ProgramState)1 NOT_CONSUMED (org.sonar.java.se.checks.StreamConsumedCheck.StreamPipelineConstraint.NOT_CONSUMED)1 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)1 JavaFileScannerContext (org.sonar.plugins.java.api.JavaFileScannerContext)1