当前位置: 首页>>代码示例>>Java>>正文


Java ForLoopTree.getUpdate方法代码示例

本文整理汇总了Java中com.sun.source.tree.ForLoopTree.getUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java ForLoopTree.getUpdate方法的具体用法?Java ForLoopTree.getUpdate怎么用?Java ForLoopTree.getUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.tree.ForLoopTree的用法示例。


在下文中一共展示了ForLoopTree.getUpdate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitForLoop

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public List<? extends TypeMirror> visitForLoop(ForLoopTree node, Object p) {
    if (theExpression == null) {
        // ambigous
        return null;
    }
    if (theExpression.getLeaf() == node.getCondition()) {
        return booleanType();
    } else {
        if (!((node.getInitializer() != null && node.getInitializer().contains(theExpression.getLeaf())) || (node.getUpdate() != null && node.getUpdate().contains(theExpression.getLeaf())))) {
            return null;
        }
        // initializer and update operation can have any result type, including none
        TypeElement tel = info.getElements().getTypeElement("java.lang.Void");
        if (tel == null) {
            return null;
        }
        return Collections.singletonList(tel.asType()); // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ExpectedTypeResolver.java

示例2: visitForLoop

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Mirror visitForLoop(ForLoopTree arg0, EvaluationContext evaluationContext) {
    try {
        evaluationContext.pushBlock();
        for (StatementTree st : arg0.getInitializer()) {
            st.accept(this, evaluationContext);
        }
        Mirror result = null;
        ExpressionTree condition = arg0.getCondition();
        List<? extends ExpressionStatementTree> updateList = arg0.getUpdate();
        StatementTree statement = arg0.getStatement();
        while (condition == null || evaluateCondition(arg0, evaluationContext, condition)) {
            Mirror value = null;
            try {
                evaluationContext.pushBlock();
                value = statement.accept(this, evaluationContext);
                if (value instanceof Break) {
                    break;
                } else if (value instanceof Continue) {
                    continue;
                }
                if (value != null) {
                    result = value;
                }
            } finally {
                evaluationContext.popBlock();
                if ((value instanceof Continue) || !(value instanceof CommandMirror)) {
                    for (Tree tree : updateList) {
                        tree.accept(this, evaluationContext);
                    } // for
                } // if
            } // finally
        } // while
        return result;
    } finally {
        evaluationContext.popBlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:EvaluatorVisitor.java

示例3: matchForLoop

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Description matchForLoop(ForLoopTree forLoopTree, VisitorState visitorState) {
  List<? extends ExpressionStatementTree> updates = forLoopTree.getUpdate();

  // keep track of all the symbols that are updated in the for loop header
  final Set<Symbol> incrementedSymbols =
      updates
          .stream()
          .filter(expStateTree -> expStateTree.getExpression() instanceof UnaryTree)
          .map(
              expStateTree ->
                  ASTHelpers.getSymbol(
                      ((UnaryTree) expStateTree.getExpression()).getExpression()))
          .collect(Collectors.toCollection(HashSet::new));

  // track if they are updated in the body without a conditional surrounding them
  StatementTree body = forLoopTree.getStatement();
  List<? extends StatementTree> statementTrees =
      body instanceof BlockTree ? ((BlockTree) body).getStatements() : ImmutableList.of(body);
  for (StatementTree s : statementTrees) {
    if (!CONDITIONALS.contains(s.getKind())) {
      Optional<Symbol> opSymbol = returnUnarySym(s);
      if (opSymbol.isPresent() && incrementedSymbols.contains(opSymbol.get())) {
        // both ++ and --
        return describeMatch(forLoopTree);
      }
    }
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:31,代码来源:IncrementInForLoopAndHeader.java

示例4: visitContinue

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
public Boolean visitContinue(ContinueTree node, ConstructorData p) {
    StatementTree loop = info.getTreeUtilities().getBreakContinueTarget(getCurrentPath());

    if (loop == null) {
        super.visitContinue(node, p);
        return null;
    }

    Tree resumePoint;

    if (loop.getKind() == Kind.LABELED_STATEMENT) {
        loop = ((LabeledStatementTree) loop).getStatement();
    }
    
    switch (loop.getKind()) {
        case WHILE_LOOP:
            resumePoint = ((WhileLoopTree) loop).getCondition();
            break;
        case FOR_LOOP: {
                ForLoopTree flt = (ForLoopTree)loop;
                resumePoint = null;
                if (flt.getUpdate() != null && !flt.getUpdate().isEmpty()) {
                    // resume will react on the 1st Tree of the update statement (always processed left to right)
                    resumePoint = flt.getUpdate().get(0);
                } 
                if (resumePoint == null) {
                    resumePoint = flt.getCondition();
                }
                if (resumePoint == null) {
                    resumePoint = flt.getStatement();
                }
        }
            break;
        case DO_WHILE_LOOP:
            resumePoint = ((DoWhileLoopTree) loop).getCondition();
            break;
        case ENHANCED_FOR_LOOP:
            resumePoint = ((EnhancedForLoopTree) loop).getStatement();
            break;
        default:
            resumePoint = null;
            break;
    }

    if (resumePoint != null) {
        recordResume(resumeBefore, resumePoint, variable2State);
    }

    variable2State = new HashMap< Element, State>();

    super.visitContinue(node, p);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:Flow.java

示例5: visitForLoop

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree node, Void unused) {
    sync(node);
    token("for");
    builder.space();
    token("(");
    builder.open(plusFour);
    builder.open(
            node.getInitializer().size() > 1
                    && node.getInitializer().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT
                    ? plusFour
                    : ZERO);
    if (!node.getInitializer().isEmpty()) {
        if (node.getInitializer().get(0).getKind() == VARIABLE) {
            PeekingIterator<StatementTree> it =
                    Iterators.<StatementTree>peekingIterator(node.getInitializer().iterator());
            visitVariables(
                    variableFragments(it, it.next()), DeclarationKind.NONE, Direction.HORIZONTAL);
        } else {
            boolean first = true;
            builder.open(ZERO);
            for (StatementTree t : node.getInitializer()) {
                if (!first) {
                    token(",");
                    builder.breakOp(" ");
                }
                scan(((ExpressionStatementTree) t).getExpression(), null);
                first = false;
            }
            token(";");
            builder.close();
        }
    } else {
        token(";");
    }
    builder.close();
    builder.breakOp(" ");
    if (node.getCondition() != null) {
        scan(node.getCondition(), null);
    }
    token(";");
    if (!node.getUpdate().isEmpty()) {
        builder.breakOp(" ");
        builder.open(node.getUpdate().size() <= 1 ? ZERO : plusFour);
        boolean firstUpdater = true;
        for (ExpressionStatementTree updater : node.getUpdate()) {
            if (!firstUpdater) {
                token(",");
                builder.breakToFill(" ");
            }
            scan(updater.getExpression(), null);
            firstUpdater = false;
        }
        builder.guessToken(";");
        builder.close();
    } else {
        builder.space();
    }
    builder.close();
    token(")");
    visitStatement(
            node.getStatement(),
            CollapseEmptyOrNot.YES,
            AllowLeadingBlankLine.YES,
            AllowTrailingBlankLine.NO);
    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:68,代码来源:JavaInputAstVisitor.java

示例6: visitForLoop

import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Node visitForLoop(ForLoopTree tree, Void p) {
    Name parentLabel = getLabel(getCurrentPath());

    Label conditionStart = new Label();
    Label loopEntry = new Label();
    Label loopExit = new Label();

    // If the loop is a labeled statement, then its continue
    // target is identical for continues with no label and
    // continues with the loop's label.
    Label updateStart;
    if (parentLabel != null) {
        updateStart = continueLabels.get(parentLabel);
    } else {
        updateStart = new Label();
    }

    Label oldBreakTargetL = breakTargetL;
    breakTargetL = loopExit;

    Label oldContinueTargetL = continueTargetL;
    continueTargetL = updateStart;

    // Initializer
    for (StatementTree init : tree.getInitializer()) {
        scan(init, p);
    }

    // Condition
    addLabelForNextNode(conditionStart);
    if (tree.getCondition() != null) {
        unbox(scan(tree.getCondition(), p));
        ConditionalJump cjump = new ConditionalJump(loopEntry, loopExit);
        extendWithExtendedNode(cjump);
    }

    // Loop body
    addLabelForNextNode(loopEntry);
    if (tree.getStatement() != null) {
        scan(tree.getStatement(), p);
    }

    // Update
    addLabelForNextNode(updateStart);
    for (ExpressionStatementTree update : tree.getUpdate()) {
        scan(update, p);
    }

    extendWithExtendedNode(new UnconditionalJump(conditionStart));

    // Loop exit
    addLabelForNextNode(loopExit);

    breakTargetL = oldBreakTargetL;
    continueTargetL = oldContinueTargetL;

    return null;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:60,代码来源:CFGBuilder.java


注:本文中的com.sun.source.tree.ForLoopTree.getUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。