List of usage examples for org.eclipse.jdt.core.dom SwitchCase getExpression
public Expression getExpression()
null if there is none (the "default:" case). From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(SwitchCase node) { if (node.isDefault()) { this.fBuffer.append("default :");//$NON-NLS-1$ } else {//from w ww .j a va 2 s . c o m this.fBuffer.append("case ");//$NON-NLS-1$ node.getExpression().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(SwitchCase 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.CASE); if (node.getExpression() != null) { node.getExpression().accept(this); b.setExpression(expressions.pop()); }// w w w . j av a 2 s .c o m list.add(b.build()); return false; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(SwitchCase node) { pushNode(node, node.getExpression() != null ? node.getExpression().toString() : "default"); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(SwitchCase node) { if (node.isDefault()) { this.buffer.append("default :\n");//$NON-NLS-1$ } else {//from w ww . j a v a2 s . co m this.buffer.append("case ");//$NON-NLS-1$ node.getExpression().accept(this); this.buffer.append(":\n");//$NON-NLS-1$ } this.indent++; // decremented in visit(SwitchStatement) return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(SwitchCase node) { if (node.isDefault()) { handleToken(node, TokenNameCOLON, this.options.insert_space_before_colon_in_default, false); } else {/* w w w .j a va 2s. c om*/ handleToken(node, TokenNamecase, false, true); handleToken(node.getExpression(), TokenNameCOLON, this.options.insert_space_before_colon_in_case, false); } return true; }
From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
@Override public boolean visit(SwitchCase node) { /* TODO: specific params: don't show the switch part (only the case argument) */ try {/*from www .ja v a 2 s .c om*/ ScopeInfo scope = _scopeStack.peek(); if (!(scope._statement instanceof SwitchStatement)) { if (!(scope._statement instanceof SwitchCase)) { throw new ScopeTraceException("Lost track of stack (in case), found:" + scope._statement); //$NON-NLS-1$ } _scopeStack.pop(); scope = _scopeStack.peek(); } if (!(scope._statement instanceof SwitchStatement)) { throw new ScopeTraceException("Lost track of stack (in case2), found:" + scope._statement); //$NON-NLS-1$ } String hint = ""; //$NON-NLS-1$ if (node.isDefault()) { hint = "default"; //$NON-NLS-1$ } else { hint = "case: " + node.getExpression(); //$NON-NLS-1$ } int startLoc = node.getStartPosition(); _scopeStack.push(new ScopeInfo(scope._str + " - " + hint, startLoc, node)); //$NON-NLS-1$ } catch (ScopeTraceException e) { if (Activator.DEBUG) Activator.log(e); } catch (EmptyStackException e) { if (Activator.DEBUG) Activator.log(e); } return shouldContinue(); }
From source file:com.drgarbage.ast.ASTGraphUtil.java
License:Apache License
/** * Returns nodes description.//from w ww .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;/* w ww . java 2 s . co 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
@Override public boolean visit(SwitchCase node) { if (node.isDefault()) { buffer.append(" default:"); } else {//from w ww. ja v a2 s. c o m buffer.append(" case "); Expression expr = node.getExpression(); boolean isEnumConstant = Types.getTypeBinding(expr).isEnum(); if (isEnumConstant) { String bareTypeName = NameTable.getFullName(Types.getTypeBinding(expr)).replace("Enum", ""); buffer.append(bareTypeName).append("_"); } if (isEnumConstant && expr instanceof SimpleName) { buffer.append(((SimpleName) expr).getIdentifier()); } else if (isEnumConstant && expr instanceof QualifiedName) { buffer.append(((QualifiedName) expr).getName().getIdentifier()); } else { expr.accept(this); } buffer.append(":"); } return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(SwitchCase node) { if (node.isDefault()) { sb.println("default :"); } else {// ww w .jav a 2 s .com sb.print("case "); node.getExpression().accept(this); sb.println(":"); } sb.indent(); return false; }