List of usage examples for org.eclipse.jdt.core.dom SwitchStatement getStartPosition
public final int getStartPosition()
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(SwitchStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); languageConstructs.add(/*from w w w . j a v a 2 s . co m*/ new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); return true; }
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 w w. jav a 2 s. co m _container.add(new Hint("switch", startLoc, endLoc, hint)); //$NON-NLS-1$ } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
private CAstNode visit(SwitchStatement n, WalkContext context) { ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition()); CAstNode breakAst = visitNode(breakTarget, context); String loopLabel = (String) context.getLabelMap().get(n); // set by labeled statement (if there is one before this // switch statement) WalkContext childContext = new BreakContext(context, loopLabel, breakTarget); Expression cond = n.getExpression(); List/* <Statement> */ cases = n.statements(); // First compute the control flow edges for the various case labels for (int i = 0; i < cases.size(); i++) { Statement se = (Statement) cases.get(i); if (se instanceof SwitchCase) { SwitchCase c = (SwitchCase) se; if (c.isDefault()) context.cfg().add(n, c, CAstControlFlowMap.SWITCH_DEFAULT); else// ww w . j av a 2 s.c om context.cfg().add(n, c, getSwitchCaseConstant(c, context)); // if we don't do this, we may not get a constant but a // block expression or something else } } ArrayList<CAstNode> caseNodes = new ArrayList<CAstNode>(); // polyglot bundles all statements in between two statements into a block. // this is temporary place to hold current bundle of nodes. ArrayList<CAstNode> currentBlock = new ArrayList<CAstNode>(); // Now produce the CAst representation for each case for (Object o : cases) { Statement s = (Statement) o; if (s instanceof SwitchCase) { if (!currentBlock.isEmpty()) { // bundle up statements before this case CAstNode stmtNodes[] = currentBlock.toArray(new CAstNode[currentBlock.size()]); // make position from start of first statement to end of last statement T positionOfAll = makePosition(childContext.pos().getPosition(stmtNodes[0]).getFirstOffset(), childContext.pos().getPosition(stmtNodes[stmtNodes.length - 1]).getLastOffset()); caseNodes.add(makeNode(childContext, fFactory, positionOfAll, CAstNode.BLOCK_STMT, stmtNodes)); currentBlock.clear(); } caseNodes.add(visitNode(s, childContext)); } else { visitNodeOrNodes(s, childContext, currentBlock); } } if (!currentBlock.isEmpty()) { // bundle up statements before this case CAstNode stmtNodes[] = currentBlock.toArray(new CAstNode[currentBlock.size()]); // make position from start of first statement to end of last statement T positionOfAll = makePosition(childContext.pos().getPosition(stmtNodes[0]).getFirstOffset(), childContext.pos().getPosition(stmtNodes[stmtNodes.length - 1]).getLastOffset()); caseNodes.add(makeNode(childContext, fFactory, positionOfAll, CAstNode.BLOCK_STMT, stmtNodes)); } // Now produce the switch stmt itself CAstNode switchAst = makeNode(context, fFactory, n, CAstNode.SWITCH, visitNode(cond, context), makeNode( context, fFactory, n, CAstNode.BLOCK_STMT, caseNodes.toArray(new CAstNode[caseNodes.size()]))); context.cfg().map(n, switchAst); // Finally, wrap the entire switch in a block so that we have a // well-defined place to 'break' to. return makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, switchAst, breakAst); }
From source file:net.sf.eclipsecs.ui.quickfixes.coding.MissingSwitchDefaultQuickfix.java
License:Open Source License
/** * {@inheritDoc}//w w w. java 2 s . c om */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { public boolean visit(SwitchStatement node) { if (containsPosition(lineInfo, node.getStartPosition())) { SwitchCase defNode = node.getAST().newSwitchCase(); defNode.setExpression(null); node.statements().add(defNode); node.statements().add(node.getAST().newBreakStatement()); } return true; // also visit children } }; }
From source file:org.key_project.sed.key.core.model.KeYBranchStatement.java
License:Open Source License
/** * Computes the {@link SourceLocation} which values are returned via * {@link #getLineNumber()}, {@link #getCharStart()} and {@link #getCharEnd()}. * @return The computed {@link SourceLocation}. * @throws DebugException Occurred Exception. *//*from w w w. j a va 2 s . c o m*/ protected SourceLocation computeSourceLocation() throws DebugException { SourceLocation location = KeYUtil.convertToSourceLocation(executionNode.getActivePositionInfo()); ASTNode statementNode = KeYModelUtil.findASTNode(this, location); if (statementNode != null) { if (statementNode instanceof IfStatement) { IfStatement ifStatement = (IfStatement) statementNode; return new SourceLocation(-1, ifStatement.getStartPosition(), ifStatement.getThenStatement().getStartPosition()); } else if (statementNode instanceof SwitchStatement) { SwitchStatement switchStatement = (SwitchStatement) statementNode; @SuppressWarnings("unchecked") Object firstCase = CollectionUtil.getFirst(switchStatement.statements()); if (firstCase != null) { Assert.isTrue(firstCase instanceof ASTNode); return new SourceLocation(-1, switchStatement.getStartPosition(), ((ASTNode) firstCase).getStartPosition()); } else { return KeYModelUtil.updateLocationFromAST(location, statementNode); } } else { return KeYModelUtil.updateLocationFromAST(location, statementNode); } } else { return location; } }
From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java
License:Open Source License
/** Visit an ast node, and return whether its children should be further * visited./*from w w w . jav a 2 s . c om*/ * * @param node The AST node. * @return Whether its children should be further visited. */ public boolean visit(SwitchStatement node) { _output(_indent); _output("switch ("); node.getExpression().accept(this); _output(") "); _openBrace(); for (Iterator it = node.statements().iterator(); it.hasNext();) { Statement s = (Statement) it.next(); if (!(s instanceof SwitchCase)) { _increaseIndent(); } s.accept(this); if (!(s instanceof SwitchCase)) { _decreaseIndent(); } } _checkComments((node.getStartPosition() + node.getLength()) - 1); _closeBrace(); return false; }
From source file:sharpen.core.CSharpBuilder.java
License:Open Source License
public boolean visit(SwitchStatement node) { _currentContinueLabel = null;// w w w .ja v a 2s . c o m CSBlock saved = _currentBlock; ITypeBinding switchType = node.getExpression().resolveTypeBinding(); CSSwitchStatement mappedNode = new CSSwitchStatement(node.getStartPosition(), mapExpression(node.getExpression())); addStatement(mappedNode); CSCaseClause defaultClause = null; CSCaseClause current = null; CSBlock openCaseBlock = null; _currentBlock = null; for (ASTNode element : Types.<Iterable<ASTNode>>cast(node.statements())) { if (ASTNode.SWITCH_CASE == element.getNodeType()) { if (null == current) { if (_currentBlock != null) { List<CSStatement> stats = _currentBlock.statements(); CSStatement lastStmt = stats.size() > 0 ? stats.get(stats.size() - 1) : null; if (!(lastStmt instanceof CSThrowStatement) && !(lastStmt instanceof CSReturnStatement) && !(lastStmt instanceof CSBreakStatement) && !(lastStmt instanceof CSGotoStatement)) openCaseBlock = _currentBlock; } current = new CSCaseClause(); mappedNode.addCase(current); _currentBlock = current.body(); } SwitchCase sc = (SwitchCase) element; if (sc.isDefault()) { defaultClause = current; current.isDefault(true); if (openCaseBlock != null) openCaseBlock.addStatement(new CSGotoStatement(Integer.MIN_VALUE, "default")); } else { ITypeBinding stype = pushExpectedType(switchType); CSExpression caseExpression = mapExpression(sc.getExpression()); current.addExpression(caseExpression); popExpectedType(stype); if (openCaseBlock != null) openCaseBlock.addStatement(new CSGotoStatement(Integer.MIN_VALUE, caseExpression)); } openCaseBlock = null; } else { element.accept(this); current = null; } } if (openCaseBlock != null) openCaseBlock.addStatement(new CSBreakStatement(Integer.MIN_VALUE)); if (null != defaultClause) { List<CSStatement> stats = defaultClause.body().statements(); CSStatement lastStmt = stats.size() > 0 ? stats.get(stats.size() - 1) : null; if (!(lastStmt instanceof CSThrowStatement)) { defaultClause.body().addStatement(new CSBreakStatement(Integer.MIN_VALUE)); } } _currentBlock = saved; return false; }