@Override public boolean visit(Block node) { this.fBuffer.append("{");//$NON-NLS-1$ for (Iterator<Statement> it= node.statements().iterator(); it.hasNext();) { Statement s= it.next(); s.accept(this); } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
private static Statement getSibling(Statement node, boolean isPrevious) { if (node.getParent() instanceof Block) { final List<Statement> stmts = asList((Statement) node.getParent()); final int indexOfNode = stmts.indexOf(node); final int siblingIndex = isPrevious ? indexOfNode - 1 : indexOfNode + 1; if (0 <= siblingIndex && siblingIndex < stmts.size()) { return stmts.get(siblingIndex); } } return null; }
private void handle(Statement body, ChildPropertyDescriptor bodyProperty) { if ((body.getFlags() & ASTNode.RECOVERED) != 0) return; Statement parent= (Statement)body.getParent(); if ((parent.getFlags() & ASTNode.RECOVERED) != 0) return; if (fRemoveUnnecessaryBlocksOnlyWhenReturnOrThrow) { if (!(body instanceof Block)) { if (body.getNodeType() != ASTNode.IF_STATEMENT && body.getNodeType() != ASTNode.RETURN_STATEMENT && body.getNodeType() != ASTNode.THROW_STATEMENT) { fResult.add(new AddBlockOperation(bodyProperty, body, parent)); } } else { if (RemoveBlockOperation.satisfiesCleanUpPrecondition(parent, bodyProperty, true)) { fResult.add(new RemoveBlockOperation(parent, bodyProperty)); } } } else if (fFindControlStatementsWithoutBlock) { if (!(body instanceof Block)) { fResult.add(new AddBlockOperation(bodyProperty, body, parent)); } } else if (fRemoveUnnecessaryBlocks) { if (RemoveBlockOperation.satisfiesCleanUpPrecondition(parent, bodyProperty, false)) { fResult.add(new RemoveBlockOperation(parent, bodyProperty)); } } }
/** * Copies the leading comment from the given statement. * * @param source the statement that supplies the leading comment * @since 2.1 */ void copyLeadingComment(Statement source) { setLeadingComment(source.getLeadingComment()); }
@Override int memSize() { int size = BASE_NODE_SIZE + 1 * 4 + stringSize(getLeadingComment()); return size; } }
private static int getIndex(int offset, List<Statement> statements) { for (int i = 0; i < statements.size(); i++) { Statement s = statements.get(i); if (offset <= s.getStartPosition()) { return i; } if (offset < s.getStartPosition() + s.getLength()) { return -1; } } return statements.size(); }
if (!isControlStatementWithBlock(statement.getParent())) { return false; int statementStart= statement.getStartPosition(); int statementEnd= statementStart + statement.getLength(); statement= (Statement) statement.getParent(); switch (statement.getNodeType()) { case ASTNode.IF_STATEMENT: int selectionStart= context.getSelectionOffset(); return true; AST ast= statement.getAST(); if (statement.getNodeType() == ASTNode.IF_STATEMENT) { ASTRewrite rewrite= ASTRewrite.create(ast); while (statement.getLocationInParent() == IfStatement.ELSE_STATEMENT_PROPERTY) { statement= (Statement) statement.getParent();
private void handleSimpleLoop(Statement body, int wrappingOption) { if (!(body instanceof Block)) { this.wrapIndexes.add(this.tm.firstIndexIn(body, -1)); this.wrapParentIndex = this.tm.firstIndexBefore(body, TokenNameRPAREN); this.wrapGroupEnd = this.tm.lastIndexIn(body, -1); handleWrap(wrappingOption, body.getParent()); body.accept(new ASTVisitor() { @Override public boolean visit(Block node) { forceContinuousWrapping(node, WrapPreparator.this.tm.firstIndexIn(node, -1)); return false; } }); } }
enhancedFor.getBody().accept(keyUseVisitor); int keyUses = keyUseVisitor.getUses().size(); final int insertionPoint = asList(enhancedFor.getBody()).get(0).getStartPosition() - 1; final Variable entryVar = new Variable( new VariableNameDecider(enhancedFor.getBody(), insertionPoint).suggest("entry", "mapEntry"), b);
private boolean simpleStmt(Statement stmt) { switch (stmt.getNodeType()) { case ASTNode.IF_STATEMENT: case ASTNode.DO_STATEMENT: case ASTNode.WHILE_STATEMENT: case ASTNode.FOR_STATEMENT: case ASTNode.ENHANCED_FOR_STATEMENT: case ASTNode.TRY_STATEMENT: return false; default: return true; } }
@Override ASTNode clone0(AST target) { WhileStatement result = new WhileStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setExpression((Expression) getExpression().clone(target)); result.setBody((Statement) getBody().clone(target)); return result; }
@Override final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == STATEMENTS_PROPERTY) { return statements(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
checkModifiable(); this.optionalLeadingComment = comment;
private static int getIndex(int offset, List<Statement> statements) { for (int i= 0; i < statements.size(); i++) { Statement s= statements.get(i); if (offset <= s.getStartPosition()) { return i; } if (offset < s.getStartPosition() + s.getLength()) { return -1; } } return statements.size(); }
/** * Copies the leading comment from the given statement. * * @param source the statement that supplies the leading comment * @since 2.1 */ void copyLeadingComment(Statement source) { setLeadingComment(source.getLeadingComment()); }
int memSize() { int size = BASE_NODE_SIZE + 1 * 4 + stringSize(getLeadingComment()); return size; } }
@Override public void endVisit(Statement node) { super.endVisit(node); if (node.getNodeType() == ASTNode.IF_STATEMENT || node.getNodeType() == ASTNode.WHILE_STATEMENT || node.getNodeType() == ASTNode.FOR_STATEMENT || node.getNodeType() == ASTNode.DO_STATEMENT || node.getNodeType() == ASTNode.SWITCH_STATEMENT) { if (showEndStatement) { minings.add(new EndStatementCodeMining(node, textEditor, viewer, endStatementMinLineNumber, provider)); } } }
@Override ASTNode clone0(AST target) { DoStatement result = new DoStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setBody((Statement) getBody().clone(target)); result.setExpression((Expression) getExpression().clone(target)); return result; }
@Override final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == STATEMENTS_PROPERTY) { return statements(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
checkModifiable(); this.optionalLeadingComment = comment;