List of usage examples for org.eclipse.jdt.core.dom SwitchCase getStartPosition
public final int getStartPosition()
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(SwitchCase 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(// ww w .jav a2 s . com 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(SwitchCase node) { /* TODO: specific params: don't show the switch part (only the case argument) */ try {/*from ww w.j ava2s. com*/ 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:net.sf.eclipsecs.ui.quickfixes.coding.DefaultComesLastQuickfix.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j ava 2s . c o m */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { public boolean visit(SwitchCase node) { if (containsPosition(lineInfo, node.getStartPosition())) { if (node.isDefault() && !isLastSwitchCase(node)) { SwitchStatement switchStatement = (SwitchStatement) node.getParent(); List defaultCaseStatements = new ArrayList(); defaultCaseStatements.add(node); // collect all statements belonging to the default case int defaultStatementIndex = switchStatement.statements().indexOf(node); for (int i = defaultStatementIndex + 1; i < switchStatement.statements().size(); i++) { ASTNode tmpNode = (ASTNode) switchStatement.statements().get(i); if (!(tmpNode instanceof SwitchCase)) { defaultCaseStatements.add(tmpNode); } else { break; } } // move the statements to the end of the statement list switchStatement.statements().removeAll(defaultCaseStatements); switchStatement.statements().addAll(defaultCaseStatements); } } return true; } private boolean isLastSwitchCase(SwitchCase switchCase) { SwitchStatement switchStatement = (SwitchStatement) switchCase.getParent(); // collect all statements belonging to the default case int defaultStatementIndex = switchStatement.statements().indexOf(switchCase); for (int i = defaultStatementIndex + 1; i < switchStatement.statements().size(); i++) { ASTNode tmpNode = (ASTNode) switchStatement.statements().get(i); if (tmpNode instanceof SwitchCase) { return false; } } return true; } }; }