test_class.file: cypher2sql/src/test/java/org/cytosm/cypher2sql/lowering/typeck/VarDependenciesTest.java
test_class.identifier: VarDependenciesTest
test_class.superclass: extends BaseVarTests
test_case.body: @Test
      public void testGetUsedAndIndirectUsedVars2() {
          String cypher = "" +
                  "MATCH (a)--(e)\n" +
                  "MATCH (b)--(c)\n" +
                  "MATCH (a)--(d)\n" +
                  "RETURN 42";
          Statement st = PassAvailables.parseCypher(cypher);
          SingleQuery sq = (SingleQuery) st.query.part;
          VarDependencies dependencies = new VarDependencies(st);
  
          Iterator<Clause> clauses = sq.clauses.iterator();
          List<Var> match0 = dependencies.getUsedAndIndirectUsedVars(
                  this.genClauseForASTNode(this.getPatternPart(clauses.next()).next()));
          List<Var> match1 = dependencies.getUsedAndIndirectUsedVars(
                  this.genClauseForASTNode(this.getPatternPart(clauses.next()).next()));
          List<Var> match2 = dependencies.getUsedAndIndirectUsedVars(
                  this.genClauseForASTNode(this.getPatternPart(clauses.next()).next()));
  
          Assert.assertEquals(match0.size(), 2);
          Assert.assertEquals(match1.size(), 2);
          Assert.assertEquals(match2.size(), 3);
      }
test_case.class_method_signature: VarDependenciesTest.testGetUsedAndIndirectUsedVars2()
test_case.full_signature: @Test public void testGetUsedAndIndirectUsedVars2()
test_case.identifier: testGetUsedAndIndirectUsedVars2
test_case.invocations: parseCypher iterator getUsedAndIndirectUsedVars genClauseForASTNode next getPatternPart next getUsedAndIndirectUsedVars genClauseForASTNode next getPatternPart next getUsedAndIndirectUsedVars genClauseForASTNode next getPatternPart next assertEquals size assertEquals size assertEquals size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetUsedAndIndirectUsedVars2()
focal_class.declarator: usedVariablesInClause = new HashMap<>()
focal_class.modifier: private
focal_class.original_string: private Map<ClauseId, List<Var>> usedVariablesInClause = new HashMap<>();
focal_class.type: Map<ClauseId, List<Var>>
focal_class.var_name: usedVariablesInClause
focal_class.declarator: reachableVariables = new HashMap<>()
focal_class.modifier: private
focal_class.original_string: private Map<ClauseId, AvailableVariables> reachableVariables = new HashMap<>();
focal_class.type: Map<ClauseId, AvailableVariables>
focal_class.var_name: reachableVariables
focal_class.declarator: relationships = new HashMap<>()
focal_class.modifier: private
focal_class.original_string: private Map<ClauseId, List<Relationship>> relationships = new HashMap<>();
focal_class.type: Map<ClauseId, List<Relationship>>
focal_class.var_name: relationships
focal_class.declarator: returnExprs = new ArrayList<>()
focal_class.modifier: private
focal_class.original_string: private List<Expr> returnExprs = new ArrayList<>();
focal_class.type: List<Expr>
focal_class.var_name: returnExprs
focal_class.file: cypher2sql/src/main/java/org/cytosm/cypher2sql/lowering/typeck/VarDependencies.java
focal_class.identifier: VarDependencies
focal_class.class_method_signature: VarDependencies.VarDependencies(final Statement statement)
focal_class.full_signature: public  VarDependencies(final Statement statement)
focal_class.identifier: VarDependencies
focal_class.modifiers: public
focal_class.parameters: (final Statement statement)
focal_class.signature:  VarDependencies(final Statement statement)
focal_class.class_method_signature: VarDependencies.getUsedVars(ClauseId clauseId)
focal_class.full_signature: public List<Var> getUsedVars(ClauseId clauseId)
focal_class.identifier: getUsedVars
focal_class.modifiers: public
focal_class.parameters: (ClauseId clauseId)
focal_class.return: List<Var>
focal_class.signature: List<Var> getUsedVars(ClauseId clauseId)
focal_class.class_method_signature: VarDependencies.getAllVariables()
focal_class.full_signature: public Set<Var> getAllVariables()
focal_class.identifier: getAllVariables
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Set<Var>
focal_class.signature: Set<Var> getAllVariables()
focal_class.class_method_signature: VarDependencies.getUsedAndIndirectUsedVars(ClauseId clauseId)
focal_class.full_signature: public List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId)
focal_class.identifier: getUsedAndIndirectUsedVars
focal_class.modifiers: public
focal_class.parameters: (ClauseId clauseId)
focal_class.return: List<Var>
focal_class.signature: List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId)
focal_class.class_method_signature: VarDependencies.getReachableVars(ClauseId clauseId)
focal_class.full_signature: public AvailableVariables getReachableVars(ClauseId clauseId)
focal_class.identifier: getReachableVars
focal_class.modifiers: public
focal_class.parameters: (ClauseId clauseId)
focal_class.return: AvailableVariables
focal_class.signature: AvailableVariables getReachableVars(ClauseId clauseId)
focal_class.class_method_signature: VarDependencies.getRelationships(ClauseId clauseId)
focal_class.full_signature: public List<Relationship> getRelationships(ClauseId clauseId)
focal_class.identifier: getRelationships
focal_class.modifiers: public
focal_class.parameters: (ClauseId clauseId)
focal_class.return: List<Relationship>
focal_class.signature: List<Relationship> getRelationships(ClauseId clauseId)
focal_class.class_method_signature: VarDependencies.getReturnExprs()
focal_class.full_signature: public List<Expr> getReturnExprs()
focal_class.identifier: getReturnExprs
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<Expr>
focal_class.signature: List<Expr> getReturnExprs()
focal_method.body: public List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId) {
          // Start with the used variable.
          Set<Var> result = new HashSet<>(this.getUsedVars(clauseId));
          Stack<Var> stack = new Stack<>();
  
          List<Relationship> relsToInspect = relationships.entrySet().stream()
                  .filter(a -> a.getKey().compareTo(clauseId) < 0)
                  .flatMap(x -> x.getValue().stream())
                  .collect(Collectors.toList());
  
          // Start with the used variables:
          stack.addAll(result);
  
          while (!stack.isEmpty()) {
              Var var = stack.pop();
              if (var instanceof NodeVar) {
                  relsToInspect.stream().filter(r -> r.leftNode == var).forEach(rel -> {
                      if (!result.contains(rel.rightNode)) {
                          stack.add(rel.rightNode);
                          result.add(rel.rightNode);
                      }
                  });
                  relsToInspect.stream().filter(r -> r.rightNode == var).forEach(rel -> {
                      if (!result.contains(rel.leftNode)) {
                          stack.add(rel.leftNode);
                          result.add(rel.leftNode);
                      }
                  });
              }
          }
  
          return Collections.unmodifiableList(result.stream().collect(Collectors.toList()));
      }
focal_method.class_method_signature: VarDependencies.getUsedAndIndirectUsedVars(ClauseId clauseId)
focal_method.full_signature: public List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId)
focal_method.identifier: getUsedAndIndirectUsedVars
focal_method.invocations: getUsedVars collect flatMap filter stream entrySet compareTo getKey stream getValue toList addAll isEmpty pop forEach filter stream contains add add forEach filter stream contains add add unmodifiableList collect stream toList
focal_method.modifiers: public
focal_method.parameters: (ClauseId clauseId)
focal_method.return: List<Var>
focal_method.signature: List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId)