use of org.eclipse.jdt.core.dom.SwitchCase in project che by eclipse.
the class Checks method isEnumCase.
public static boolean isEnumCase(ASTNode node) {
if (node instanceof SwitchCase) {
final SwitchCase caze = (SwitchCase) node;
final Expression expression = caze.getExpression();
if (expression instanceof Name) {
final Name name = (Name) expression;
final IBinding binding = name.resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) binding;
return variableBinding.isEnumConstant();
}
}
}
return false;
}
use of org.eclipse.jdt.core.dom.SwitchCase in project che by eclipse.
the class ExtractConstantRefactoring method canReplace.
// !! - like one in ExtractTempRefactoring
private static boolean canReplace(IASTFragment fragment) {
ASTNode node = fragment.getAssociatedNode();
ASTNode parent = node.getParent();
if (parent instanceof VariableDeclarationFragment) {
VariableDeclarationFragment vdf = (VariableDeclarationFragment) parent;
if (node.equals(vdf.getName()))
return false;
}
if (parent instanceof ExpressionStatement)
return false;
if (parent instanceof SwitchCase) {
if (node instanceof Name) {
Name name = (Name) node;
ITypeBinding typeBinding = name.resolveTypeBinding();
if (typeBinding != null) {
return !typeBinding.isEnum();
}
}
}
return true;
}
use of org.eclipse.jdt.core.dom.SwitchCase in project AutoRefactor by JnRouvignac.
the class SwitchRefactoring method getSwitchStructure.
private List<SwitchCaseSection> getSwitchStructure(final SwitchStatement node) {
final List<SwitchCaseSection> switchStructure = new ArrayList<SwitchCaseSection>();
SwitchCaseSection currentCase = new SwitchCaseSection();
for (final Statement stmt : statements(node)) {
if (stmt instanceof SwitchCase) {
final SwitchCase swithCase = (SwitchCase) stmt;
if (!currentCase.stmts.isEmpty()) {
switchStructure.add(currentCase);
currentCase = new SwitchCaseSection();
}
currentCase.existingCases.add(swithCase);
} else {
currentCase.stmts.add(stmt);
}
}
if (!currentCase.existingCases.isEmpty()) {
switchStructure.add(currentCase);
}
return switchStructure;
}
use of org.eclipse.jdt.core.dom.SwitchCase in project AutoRefactor by JnRouvignac.
the class ASTBuilder method case0.
/**
* Builds a new {@link SwitchCase} instance.
*
* @param expr
* the case expression
* @return a new switch case statement
*/
public SwitchCase case0(Expression expr) {
final SwitchCase sc = ast.newSwitchCase();
sc.setExpression(expr);
return sc;
}
use of org.eclipse.jdt.core.dom.SwitchCase in project eclipse-pmd by acanda.
the class DefaultLabelNotLastInSwitchStmtQuickFix method apply.
/**
* 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}.
*/
@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;
}
Aggregations