コード例 #1
0
  protected CtMethod apply(CtMethod method, List<Statement> statements, int index) {
    CtMethod cloned_method = AmplificationHelper.cloneMethodTest(method, "_cf", 1000);
    CtStatement stmt = getAssertStatement(cloned_method).get(index);
    statements
        .stream()
        .forEach(
            c -> {
              stmt.insertBefore((CtStatement) c.getCtCodeFragment());
              c.getCtCodeFragment().setParent(stmt.getParent());
            });

    return cloned_method;
  }
コード例 #2
0
  protected List<CtLocalVariable> getLocalVarInScope(CtStatement stmt) {
    List<CtLocalVariable> vars = new ArrayList<>();
    try {
      CtBlock parentBlock = stmt.getParent(CtBlock.class);
      if (parentBlock != null) {
        boolean beforeCurrentStmt = true;
        int i = 0;
        List<CtStatement> stmts = parentBlock.getStatements();

        while (beforeCurrentStmt && i < stmts.size()) {
          CtStatement currentStatement = stmts.get(i);
          i++;
          beforeCurrentStmt = beforeCurrentStmt && currentStatement != stmt;
          if (currentStatement instanceof CtLocalVariable) {
            vars.add((CtLocalVariable) currentStatement);
          }
        }
        vars.addAll(getLocalVarInScope(parentBlock));
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return vars;
  }