@Override public boolean visit(Block node) { if (!(node.getParent() instanceof LambdaExpression)) { searchNode(node, contents, label, textedits); } return true; } });
boolean isBlockInsideBlock (Block node) { return node.getParent() instanceof Block; }
public final boolean visit(final Block block) { Assert.isNotNull(block); if (declarations && block.getParent() instanceof MethodDeclaration) return false; return super.visit(block); } };
public final boolean visit(final Block block) { Assert.isNotNull(block); if (declarations && block.getParent() instanceof MethodDeclaration) return false; return super.visit(block); } };
private boolean match0(final Block node, final Statement other) { if ((node.getParent() instanceof IfStatement || node.getParent() instanceof ForStatement || node.getParent() instanceof EnhancedForStatement || node.getParent() instanceof WhileStatement || node.getParent() instanceof DoStatement) && node.statements().size() == 1) { return safeSubtreeMatch(node.statements().get(0), other) || super.match(node, other); } return super.match(node, other); } }
try (BufferedReader bufferedReader = new BufferedReader(reader)) { Block block = new Block(); String line, previousIndents = ""; while (null != (line = bufferedReader.readLine()) { Matcher m = Pattern.compile("^(\\s+)").matcher(line); if (m.find()) { String indents = m.group(1); if (previousIndents.equals(indents)) { // update current block } else if (indents.length() > previousIndents.length()) { // start a new block Block newBlock = new Block(); newBlock.setParent(block); block.getChildren().add(newBlock); block = newBlock; } else { // current block finished, return to parent block = block.getParent(); } previousIndents = indents; } } } catch (IOException ioEx) { throw new ParseException(ioEx); }
@Override public boolean visit(Block node) { final List<Statement> stmts = statements(node); if (stmts.size() == 1 && stmts.get(0) instanceof Block) { replaceBlock((Block) stmts.get(0)); return DO_NOT_VISIT_SUBTREE; } else if (node.getParent() instanceof Block) { final Set<String> ifVariableNames = getLocalVariableIdentifiers(node, false); final Set<String> followingVariableNames = new HashSet<String>(); for (final Statement statement : getNextSiblings(node)) { followingVariableNames.addAll(getLocalVariableIdentifiers(statement, true)); } if (!ifVariableNames.removeAll(followingVariableNames)) { replaceBlock(node); return DO_NOT_VISIT_SUBTREE; } } return VISIT_SUBTREE; }
@Override public boolean visit(Block node) { if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node)) return true; List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } if (node.getParent().getLength() == 0) return true; // this is a fake block created by parsing in statements mode ASTNode parent = node.getParent(); if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block, this.options.insert_new_line_in_empty_block); return true; }
@Override public boolean visit(Block node) { if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node)) return true; List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } if (node.getParent().getLength() == 0) return true; // this is a fake block created by parsing in statements mode ASTNode parent = node.getParent(); if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block, this.options.insert_new_line_in_empty_block); return true; }
public boolean isGuardClause(Block node) { if (node.statements().size() != 1) return false; ASTNode parent = node.getParent(); if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null) return false; Object statement = node.statements().get(0); if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement)) return false; // guard clause cannot start with a comment // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565 int openBraceIndex = firstIndexIn(node, TokenNameLBRACE); return !get(openBraceIndex + 1).isComment(); }
public boolean isGuardClause(Block node) { if (node.statements().size() != 1) return false; ASTNode parent = node.getParent(); if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null) return false; Object statement = node.statements().get(0); if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement)) return false; // guard clause cannot start with a comment // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565 int openBraceIndex = firstIndexIn(node, TokenNameLBRACE); return !get(openBraceIndex + 1).isComment(); }
@Override public boolean visit(Block node) { if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node)) return true; List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } if (node.getParent().getLength() == 0) return true; // this is a fake block created by parsing in statements mode ASTNode parent = node.getParent(); if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block, this.options.insert_new_line_in_empty_block); return true; }
public boolean isGuardClause(Block node) { if (node.statements().size() != 1) return false; ASTNode parent = node.getParent(); if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null) return false; Object statement = node.statements().get(0); if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement)) return false; // guard clause cannot start with a comment // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565 int openBraceIndex = firstIndexIn(node, TokenNameLBRACE); return !get(openBraceIndex + 1).isComment(); }
@Override public boolean visit(Block node) { List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block); return true; }
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Block) */ public boolean visit(Block node) { if (visit(node, false)) { if (node.statements().isEmpty() && node.getParent().getNodeType() == ASTNode.METHOD_DECLARATION) { // in case of an empty method, set the breakpoint on the last line of the empty block. fLineLocation= lineNumber(node.getStartPosition() + node.getLength() - 1); fLocationFound= true; fLocationType= LOCATION_LINE; fTypeName= computeTypeName(node); return false; } return true; } return false; }
return null; ASTNode parent= block.getParent(); if (!(parent instanceof Statement)) return null;
@Override public boolean visit(Block node) { handleSemicolon(node.statements()); ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // spaces handled in #visit(MethodDeclaration) handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false); if (this.options.insert_space_after_closing_brace_in_block && (parent instanceof Statement || parent instanceof CatchClause)) { int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE); this.tm.get(closeBraceIndex).spaceAfter(); } return true; }
@Override public boolean visit(Block node) { handleSemicolon(node.statements()); ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // spaces handled in #visit(MethodDeclaration) handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false); if (this.options.insert_space_after_closing_brace_in_block && (parent instanceof Statement || parent instanceof CatchClause)) { int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE); this.tm.get(closeBraceIndex).spaceAfter(); } return true; }
@Override public boolean visit(Block node) { handleSemicolon(node.statements()); ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // spaces handled in #visit(MethodDeclaration) handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false); if (this.options.insert_space_after_closing_brace_in_block && (parent instanceof Statement || parent instanceof CatchClause)) { int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE); this.tm.get(closeBraceIndex).spaceAfter(); } return true; }
@Override public boolean visit(Block node) { handleSemicolon(node.statements()); ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // spaces handled in #visit(MethodDeclaration) handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false); if (this.options.insert_space_after_closing_brace_in_block && (parent instanceof Statement || parent instanceof CatchClause)) { int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE); this.tm.get(closeBraceIndex).spaceAfter(); } return true; }