/** * Builds a new {@link BreakStatement} instance. * * @return a new break statement */ public BreakStatement break0() { return ast.newBreakStatement(); }
/** * Append a 'break' statement. */ public void addBreak() { m_block.statements().add(m_ast.newBreakStatement()); }
/** * Add default case to switch statement. * * @param stmt statement to be executed */ public void addDefault(StatementBuilderBase stmt) { SwitchCase swcase = m_ast.newSwitchCase(); m_switch.statements().add(swcase); m_switch.statements().add(stmt.getStatement()); if (isBreakNeeded(stmt.getStatement())) { m_switch.statements().add(m_ast.newBreakStatement()); } }
/** * Add case to switch statement with a named constant as the match value. * * @param name named constant * @param stmt statement to be executed */ public void addNamedCase(String name, StatementBuilderBase stmt) { SwitchCase swcase = m_ast.newSwitchCase(); swcase.setExpression(m_ast.newSimpleName(name)); m_switch.statements().add(swcase); m_switch.statements().add(stmt.getStatement()); if (isBreakNeeded(stmt.getStatement())) { m_switch.statements().add(m_ast.newBreakStatement()); } }
/** * Add case to switch statement with a number as the match value. * * @param value match value * @param stmt statement to be executed */ public void addNumberCase(String value, StatementBuilderBase stmt) { SwitchCase swcase = m_ast.newSwitchCase(); swcase.setExpression(numberLiteral(value)); m_switch.statements().add(swcase); m_switch.statements().add(stmt.getStatement()); if (isBreakNeeded(stmt.getStatement())) { m_switch.statements().add(m_ast.newBreakStatement()); } }
private static void createMissingDefaultProposal(IInvocationContext context, SwitchStatement switchStatement, Image image, Collection<ICommandAccess> proposals) { AST ast= switchStatement.getAST(); ASTRewrite astRewrite= ASTRewrite.create(ast); ListRewrite listRewrite= astRewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY); SwitchCase newSwitchCase= ast.newSwitchCase(); newSwitchCase.setExpression(null); listRewrite.insertLast(newSwitchCase, null); listRewrite.insertLast(ast.newBreakStatement(), null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_add_default_case_description; proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_MISSING_DEFAULT_CASE, image)); }
defaultIndex++; if (!hasDefault) { listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null); defaultIndex++; listRewrite.insertAt(newSwitchCase, defaultIndex, null); defaultIndex++; listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
defaultIndex++; if (!hasDefault) { listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null); defaultIndex++; listRewrite.insertAt(newSwitchCase, defaultIndex, null); defaultIndex++; listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
private static void createMissingDefaultProposal(IInvocationContext context, SwitchStatement switchStatement, Image image, Collection<ICommandAccess> proposals) { AST ast= switchStatement.getAST(); ASTRewrite astRewrite= ASTRewrite.create(ast); ListRewrite listRewrite= astRewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY); SwitchCase newSwitchCase= ast.newSwitchCase(); newSwitchCase.setExpression(null); listRewrite.insertLast(newSwitchCase, null); listRewrite.insertLast(ast.newBreakStatement(), null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_add_default_case_description; proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_MISSING_DEFAULT_CASE, image)); }
public static void addFallThroughProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof SwitchCase && selectedNode.getParent() instanceof SwitchStatement) { AST ast= selectedNode.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(selectedNode.getParent(), SwitchStatement.STATEMENTS_PROPERTY); listRewrite.insertBefore(ast.newBreakStatement(), selectedNode, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_break_statement; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 5, image); proposals.add(proposal); } }
public static void addFallThroughProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof SwitchCase && selectedNode.getLocationInParent() == SwitchStatement.STATEMENTS_PROPERTY) { AST ast= selectedNode.getAST(); ASTNode parent= selectedNode.getParent(); // insert break: ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); listRewrite.insertBefore(ast.newBreakStatement(), selectedNode, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_break_statement; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_BREAK_STATEMENT, image); proposals.add(proposal); // insert //$FALL-THROUGH$: rewrite= ASTRewrite.create(ast); rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); ASTNode fallThroughComment= rewrite.createStringPlaceholder("//$FALL-THROUGH$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$ listRewrite.insertBefore(fallThroughComment, selectedNode, null); label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_fall_through; image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_FALL_THROUGH, image); proposals.add(proposal); } }
public static void addFallThroughProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof SwitchCase && selectedNode.getLocationInParent() == SwitchStatement.STATEMENTS_PROPERTY) { AST ast= selectedNode.getAST(); ASTNode parent= selectedNode.getParent(); // insert break: ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); listRewrite.insertBefore(ast.newBreakStatement(), selectedNode, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_break_statement; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_BREAK_STATEMENT, image); proposals.add(proposal); // insert //$FALL-THROUGH$: rewrite= ASTRewrite.create(ast); rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); ASTNode fallThroughComment= rewrite.createStringPlaceholder("//$FALL-THROUGH$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$ listRewrite.insertBefore(fallThroughComment, selectedNode, null); label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_fall_through; image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_FALL_THROUGH, image); proposals.add(proposal); } }
switchStatement.statements().add(ast.newBreakStatement());
switchStatement.statements().add(ast.newBreakStatement());