Java Code Examples for com.sun.source.tree.ForLoopTree#getInitializer()
The following examples show how to use
com.sun.source.tree.ForLoopTree#getInitializer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 6 votes |
@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 } }
Example 2
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@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; }
Example 3
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 4 votes |
@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; }
Example 4
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 4 votes |
@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.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; }