/** Generate a Python docstring with the given comment. * * @param comment the comment. * @param it the receiver of the docstring. * @return {@code true} if the docstring is added, {@code false} otherwise. */ protected static boolean generateDocString(String comment, PyAppendable it) { final String cmt = comment == null ? null : comment.trim(); if (!Strings.isEmpty(cmt)) { assert cmt != null; it.append("\"\"\"").increaseIndentation(); //$NON-NLS-1$ for (final String line : cmt.split("[\n\r\f]+")) { //$NON-NLS-1$ it.newLine().append(line); } it.decreaseIndentation().newLine(); it.append("\"\"\"").newLine(); //$NON-NLS-1$ return true; } return false; }
/** 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; }
it.append("if "); //$NON-NLS-1$ generate(guardDesc.getKey(), null, it, context); it.append(":").increaseIndentation().newLine(); //$NON-NLS-1$ it.append(eventHandleName).append(".add(").append(guardDesc.getValue()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ 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 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; }
generate(ifStatement.getIf(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); if (ifStatement.getThen() != null) { generate(ifStatement.getThen(), context.getExpectedExpressionType(), it, context); 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("class ").append(closureName).append("(") //$NON-NLS-1$//$NON-NLS-2$ .append(closureType).append(",").append(objType.getType()).append("):") //$NON-NLS-1$ //$NON-NLS-2$ .increaseIndentation().newLine().append("def ") //$NON-NLS-1$ .append(function.getSimpleName()).append("(") //$NON-NLS-1$ .append(getExtraLanguageKeywordProvider().getThisKeywordLambda().apply()); it.increaseIndentation().newLine(); if (closure.getExpression() != null) { LightweightTypeReference returnType = closureType0;
if (!fallThrough) { it.append("):"); //$NON-NLS-1$ it.increaseIndentation().newLine(); if (caseExpression.getThen() != null) { generate(caseExpression.getThen(), it, context); } else { it.append("else:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(switchStatement.getDefault(), it, context); it.decreaseIndentation().newLine();