List of usage examples for org.eclipse.jdt.core.dom SwitchStatement statements
ASTNode.NodeList statements
To view the source code for org.eclipse.jdt.core.dom SwitchStatement statements.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(SwitchStatement node) { this.fBuffer.append("switch (");//$NON-NLS-1$ node.getExpression().accept(this); this.fBuffer.append(") ");//$NON-NLS-1$ this.fBuffer.append("{");//$NON-NLS-1$ for (Iterator<Statement> it = node.statements().iterator(); it.hasNext();) { Statement s = it.next();// w ww . ja va2 s .co m s.accept(this); } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(SwitchStatement node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.SWITCH); node.getExpression().accept(this); b.setExpression(expressions.pop());//w w w . java 2s . c o m statements.push(new ArrayList<boa.types.Ast.Statement>()); for (Object s : node.statements()) ((org.eclipse.jdt.core.dom.Statement) s).accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); list.add(b.build()); return false; }
From source file:ch.acanda.eclipse.pmd.java.resolution.design.DefaultLabelNotLastInSwitchStmtQuickFix.java
License:Open Source License
/** * Moves the default case to the last position. The default case includes the default {@code SwitchCase} and all * following statements up to the next {@code SwitchCase}. *///from w w w . ja v a2 s . c o m @Override @SuppressWarnings("unchecked") protected boolean apply(final SwitchStatement node) { final List<Statement> statements = node.statements(); final List<Statement> defaultCaseStatements = new ArrayList<>(statements.size()); boolean isDefaultCaseStatement = false; for (final Statement statement : statements) { if (statement instanceof SwitchCase) { if (((SwitchCase) statement).getExpression() == DEFAULT_LABEL) { isDefaultCaseStatement = true; } else { isDefaultCaseStatement = false; } } if (isDefaultCaseStatement) { defaultCaseStatements.add(statement); } } statements.removeAll(defaultCaseStatements); statements.addAll(defaultCaseStatements); return true; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j a va 2 s . co m public boolean visit(SwitchStatement node) { pushNode(node, node.getExpression().toString()); visitList(node.statements()); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(SwitchStatement node) { this.buffer.append("switch (");//$NON-NLS-1$ node.getExpression().accept(this); this.buffer.append(") ");//$NON-NLS-1$ this.buffer.append("{\n");//$NON-NLS-1$ this.indent++; for (Iterator it = node.statements().iterator(); it.hasNext();) { Statement s = (Statement) it.next(); s.accept(this); this.indent--; // incremented in visit(SwitchCase) }/*from w ww.j a va2s . c om*/ this.indent--; printIndent(); this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(SwitchStatement node) { handleBracedCode(node, node.getExpression(), this.options.brace_position_for_switch, this.options.indent_switchstatements_compare_to_switch, true); List<Statement> statements = node.statements(); if (this.options.indent_switchstatements_compare_to_cases) { int nonBreakStatementEnd = -1; for (Statement statement : statements) { if (statement instanceof SwitchCase) { if (nonBreakStatementEnd >= 0) { // indent only comments between previous and current statement this.tm.get(nonBreakStatementEnd + 1).indent(); this.tm.firstTokenIn(statement, -1).unindent(); }/*from w w w. ja va2 s .co m*/ } else if (!(statement instanceof BreakStatement || statement instanceof Block)) { indent(statement); } nonBreakStatementEnd = (statement instanceof BreakStatement || statement instanceof ReturnStatement) ? -1 : this.tm.lastIndexIn(statement, -1); } if (nonBreakStatementEnd >= 0) { // indent comments between last statement and closing brace this.tm.get(nonBreakStatementEnd + 1).indent(); this.tm.lastTokenIn(node, TokenNameRBRACE).unindent(); } } if (this.options.indent_breaks_compare_to_cases) { for (Statement statement : statements) { if (statement instanceof BreakStatement) indent(statement); } } for (Statement statement : statements) { if (statement instanceof Block) continue; // will add break in visit(Block) if necessary if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } return true; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.SwitchStatement node) { IfStatement mainIfStatement = null;/*ww w . j ava 2 s. c o m*/ IfStatement targetIfStatement = null; Block ifBlock = null; Expression ifCondition = null; for (Iterator<?> I = node.statements().iterator(); I.hasNext();) { Object javaMember = I.next(); if (javaMember instanceof org.eclipse.jdt.core.dom.SwitchCase) { org.eclipse.jdt.core.dom.SwitchCase javaCase = (org.eclipse.jdt.core.dom.SwitchCase) javaMember; if (javaCase.getExpression() != null) { Expression condition = binaryExpression(translateExpression(node.getExpression()), TokenType.EQ_EQ, translateExpression(javaCase.getExpression())); if (ifCondition == null) { ifCondition = condition; ifBlock = block(); IfStatement ifStatement = ifStatement(condition, ifBlock); if (mainIfStatement == null) { mainIfStatement = ifStatement; } else { targetIfStatement.setElseStatement(ifStatement); } targetIfStatement = ifStatement; } else { ifCondition = binaryExpression(ifCondition, TokenType.BAR_BAR, condition); targetIfStatement.setCondition(ifCondition); } } else { ifBlock = block(); targetIfStatement.setElseStatement(ifBlock); } } else { ifCondition = null; Statement statement = translate((org.eclipse.jdt.core.dom.Statement) javaMember); if (!(statement instanceof BreakStatement)) { ifBlock.getStatements().add(statement); } } } // wrap everything into "while(true)" to handle inner "break" WhileStatement whileStatement = whileStatement(booleanLiteral(true), block(mainIfStatement, breakStatement())); return done(whileStatement); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*ww w . ja v a 2 s . co m*/ public boolean visit(SwitchStatement node) { buffer.append("switch ("); Expression expr = node.getExpression(); ITypeBinding exprType = Types.getTypeBinding(expr); if (exprType.isEnum()) { buffer.append('['); } expr.accept(this); if (exprType.isEnum()) { buffer.append(" ordinal]"); } buffer.append(") "); buffer.append("{\n"); List<Statement> stmts = node.statements(); // safe by definition boolean needsClosingBrace = false; int nStatements = stmts.size(); for (int i = 0; i < nStatements; i++) { Statement stmt = stmts.get(i); buffer.syncLineNumbers(stmt); if (stmt instanceof SwitchCase) { if (needsClosingBrace) { buffer.append("}\n"); needsClosingBrace = false; } stmt.accept(this); if (declaresLocalVar(stmts, i + 1)) { buffer.append(" {\n"); needsClosingBrace = true; } else { buffer.append('\n'); } } else { stmt.accept(this); } } if (!stmts.isEmpty() && stmts.get(nStatements - 1) instanceof SwitchCase) { // Last switch case doesn't have an associated statement, so add // an empty one. buffer.append(";\n"); } if (needsClosingBrace) { buffer.append("}\n"); } buffer.append("}\n"); return false; }
From source file:com.google.devtools.j2objc.util.ASTUtil.java
License:Apache License
@SuppressWarnings("unchecked") public static List<Statement> getStatements(SwitchStatement node) { return node.statements(); }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link SwitchStatement}s. */ @Override//ww w . jav a2 s. co m public boolean visit(SwitchStatement node) { sync(node); token("switch"); builder.space(); token("("); node.getExpression().accept(this); token(")"); builder.space(); tokenBreakTrailingComment("{", plusTwo); builder.blankLineWanted(BlankLineWanted.NO); builder.open(plusFour); boolean first = true; boolean lastWasSwitchCase = false; for (ASTNode statement : (List<ASTNode>) node.statements()) { if (!first && !lastWasSwitchCase) { builder.blankLineWanted(BlankLineWanted.PRESERVE); } if (statement.getNodeType() == ASTNode.SWITCH_CASE) { builder.open(minusTwo); builder.forcedBreak(); visit((SwitchCase) statement); builder.close(); lastWasSwitchCase = true; } else { builder.forcedBreak(); statement.accept(this); lastWasSwitchCase = false; } first = false; } builder.close(); builder.forcedBreak(); builder.blankLineWanted(BlankLineWanted.NO); token("}", plusFour); return false; }