public String initialize(CompilationUnit root, ASTNode node) { ASTNode controlNode= getBreakOrContinueNode(node); if (controlNode != null) { fASTRoot= root; try { if (root.getTypeRoot() == null || root.getTypeRoot().getBuffer() == null) return SearchMessages.BreakContinueTargetFinder_cannot_highlight; } catch (JavaModelException e) { return SearchMessages.BreakContinueTargetFinder_cannot_highlight; } fSelected= controlNode; fIsBreak= fSelected instanceof BreakStatement; fLabel= getLabel(); fDescription= Messages.format(SearchMessages.BreakContinueTargetFinder_occurrence_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(fSelected))); return null; } else { return SearchMessages.BreakContinueTargetFinder_no_break_or_continue_selected; } }
@Override public boolean visit(BreakStatement node) { SimpleName label= node.getLabel(); if (fDefiningLabel != null && isSameLabel(label) && ASTNodes.isParent(label, fDefiningLabel)) { fResult.add(label); } return false; }
@Override public void endVisit(BreakStatement node) { if (skipNode(node)) { return; } setFlowInfo(node, createBranch(node.getLabel())); }
@Override public boolean visit(BreakStatement node) { SimpleName label = node.getLabel(); if (fDefiningLabel != null && isSameLabel(label) && ASTNodes.isParent(label, fDefiningLabel)) { fResult.add(label); } return false; }
private ASTNode getBreakOrContinueNode(ASTNode selectedNode) { if (selectedNode instanceof BreakStatement) return selectedNode; if (selectedNode instanceof ContinueStatement) return selectedNode; if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof BreakStatement) return selectedNode.getParent(); if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof ContinueStatement) return selectedNode.getParent(); return null; }
private SimpleName getLabel() { if (fIsBreak){ BreakStatement bs= (BreakStatement) fSelected; return bs.getLabel(); } else { ContinueStatement cs= (ContinueStatement) fSelected; return cs.getLabel(); } }
/** * Finds the target for break or continue node. * * @param input the editor input * @param region the region * @return the break or continue target location or <code>null</code> if none * @since 3.7 */ public static OccurrenceLocation findBreakOrContinueTarget(ITypeRoot input, IRegion region) { CompilationUnit astRoot= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_NO, null); if (astRoot == null) return null; ASTNode node= NodeFinder.perform(astRoot, region.getOffset(), region.getLength()); ASTNode breakOrContinueNode= null; boolean labelSelected= false; if (node instanceof SimpleName) { SimpleName simpleName= (SimpleName) node; StructuralPropertyDescriptor location= simpleName.getLocationInParent(); if (location == ContinueStatement.LABEL_PROPERTY || location == BreakStatement.LABEL_PROPERTY) { breakOrContinueNode= simpleName.getParent(); labelSelected= true; } } else if (node instanceof ContinueStatement || node instanceof BreakStatement) breakOrContinueNode= node; if (breakOrContinueNode == null) return null; BreakContinueTargetFinder finder= new BreakContinueTargetFinder(); if (finder.initialize(astRoot, breakOrContinueNode) == null) { OccurrenceLocation[] locations= finder.getOccurrences(); if (locations != null) { if (breakOrContinueNode instanceof BreakStatement && !labelSelected) return locations[locations.length - 1]; // points to the end of target statement return locations[0]; // points to the beginning of target statement } } return null; }
private static Statement copyStatementExceptBreak(AST ast, ASTRewrite rewrite, Statement source) { if (source instanceof Block) { Block block= (Block) source; Block newBlock= ast.newBlock(); for (Iterator<Statement> iter= block.statements().iterator(); iter.hasNext();) { Statement statement= iter.next(); if (statement instanceof BreakStatement) { continue; } newBlock.statements().add(copyStatementExceptBreak(ast, rewrite, statement)); } return newBlock; } return (Statement) rewrite.createMoveTarget(source); }
@Override public boolean visit(BreakStatement node) { this.fBuffer.append("break");//$NON-NLS-1$ if (node.getLabel() != null) { this.fBuffer.append(" ");//$NON-NLS-1$ node.getLabel().accept(this); } this.fBuffer.append(";");//$NON-NLS-1$ return false; }
public boolean visit(BreakStatement node) { printIndent(); this.buffer.append("break");//$NON-NLS-1$ if (node.getLabel() != null) { this.buffer.append(" ");//$NON-NLS-1$ node.getLabel().accept(this); } this.buffer.append(";\n");//$NON-NLS-1$ return false; }
@SuppressWarnings("unchecked") @Override public boolean visit(QBreak statement) { Block block = blocks.peek(); BreakStatement breakSt = ast.newBreakStatement(); block.statements().add(breakSt); return super.visit(statement); }
@Override public boolean visit(BreakStatement node) { //System.out.println("Found: " + node.getClass()); if (node.getLabel() == null) { println("break;"); //if (node.getParent() instanceof SwitchCase) { // indent--; //} } else { print("break "); node.getLabel().accept(this); println(";"); } return false; }
@Override public boolean visit(BreakStatement node) { return false; }
/** {@inheritDoc} */ @Override public void endVisit(BreakStatement node) { logger.warn("Method endVisitBreakStatement for " + node + " for " + node + " not implemented!"); super.endVisit(node); }
/** {@inheritDoc} */ @Override public boolean visit(BreakStatement node) { logger.warn("Method visitBreakStatement for " + node + " for " + node + " not implemented!"); return super.visit(node); }
@Override public boolean visit(BreakStatement node) { this.encounteredBreakStatement = true; return super.visit(node); }
@Override public boolean visit(final BreakStatement node) { return false; }
@Override public boolean visit(final BreakStatement node) { return this.visitInstrumentable(node); }
@Override public void endVisit(BreakStatement node) { if (skipNode(node)) return; setFlowInfo(node, createBranch(node.getLabel())); }
@Override public boolean visit(BreakStatement node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
@Override public boolean visit(BreakStatement node) { add(fCreator.create(node)); return true; }
@Override public void endVisit(BreakStatement node) { endVisitNode(node); }
@Override public boolean visit(BreakStatement node) { return visitNode(node); }
@Override public boolean visit(SimpleName node) { // We have to be inside a method if (curMethod == null) return false; // Only replace variables IBinding binding = node.resolveBinding(); if (binding == null) { if ((node.getParent() instanceof LabeledStatement) && ((LabeledStatement) node.getParent()).getLabel().equals(node)) return false; if ((node.getParent() instanceof BreakStatement) && ((BreakStatement) node.getParent()).getLabel().equals(node)) return false; if (node.getParent() instanceof QualifiedName) return false; // This may happen System.err.println("Detected SimpleName without binding: " + node + "; Parent:" + node.getParent() + "\nThis may happen if there are compile errors"); // return false; } else if (binding.getKind() != IBinding.VARIABLE) return false; // Check if we need to add a "this" // Do this if current node is a field and we may replace a variable with // its name AST ast = node.getAST(); IVariableBinding vBinding = (IVariableBinding) binding; // Check for field acceses if (vBinding != null && vBinding.isField()) { // Add this if necessary if (renaming.containsValue(node.toString()) && !(node.getParent() instanceof FieldAccess) && !(node.getParent() instanceof QualifiedName)) { FieldAccess fa = ast.newFieldAccess(); fa.setExpression(ast.newThisExpression()); fa.setName(ast.newSimpleName(node.toString())); astRewrite.replace(node, fa, null); } return false; } String newName = renaming.get(node.toString()); if (newName == null || newName == "") return false; astRewrite.replace(node, ast.newSimpleName(newName), null); return false; }
@Override public boolean visit(BreakStatement node) { return visit((Statement)node); }
@Override public void endVisit(BreakStatement node) { endVisit((Statement)node); }
@Override public boolean visit(final BreakStatement node) { return this.internalVisit(node); }
@Override public boolean visit(BreakStatement node) { statements.add(new AbstractStatement(NodeType.BREAK, null)); return true; }