/** Generate the given object. * * @param whileLoop the while-loop. * @param it the target for the generated content. * @param context the context. * @return the last statement in the loop or {@code null}. */ protected XExpression _generate(XWhileExpression whileLoop, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("while "); //$NON-NLS-1$ generate(whileLoop.getPredicate(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); final XExpression last = generate(whileLoop.getBody(), it, context); it.decreaseIndentation(); return last; }
/** Generate the given object. * * @param whileLoop the while-loop. * @param it the target for the generated content. * @param context the context. * @return the last statement in the loop or {@code null}. */ protected XExpression _generate(XDoWhileExpression whileLoop, IAppendable it, IExtraLanguageGeneratorContext context) { generate(whileLoop.getBody(), it, context); it.newLine(); it.append("while "); //$NON-NLS-1$ generate(whileLoop.getPredicate(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); final XExpression last = generate(whileLoop.getBody(), it, context); it.decreaseIndentation(); return last; }
/** Generate the given object. * * @param forLoop the for-loop. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XForLoopExpression forLoop, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("for "); //$NON-NLS-1$ final String varName = it.declareUniqueNameVariable(forLoop.getDeclaredParam(), forLoop.getDeclaredParam().getSimpleName()); it.append(varName); it.append(" in "); //$NON-NLS-1$ generate(forLoop.getForExpression(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); final XExpression last = generate(forLoop.getEachExpression(), it, context); it.decreaseIndentation(); return last; }
/** Generate the given object. * * @param tryStatement the try-catch-finally statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XTryCatchFinallyExpression tryStatement, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("try:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(tryStatement.getExpression(), context.getExpectedExpressionType(), it, context); it.decreaseIndentation().newLine(); for (final XCatchClause clause : tryStatement.getCatchClauses()) { it.append("except "); //$NON-NLS-1$ it.append(clause.getDeclaredParam().getParameterType().getType()); it.append(", "); //$NON-NLS-1$ it.append(it.declareUniqueNameVariable(clause.getDeclaredParam(), clause.getDeclaredParam().getSimpleName())); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(clause.getExpression(), context.getExpectedExpressionType(), it, context); it.decreaseIndentation().newLine(); } if (tryStatement.getFinallyExpression() != null) { it.append("finally:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(tryStatement.getFinallyExpression(), it, context); it.decreaseIndentation(); } return tryStatement; }
it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ it.decreaseIndentation(); if (ifStatement.getElse() != null) { it.newLine().append("else:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(ifStatement.getElse(), context.getExpectedExpressionType(), it, context); it.decreaseIndentation(); } else if (context.getExpectedExpressionType() != null) { it.newLine().append("else:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ it.decreaseIndentation();
/** Generate the given object. * * @param forLoop the for-loop. * @param it the target for the generated content. * @param context the context. * @return the last statement in the loop or {@code null}. */ protected XExpression _generate(XBasicForLoopExpression forLoop, IAppendable it, IExtraLanguageGeneratorContext context) { for (final XExpression expr : forLoop.getInitExpressions()) { generate(expr, it, context); it.newLine(); } it.append("while "); //$NON-NLS-1$ generate(forLoop.getExpression(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); final XExpression last = generate(forLoop.getEachExpression(), it, context); for (final XExpression expr : forLoop.getUpdateExpressions()) { it.newLine(); generate(expr, it, context); } it.decreaseIndentation(); return last; }
/** Generate the given object. * * @param assertStatement the assert statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(SarlAssertExpression assertStatement, IAppendable it, IExtraLanguageGeneratorContext context) { final boolean haveAssert = !assertStatement.isIsStatic() && assertStatement.getCondition() != null; if (haveAssert) { it.append("assert (lambda:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(assertStatement.getCondition(), it, context); it.decreaseIndentation().newLine(); it.append(")()"); //$NON-NLS-1$ } if (context.getExpectedExpressionType() != null) { if (haveAssert) { it.newLine(); } it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return assertStatement; }
it.append("pass"); //$NON-NLS-1$ it.decreaseIndentation().decreaseIndentation().newLine(); it.closeScope();
it.append("pass"); //$NON-NLS-1$ it.decreaseIndentation().newLine(); it.increaseIndentation().newLine(); generate(switchStatement.getDefault(), it, context); it.decreaseIndentation().newLine();