Пример #1
0
 /**
  * Zips this tree with another, using the given function. The resulting tree is the structural
  * intersection of the two trees.
  *
  * @param bs A tree to zip this tree with.
  * @param f A function with which to zip together the two trees.
  * @return A new tree of the results of applying the given function over this tree and the given
  *     tree, position-wise.
  */
 public <B, C> Tree<C> zipWith(final Tree<B> bs, final F2<A, B, C> f) {
   return f.zipTreeM().f(this, bs);
 }
  @Override
  public ISourceChange CalculateASTNodeChange(ASTNodePair pair) {

    ISourceChange change = this.changeBuilder.buildSimpleChange(pair);
    if (change != null) return change;

    if (pair.getNodeBefore().getNodeType() != pair.getNodeAfter().getNodeType()) {
      logger.debug("Before statement: " + pair.getNodeBefore());
      logger.debug("After statement: " + pair.getNodeAfter());
      List<List<ASTNode>> groupsBefore =
          getDecendantStatements.f(pair.getNodeBefore()).snoc(pair.getNodeBefore()).group(typeEq);
      List<List<ASTNode>> groupsAfter =
          getDecendantStatements.f(pair.getNodeAfter()).snoc(pair.getNodeAfter()).group(typeEq);
      List<P2<List<ASTNode>, List<ASTNode>>> groupPairs =
          FJUtils.getSamePairs(groupsBefore, groupsAfter, listTypeEq);
      List<P2<ASTNode, ASTNode>> nodePairs =
          removeSubPairs(groupPairs.bind(similarNodeMapper.tuple()).filter(areBothNotNull));
      SubChangeContainer container = changeBuilder.createSubchangeContainer(pair);
      container.addMultiSubChanges(
          nodePairs.sort(orderByFirstNodeStart).map(statementChangeCalFunc.tuple()).toCollection());
      container = pruneSourceChangeContainer(container);
      return container == null ? changeBuilder.createUnknownChange(pair) : container;
    }

    switch (pair.getNodeBefore().getNodeType()) {
      case ASTNode.IF_STATEMENT:
        return ifCalculator.CalculateASTNodeChange(pair);
      case ASTNode.BLOCK:
        return blockCalculator.CalculateASTNodeChange(pair);
      case ASTNode.FOR_STATEMENT:
        return fsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.ENHANCED_FOR_STATEMENT:
        return enhancedForCal.CalculateASTNodeChange(pair);
      case ASTNode.WHILE_STATEMENT:
        return wsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.DO_STATEMENT:
        return dsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.TRY_STATEMENT:
        return tsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.BREAK_STATEMENT:
        return bsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.CONTINUE_STATEMENT:
        return csCalculator.CalculateASTNodeChange(pair);
      case ASTNode.RETURN_STATEMENT:
        return rsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.THROW_STATEMENT:
        return thsCalculator.CalculateASTNodeChange(pair);
      case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return varDecStaCal.CalculateASTNodeChange(pair);
      case ASTNode.EXPRESSION_STATEMENT:
        SubChangeContainer container = this.changeBuilder.createSubchangeContainer(pair);
        container.addSubChange(
            expressionCalculator.CalculateASTNodeChange(
                new ASTNodePair(
                    (ASTNode)
                        pair.getNodeBefore()
                            .getStructuralProperty(ExpressionStatement.EXPRESSION_PROPERTY),
                    (ASTNode)
                        pair.getNodeAfter()
                            .getStructuralProperty(ExpressionStatement.EXPRESSION_PROPERTY))));
        return container;
      default:
        return changeBuilder.createUnknownChange(pair);
    }
  }