コード例 #1
0
  private static ASTWhileNode makeWhileNode(ASTIfElseNode ifElseNode, ASTNode loopNode) {
    ASTCondition outerCond = null;
    ASTCondition innerCond = ifElseNode.get_Condition();
    ASTCondition newCond = null;

    if (loopNode instanceof ASTWhileNode) {
      outerCond = ((ASTWhileNode) loopNode).get_Condition();
      newCond = new ASTAndCondition(outerCond, innerCond);
    } else if (loopNode instanceof ASTUnconditionalLoopNode) {
      newCond = innerCond;
    } else {
      // not dealing with the case of ASTDoWhileNode
      return null;
    }
    List loopBody = ifElseNode.getIfBody();
    SETNodeLabel newLabel = ((ASTLabeledNode) loopNode).get_Label();

    // make new ASTWhileNode
    return new ASTWhileNode(newLabel, newCond, loopBody);
  }
コード例 #2
0
ファイル: IfElseBreaker.java プロジェクト: GeneBlue/JAADAS
  public boolean isIfElseBreakingPossiblePatternOne(ASTIfElseNode node) {
    List<Object> ifBody = node.getIfBody();
    if (ifBody.size() != 1) {
      // we are only interested if size is one
      return false;
    }

    ASTNode onlyNode = (ASTNode) ifBody.get(0);
    boolean check = checkStmt(onlyNode, node);
    if (!check) {
      return false;
    }

    // breaking is possible
    // break and store
    newIfNode = new ASTIfNode(((ASTLabeledNode) node).get_Label(), node.get_Condition(), ifBody);
    remainingBody = node.getElseBody();

    return true;
  }
コード例 #3
0
ファイル: IfElseBreaker.java プロジェクト: GeneBlue/JAADAS
  public boolean isIfElseBreakingPossiblePatternTwo(ASTIfElseNode node) {
    List<Object> elseBody = node.getElseBody();
    if (elseBody.size() != 1) {
      // we are only interested if size is one
      return false;
    }

    ASTNode onlyNode = (ASTNode) elseBody.get(0);
    boolean check = checkStmt(onlyNode, node);
    if (!check) {
      return false;
    }
    // breaking is possible

    ASTCondition cond = node.get_Condition();
    // flip
    cond.flip();

    newIfNode = new ASTIfNode(((ASTLabeledNode) node).get_Label(), cond, elseBody);
    remainingBody = node.getIfBody();

    return true;
  }