use of org.eclipse.jdt.core.dom.SwitchStatement in project AutoRefactor by JnRouvignac.
the class ASTBuilder method switch0.
/**
* Builds a new {@link SwitchStatement} instance.
*
* @param expr
* the switch expression
* @return a new switch statement
*/
public SwitchStatement switch0(Expression expr) {
final SwitchStatement ss = ast.newSwitchStatement();
ss.setExpression(expr);
return ss;
}
use of org.eclipse.jdt.core.dom.SwitchStatement in project eclipse.jdt.ls by eclipse.
the class ExtractMethodAnalyzer method getParentLoopBody.
private Statement getParentLoopBody(ASTNode node) {
Statement stmt = null;
ASTNode start = node;
while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) {
start = start.getParent();
}
if (start instanceof ForStatement) {
stmt = ((ForStatement) start).getBody();
} else if (start instanceof DoStatement) {
stmt = ((DoStatement) start).getBody();
} else if (start instanceof WhileStatement) {
stmt = ((WhileStatement) start).getBody();
} else if (start instanceof EnhancedForStatement) {
stmt = ((EnhancedForStatement) start).getBody();
}
if (start != null && start.getParent() instanceof LabeledStatement) {
LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
fEnclosingLoopLabel = labeledStatement.getLabel();
}
return stmt;
}
use of org.eclipse.jdt.core.dom.SwitchStatement in project eclipse.jdt.ls by eclipse.
the class FlowAnalyzer method createSwitchData.
// ---- Helper to process switch statement ----------------------------------------
protected SwitchData createSwitchData(SwitchStatement node) {
SwitchData result = new SwitchData();
List<Statement> statements = node.statements();
if (statements.isEmpty()) {
return result;
}
int start = -1, end = -1;
GenericSequentialFlowInfo info = null;
for (Iterator<Statement> iter = statements.iterator(); iter.hasNext(); ) {
Statement statement = iter.next();
if (statement instanceof SwitchCase) {
SwitchCase switchCase = (SwitchCase) statement;
if (switchCase.isDefault()) {
result.setHasDefaultCase();
}
if (info == null) {
info = createSequential();
start = statement.getStartPosition();
} else {
if (info.isReturn() || info.isPartialReturn() || info.branches()) {
result.add(new Region(start, end - start + 1), info);
info = createSequential();
start = statement.getStartPosition();
}
}
} else {
info.merge(getFlowInfo(statement), fFlowContext);
}
end = statement.getStartPosition() + statement.getLength() - 1;
}
result.add(new Region(start, end - start + 1), info);
return result;
}
use of org.eclipse.jdt.core.dom.SwitchStatement in project whole by wholeplatform.
the class SimpleEntityImplBuilder method addField.
public void addField(String fType, String fName, String name, boolean isId, boolean isOptional, boolean isReference, boolean isShared, boolean isDerived) {
// if (StringUtils.isAmbiguous(fType))
if (!StringUtils.isPrimitiveOrString(fType))
addImportDeclaration(generator.modelPackage() + "." + fType);
if (isId) {
hashCodeMethodAddId(fType, fName);
equalsMethodAddId(fType, fName);
toStringMethodAddField(fType, fName);
}
// add field, getter and setter methods
addBodyDeclaration(newFieldDeclaration(fType, fName));
addBodyDeclaration(newGetterMethodWithNotification(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fType, fName, name));
addBodyDeclaration(newSetterMethodWithNotification(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fType, fName, name, isReference));
if (StringUtils.isPrimitiveOrString(fType))
return;
// add get(int index) case
if (getByIndexMethod().getBody().statements().size() == 0) {
SwitchStatement switchStm = newSwitchStatement(ast.newSimpleName("index"));
getByIndexMethod().getBody().statements().add(switchStm);
getByIndexSwitchStatements = switchStm.statements();
}
getByIndexSwitchStatements.add(newCaseStatement(newLiteral(featureIndex)));
getByIndexSwitchStatements.add(newReturnStatement(newMethodInvocation(newMethodInvocation(StringUtils.getterName(StringUtils.isJavaKeyword(name) ? name : fName)), "wGetAdaptee", newLiteral(false))));
// add set(int index, IEntity value) case
if (setByIndexMethod().getBody().statements().size() == 0) {
SwitchStatement switchStm = newSwitchStatement(ast.newSimpleName("index"));
setByIndexMethod().getBody().statements().add(switchStm);
setByIndexSwitchStatements = switchStm.statements();
}
setByIndexSwitchStatements.add(newCaseStatement(newLiteral(featureIndex)));
MethodInvocation callExp = newMethodInvocation(StringUtils.setterName(StringUtils.isJavaKeyword(name) ? name : fName), newMethodInvocation(ast.newSimpleName("value"), "wGetAdapter", newFieldAccess(((LanguageGenerator) generator).specificEntityDescriptorEnumName(), fType)));
setByIndexSwitchStatements.add(newExpressionStatement(callExp));
setByIndexSwitchStatements.add(ast.newBreakStatement());
featureIndex++;
if (isReference)
references++;
else
children++;
}
use of org.eclipse.jdt.core.dom.SwitchStatement in project whole by wholeplatform.
the class GenericBuilderAdapterBuilder method getFeatureMethodSwitch.
protected List getFeatureMethodSwitch(String type) {
List cases = featureSwitchMap.get(type);
if (cases == null) {
MethodDeclaration method = newMethodDeclaration("void", type, newSingleVariableDeclaration(FeatureDescriptor.class.getName(), "featureDesc"));
SwitchStatement switchStm = newSwitchStatement(newMethodInvocation("featureDesc", "getOrdinal"));
method.getBody().statements().add(switchStm);
addBodyDeclaration(method);
featureSwitchMap.put(type, cases = switchStm.statements());
}
return cases;
}
Aggregations