// ;
sb.append(";" + EOL);
} else if (statement instanceof ExpressionStatement) {
ExpressionStatement expressionStatement = (ExpressionStatement)statement;
String expressionSource = getSource(expressionStatement.getJavaExpression(), indent, 0, context);
emitLine(sb, 0, expressionSource + ";");
} else if (statement instanceof LineComment) {
LineComment lineComment = (LineComment)statement;
emitLine(sb, indent, "// " + lineComment.getCommentText());
} else if (statement instanceof MultiLineComment) {
boolean isJavaDoc = (statement instanceof JavaDocComment);
MultiLineComment jdc = (MultiLineComment)statement;
Iterator<String> it = jdc.getCommentLines().iterator();
String firstLine = it.next();
boolean nd = !firstLine.startsWith("/*");
if (nd) {
emitLine(sb, indent, isJavaDoc ? "/**" : "/*");
}
it = jdc.getCommentLines().iterator();
while (it.hasNext()) {
String line = it.next();
if (nd) {
emitLine(sb, indent, " * " + line);
} else {
emitLine(sb, indent, line);
}
}
if (nd) {
emitLine(sb, indent, " */");
}
} else if (statement instanceof ReturnStatement) {
ReturnStatement returnStatement = (ReturnStatement)statement;
if (returnStatement.getReturnExpression() == null) {
emitLine(sb, indent, "return;");
} else {
emitLine(sb, indent, "return " + getSource(returnStatement.getReturnExpression(),indent, 7, context) + ";");
}
} else if (statement instanceof IfThenElseStatement) {
IfThenElseStatement iteStatement = (IfThenElseStatement)statement;
emitLine(sb, indent, "if (" + getSource(iteStatement.getCondition(), indent, 4, context) + ") {");
sb.append(getSource(iteStatement.getThenStatement(), context, indent + 1));
// Emit the else clause only if there is one.
StringBuilder elseClause = getSource(iteStatement.getElseStatement(), context, indent + 1);
if (elseClause.length() > 0) {
emitLine(sb, indent, "} else {");
sb.append(elseClause);
}
emitLine(sb, indent, "}");
} else if (statement instanceof SwitchStatement) {
SwitchStatement switchStatement = (SwitchStatement)statement;
JavaExpression condition = switchStatement.getCondition();
List<IntCaseGroup> caseGroups = switchStatement.getCaseGroups();
JavaStatement defaultStatementGroup = switchStatement.getDefaultStatement();
// Sort cases by the first case label in each group.
Collections.sort(caseGroups, new Comparator<IntCaseGroup>() {
public int compare(IntCaseGroup o1, IntCaseGroup o2) {
int int1 = o1.getNthCaseLabel(0);
int int2 = o2.getNthCaseLabel(0);
if (int1 < int2) {
return -1;
}
if (int1 > int2) {
return 1;
}
return 0;
}
});
emitIndent (sb, indent);
int length = sb.length();
sb.append("switch (");
String conditionString = getSource(condition, 0, 0, context, true);
conditionString = conditionString.replaceAll(EOL," ");
sb.append(conditionString);
if (sb.lastIndexOf(EOL, length) >= 0) {
emitLine(sb);
emitIndent(sb, indent);
for (int i = 0; i < 7; ++i) {
sb.append(" ");
}
sb.append (") {");
emitLine (sb);
} else {
sb.append(") {");
emitLine(sb);
}
emitLine(sb);
// case labels and their statement groups.
for (final IntCaseGroup switchCaseGroup : caseGroups) {
JavaStatement caseStatementGroup = switchCaseGroup.getStatement();
int nCaseLabels = switchCaseGroup.getNCaseLabels();
for (int i = 0; i < nCaseLabels - 1; i++) {
emitLine(sb, indent + 1, "case " + switchCaseGroup.getNthCaseLabel(i) + ":");
}
emitLine(sb, indent + 1, "case " + switchCaseGroup.getNthCaseLabel(nCaseLabels - 1) + ": {");
sb.append(getSource(caseStatementGroup, context, indent + 2));
emitLine(sb, indent + 1, "}");
emitLine(sb);
}
// default label and statement group.
if (defaultStatementGroup != null) {
emitLine(sb, indent + 1, "default: {");
sb.append(getSource(defaultStatementGroup, context, indent + 2));
emitLine(sb, indent + 1, "}");
}
emitLine(sb, indent, "}");
} else if (statement instanceof Block) {
Block block = (Block)statement;
int blockIndent = indent;
List<JavaExceptionHandler> exceptionHandlers = block.getExceptionHandlers();
if (!exceptionHandlers.isEmpty()) {
emitLine(sb, indent, "try {");
blockIndent++;
}
boolean doingLocalVarDeclarations = false;
boolean wasLineComment = false;
int nStatements = block.getNBlockStatements();
for (int i = 0; i < nStatements; i++) {
JavaStatement blockStatement = block.getNthBlockStatement(i);
// Try to separate local var declarations from other types of block statements.
boolean isLocalVarDeclaration = blockStatement instanceof LocalVariableDeclaration;
if (!wasLineComment && isLocalVarDeclaration != doingLocalVarDeclarations && i > 0) {
sb.append(EOL);
}
doingLocalVarDeclarations = isLocalVarDeclaration;
wasLineComment = blockStatement instanceof LineComment;
// Now append the source.
sb.append(getSource(blockStatement, context, blockIndent));
}
if (!exceptionHandlers.isEmpty()) {
for (final JavaExceptionHandler eh : exceptionHandlers) {
emitLine(sb, indent, "} catch (" + fixupClassName(eh.getExceptionClass().getName()) + " " + eh.getExceptionVarName() + ") {");
sb.append(getSource(eh.getHandlerCode(), context, blockIndent));
}
emitLine(sb, indent, "}");
}
} else
if (statement instanceof ThrowStatement) {
ThrowStatement throwStatement = (ThrowStatement)statement;
emitLine(sb, indent, "throw " + getSource(throwStatement.getThrownExpression(), indent, 6, context) + ";");
} else
if (statement instanceof UnconditionalLoop) {
UnconditionalLoop whileStatement = (UnconditionalLoop)statement;
emitLine (sb, indent, whileStatement.getLabel() + ": while (true) {");
sb.append(getSource(whileStatement.getBody(), context, indent + 1));
emitLine (sb, indent, "}");
} else
if (statement instanceof LabelledContinue) {
LabelledContinue lc = (LabelledContinue)statement;
emitLine (sb, indent, "continue " + lc.getLabel() + ";");
} else
if (statement instanceof SynchronizedMethodInvocation){
// A method invocation wrapped in a synchronization block.
SynchronizedMethodInvocation sof = (SynchronizedMethodInvocation)statement;
// Start the synchronized block.
emitLine (sb, indent, "synchronized (" + getSource(sof.getSynchronizingObject(), indent, 14, context) + ") {");
// Add the method invocation.
sb.append (getSource(new ExpressionStatement(sof.getMethodInvocation()), context, indent + 1));
// Finish the block.
emitLine (sb, indent, "}");
} else
if (statement instanceof AssertStatement) {