Search in sources :

Example 1 with Node

use of org.sonar.java.se.ExplodedGraph.Node in project sonar-java by SonarSource.

the class FlowComputation method run.

private Set<Flow> run(final ExplodedGraph.Node node, PSet<Symbol> trackedSymbols) {
    Set<Flow> flows = new HashSet<>();
    Deque<ExecutionPath> workList = new ArrayDeque<>();
    SameConstraints sameConstraints = new SameConstraints(node, trackedSymbols, domains);
    node.edges().stream().flatMap(e -> startPath(e, trackedSymbols, sameConstraints)).forEach(workList::push);
    int flowSteps = 0;
    Set<ExecutionPath> visited = new HashSet<>(workList);
    while (!workList.isEmpty()) {
        ExecutionPath path = workList.pop();
        if (path.finished) {
            flows.add(path.flow);
        } else {
            path.lastEdge.parent.edges().stream().filter(path::notVisited).flatMap(path::addEdge).forEach(ep -> {
                if (visited.add(ep)) {
                    workList.push(ep);
                }
            });
        }
        flowSteps++;
        if (flowSteps == MAX_FLOW_STEPS) {
            LOG.debug("Flow was not able to complete");
            break;
        }
    }
    return flows;
}
Also used : JavaSymbol(org.sonar.java.resolve.JavaSymbol) ExpressionUtils(org.sonar.java.model.ExpressionUtils) MethodYield(org.sonar.java.se.xproc.MethodYield) Loggers(org.sonar.api.utils.log.Loggers) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) Map(java.util.Map) Arguments(org.sonar.plugins.java.api.tree.Arguments) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SyntaxTreeNameFinder(org.sonar.java.se.checks.SyntaxTreeNameFinder) Set(java.util.Set) Collectors(java.util.stream.Collectors) BinarySymbolicValue(org.sonar.java.se.symbolicvalues.BinarySymbolicValue) JavaFileScannerContext(org.sonar.plugins.java.api.JavaFileScannerContext) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) Optional(java.util.Optional) Constraint(org.sonar.java.se.constraint.Constraint) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) Symbol(org.sonar.plugins.java.api.semantic.Symbol) IntStream(java.util.stream.IntStream) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) Deque(java.util.Deque) ConstraintsByDomain(org.sonar.java.se.constraint.ConstraintsByDomain) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) Lists(com.google.common.collect.Lists) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) PSet(org.sonar.java.collections.PSet) Node(org.sonar.java.se.ExplodedGraph.Node) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) ConditionalExpressionTree(org.sonar.plugins.java.api.tree.ConditionalExpressionTree) Tree(org.sonar.plugins.java.api.tree.Tree) Type(org.sonar.plugins.java.api.semantic.Type) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) PCollections(org.sonar.java.collections.PCollections) CFG(org.sonar.java.cfg.CFG) Preconditions(com.google.common.base.Preconditions) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) CheckForNull(javax.annotation.CheckForNull) HappyPathYield(org.sonar.java.se.xproc.HappyPathYield) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) ArrayDeque(java.util.ArrayDeque) Constraint(org.sonar.java.se.constraint.Constraint) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) HashSet(java.util.HashSet)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1