List of usage examples for org.eclipse.jdt.core.dom SwitchStatement getExpression
public Expression getExpression()
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 v a 2 s . c o 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 . j a v a 2 s . com 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:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from www.j a v a2 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 ww w. j a va 2 s.c o m 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(); }/* w ww .j ava 2 s . c o 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.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(SwitchStatement node) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_switch, this.options.insert_space_after_opening_paren_in_switch); handleTokenAfter(node.getExpression(), TokenNameRPAREN, this.options.insert_space_before_closing_paren_in_switch, false); handleTokenAfter(node.getExpression(), TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_switch, false); return true;//from w w w .ja v a 2 s. c o m }
From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
@Override public boolean visit(SwitchStatement node) { String hint = GetNodeText(node.getExpression()); int startLoc = node.getStartPosition(); int endLoc = startLoc + node.getLength() - 1; hint = "switch( " + hint + " )"; //$NON-NLS-1$ //$NON-NLS-2$ _scopeStack.push(new ScopeInfo(hint, startLoc, node)); try {// w ww . j a va 2 s. com _container.add(new Hint("switch", startLoc, endLoc, hint)); //$NON-NLS-1$ } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
From source file:com.drgarbage.ast.ASTGraphUtil.java
License:Apache License
/** * Returns nodes description./* ww w.j a va2 s . c o m*/ * * @param node the AST-node * @return description string */ public static String getNodeDescr(ASTNode node) { StringBuffer elementDescr = new StringBuffer(node.getClass().getSimpleName()); elementDescr.append(": "); int nodeType = node.getNodeType(); switch (nodeType) { case ASTNode.COMPILATION_UNIT: CompilationUnit cu = (CompilationUnit) node; elementDescr.append(cu.getJavaElement().getElementName()); break; case ASTNode.PACKAGE_DECLARATION: PackageDeclaration pd = (PackageDeclaration) node; elementDescr.append(pd.getName()); break; case ASTNode.TYPE_DECLARATION: TypeDeclaration td = (TypeDeclaration) node; appendModifiers(td.getModifiers(), elementDescr); elementDescr.append(" class "); elementDescr.append(td.getName()); break; case ASTNode.METHOD_DECLARATION: MethodDeclaration md = (MethodDeclaration) node; appendModifiers(md.getModifiers(), elementDescr); elementDescr.append(md.getReturnType2() == null ? "" : md.getReturnType2().toString()); elementDescr.append(' '); elementDescr.append(md.getName()); elementDescr.append("()"); break; case ASTNode.BLOCK: elementDescr.append("{...}"); break; case ASTNode.IF_STATEMENT: IfStatement is = (IfStatement) node; elementDescr.append("if( "); elementDescr.append(is.getExpression().toString()); elementDescr.append(")"); break; case ASTNode.FOR_STATEMENT: ForStatement fs = (ForStatement) node; elementDescr.append("for (...; "); elementDescr.append(fs.getExpression().toString()); elementDescr.append("; ...){...}"); break; case ASTNode.WHILE_STATEMENT: WhileStatement ws = (WhileStatement) node; elementDescr.append("while ( "); elementDescr.append(ws.getExpression().toString()); elementDescr.append("){...}"); break; case ASTNode.DO_STATEMENT: DoStatement ds = (DoStatement) node; elementDescr.append("do {...} while ("); elementDescr.append(ds.getExpression().toString()); elementDescr.append(")"); break; case ASTNode.LABELED_STATEMENT: LabeledStatement ls = (LabeledStatement) node; elementDescr.append(ls.getLabel().toString()); elementDescr.append(":"); break; case ASTNode.CATCH_CLAUSE: CatchClause cs = (CatchClause) node; elementDescr.append("catch ("); elementDescr.append(cs.getException().toString()); elementDescr.append("){...}"); break; case ASTNode.SWITCH_STATEMENT: SwitchStatement ss = (SwitchStatement) node; elementDescr.append("switch ("); elementDescr.append(ss.getExpression().toString()); elementDescr.append("){...}"); break; case ASTNode.SWITCH_CASE: SwitchCase sc = (SwitchCase) node; elementDescr.append("case "); elementDescr.append(sc.getExpression() == null ? "default" : sc.getExpression().toString()); elementDescr.append(":"); break; case ASTNode.JAVADOC: case ASTNode.BLOCK_COMMENT: case ASTNode.LINE_COMMENT: case ASTNode.TRY_STATEMENT: /* nothing to do */ break; default: elementDescr.append(node.toString()); } /* cut the string if it is too long */ String str = elementDescr.toString(); if (str.length() > 128) { str = str.substring(0, 128) + " ... "; } str = str.replaceAll("\n", ""); return str; }
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;//from w w w .ja va2 s.c om 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//from ww w. j a v a2 s. com 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; }