本文整理汇总了Java中com.sun.source.tree.ForLoopTree.getCondition方法的典型用法代码示例。如果您正苦于以下问题:Java ForLoopTree.getCondition方法的具体用法?Java ForLoopTree.getCondition怎么用?Java ForLoopTree.getCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.ForLoopTree
的用法示例。
在下文中一共展示了ForLoopTree.getCondition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
示例2: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Boolean visitForLoop(ForLoopTree that, Void unused) {
Boolean condValue = ASTHelpers.constValue(that.getCondition(), Boolean.class);
if (!Objects.equals(condValue, false)) {
scan(that.getStatement());
}
// (1)
if (that.getCondition() != null && !Objects.equals(condValue, true)) {
return true;
}
// (2)
if (breaks.contains(that)) {
return true;
}
return false;
}
示例3: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree node, EnumSet<UseTypes> p) {
if (node.getCondition() != null && node.getCondition().getKind() == Kind.IDENTIFIER) {
handlePossibleIdentifier(new TreePath(getCurrentPath(), node.getCondition()), EnumSet.of(UseTypes.READ));
}
return super.visitForLoop(node, p);
}
示例4: 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();
}
}
示例5: matchForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Description matchForLoop(ForLoopTree tree, VisitorState state) {
if (tree.getCondition() != null) {
return doUnboxingCheck(state, tree.getCondition());
}
return Description.NO_MATCH;
}
示例6: matchForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Description matchForLoop(ForLoopTree tree, VisitorState state) {
if (tree.getCondition() == null) {
return NO_MATCH;
}
return check(
tree.getCondition(),
ImmutableList.<Tree>builder()
.add(tree.getCondition())
.add(tree.getStatement())
.addAll(tree.getUpdate())
.build());
}
示例7: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree node, Void p) {
if (node.getCondition() != null) {
// Condition is null e.g. in "for (;;) {...}"
checkForNullability(node.getCondition(), CONDITION_NULLABLE);
}
return super.visitForLoop(node, p);
}
示例8: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
public CodeModel visitForLoop(ForLoopTree node, VisitContext context) {
if (node.getInitializer().size() != 1) {
throw new UnsupportedOperationException();
}
if (node.getUpdate().size() != 1) {
throw new UnsupportedOperationException();
}
StatementModel body = scan(node.getStatement(), context);
if (node.getInitializer().size() == 1 &&
node.getInitializer().get(0).getKind() == Tree.Kind.VARIABLE &&
node.getCondition().getKind() == Tree.Kind.LESS_THAN &&
node.getUpdate().size() == 1 &&
node.getUpdate().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT &&
node.getUpdate().get(0).getExpression().getKind() == Tree.Kind.POSTFIX_INCREMENT) {
VariableTree init = (VariableTree) node.getInitializer().get(0);
BinaryTree lessThan = (BinaryTree) node.getCondition();
UnaryTree increment = (UnaryTree) node.getUpdate().get(0).getExpression();
if (lessThan.getLeftOperand().getKind() == Tree.Kind.IDENTIFIER &&
increment.getExpression().getKind() == Tree.Kind.IDENTIFIER) {
String id1 = init.getName().toString();
String id2 = ((IdentifierTree) lessThan.getLeftOperand()).getName().toString();
String id3 = ((IdentifierTree) increment.getExpression()).getName().toString();
if (id1.equals(id2) && id2.equals(id3)) {
ExpressionModel from = scan(init.getInitializer(), context);
ExpressionModel to = scan(lessThan.getRightOperand(), context);
return context.builder.sequenceForLoop(id1, from, to, body);
}
}
}
StatementModel initializer = scan(node.getInitializer().get(0), context);
ExpressionModel update = scan(node.getUpdate().get(0).getExpression(), context);
ExpressionModel condition = scan(node.getCondition(), context);
return context.builder.forLoop(initializer, condition, update, body);
}
示例9: 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;
}
示例10: 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;
}
示例11: interestingPartOfLoop
import com.sun.source.tree.ForLoopTree; //导入方法依赖的package包/类
@Override
Object interestingPartOfLoop(ForLoopTree loop) {
return loop.getCondition();
}
示例12: 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;
}