use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createBinarySymbolicValue.
public SymbolicValue createBinarySymbolicValue(Tree syntaxNode, List<ProgramState.SymbolicValueSymbol> computedFrom) {
SymbolicValue result;
switch(syntaxNode.kind()) {
case EQUAL_TO:
result = createRelationalSymbolicValue(Kind.EQUAL, computedFrom);
break;
case NOT_EQUAL_TO:
result = createRelationalSymbolicValue(Kind.NOT_EQUAL, computedFrom);
break;
case LESS_THAN:
result = createRelationalSymbolicValue(Kind.LESS_THAN, computedFrom);
break;
case LESS_THAN_OR_EQUAL_TO:
result = createRelationalSymbolicValue(Kind.GREATER_THAN_OR_EQUAL, Lists.reverse(computedFrom));
break;
case GREATER_THAN:
result = createRelationalSymbolicValue(Kind.LESS_THAN, Lists.reverse(computedFrom));
break;
case GREATER_THAN_OR_EQUAL_TO:
result = createRelationalSymbolicValue(Kind.GREATER_THAN_OR_EQUAL, computedFrom);
break;
case AND:
case AND_ASSIGNMENT:
result = new SymbolicValue.AndSymbolicValue();
result.computedFrom(computedFrom);
break;
case OR:
case OR_ASSIGNMENT:
result = new SymbolicValue.OrSymbolicValue();
result.computedFrom(computedFrom);
break;
case XOR:
case XOR_ASSIGNMENT:
result = new SymbolicValue.XorSymbolicValue();
result.computedFrom(computedFrom);
break;
default:
result = createDefaultSymbolicValue();
result.computedFrom(computedFrom);
}
return result;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue 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.");
});
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class UnclosedResourcesCheck method symbolicValuesToReport.
private static Set<SymbolicValue> symbolicValuesToReport(CheckerContext context) {
List<SymbolicValue> openSymbolicValues = context.getState().getValuesWithConstraints(OPEN);
Set<SymbolicValue> svToReport = new HashSet<>(openSymbolicValues);
// report only outermost OPEN symbolic value
for (SymbolicValue openSymbolicValue : openSymbolicValues) {
if (openSymbolicValue instanceof ResourceWrapperSymbolicValue) {
svToReport.remove(openSymbolicValue.wrappedValue());
}
}
return svToReport;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class InvariantReturnCheck method checkEndOfExecutionPath.
@Override
public void checkEndOfExecutionPath(CheckerContext context, ConstraintManager constraintManager) {
if (context.getState().exitingOnRuntimeException()) {
return;
}
MethodInvariantContext methodInvariantContext = methodInvariantContexts.peek();
if (!methodInvariantContext.methodToCheck) {
return;
}
SymbolicValue exitValue = context.getState().exitValue();
if (exitValue != null) {
methodInvariantContext.endPaths++;
methodInvariantContext.symbolicValues.add(exitValue);
ConstraintsByDomain constraints = context.getState().getConstraints(exitValue);
if (constraints != null) {
constraints.forEach(methodInvariantContext.methodConstraints::put);
} else {
// Relational SV or NOT SV : we can't say anything.
methodInvariantContext.avoidRaisingConstraintIssue = true;
}
}
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class MapComputeIfAbsentOrPresentCheck method checkPostStatement.
@Override
public ProgramState checkPostStatement(CheckerContext context, Tree syntaxNode) {
if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) syntaxNode;
if (MAP_GET.matches(mit)) {
ProgramState psBeforeInvocation = context.getNode().programState;
ProgramState psAfterInvocation = context.getState();
SymbolicValue keySV = psBeforeInvocation.peekValue(0);
SymbolicValue mapSV = psBeforeInvocation.peekValue(1);
SymbolicValue valueSV = psAfterInvocation.peekValue();
mapGetInvocations.put(mapSV, new MapGetInvocation(valueSV, keySV, mit));
}
}
return super.checkPostStatement(context, syntaxNode);
}
Aggregations