Search in sources :

Example 1 with SymbolicValueSymbol

use of org.sonar.java.se.ProgramState.SymbolicValueSymbol in project sonar-java by SonarSource.

the class RedundantAssignmentsCheck method handleAssignment.

private void handleAssignment(CheckerContext context, AssignmentExpressionTree assignmentExpressionTree) {
    SymbolicValueSymbol assignedVariable = context.getState().peekValueSymbol();
    Symbol assignedSymbol = assignedVariable.symbol();
    if (assignedSymbol == null || // meaning that 'stream = stream.map(...);' would be detected as redundant assignment if not explicitly excluded
    STREAM_TYPES.stream().anyMatch(assignedSymbol.type()::is)) {
        return;
    }
    ExplodedGraph.Node node = context.getNode();
    ProgramState previousState = node.programState;
    SymbolicValue oldValue = previousState.getValue(assignedSymbol);
    SymbolicValue newValue = assignedVariable.symbolicValue();
    Symbol fromSymbol = previousState.peekValueSymbol().symbol();
    assignmentsByMethod.peek().put(assignmentExpressionTree, new AssignmentDataHolder(assignedSymbol, oldValue, newValue, fromSymbol, node));
}
Also used : ExplodedGraph(org.sonar.java.se.ExplodedGraph) SymbolicValueSymbol(org.sonar.java.se.ProgramState.SymbolicValueSymbol) SymbolicValueSymbol(org.sonar.java.se.ProgramState.SymbolicValueSymbol) Symbol(org.sonar.plugins.java.api.semantic.Symbol) ProgramState(org.sonar.java.se.ProgramState) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue)

Aggregations

ExplodedGraph (org.sonar.java.se.ExplodedGraph)1 ProgramState (org.sonar.java.se.ProgramState)1 SymbolicValueSymbol (org.sonar.java.se.ProgramState.SymbolicValueSymbol)1 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)1 Symbol (org.sonar.plugins.java.api.semantic.Symbol)1