Beispiel #1
0
  /**
   * Split a block into sub methods.
   *
   * @param block Block or function to split.
   * @return new weight for the resulting block.
   */
  private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
      final long weight = WeighNodes.weigh(statement, weightCache);

      if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
        if (!statements.isEmpty()) {
          splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
          statements = new ArrayList<>();
          statementsWeight = 0;
        }
      }

      if (statement.isTerminal()) {
        splits.add(statement);
      } else {
        statements.add(statement);
        statementsWeight += weight;
      }
    }

    if (!statements.isEmpty()) {
      splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
  }
 private List<? extends StatementTree> translateStats(final List<? extends Statement> stats) {
   if (stats == null) {
     return null;
   }
   final List<StatementTreeImpl> statTrees = new ArrayList<>(stats.size());
   for (final Statement stat : stats) {
     curStat = null;
     stat.accept(this);
     assert curStat != null;
     statTrees.add(curStat);
   }
   return statTrees;
 }
  private StatementTreeImpl translateStat(final Statement stat) {
    if (stat == null) {
      return null;
    }

    curStat = null;
    stat.accept(this);
    assert curStat != null : "null for " + stat;
    return curStat;
  }