private static void appendReturnIfExpectedReturnedExpression(IAppendable it, IExtraLanguageGeneratorContext context) { if (context.getExpectedExpressionType() != null) { it.append("return "); //$NON-NLS-1$ } }
/** Generate the given object. * * @param literal the null literal. * @param it the target for the generated content. * @param context the context. * @return the literal. */ @SuppressWarnings("static-method") protected XExpression _generate(XNullLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append("None"); //$NON-NLS-1$ return literal; }
/** Generate the given object. * * @param literal the literal. * @param it the target for the generated content. * @param context the context. * @return the literal. */ @SuppressWarnings("static-method") protected XExpression _generate(XStringLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append("u\"").append(Strings.convertToJavaString(literal.getValue())).append("\""); //$NON-NLS-1$//$NON-NLS-2$ return literal; }
private void serializeTypeArguments(JvmParameterizedTypeReference reference, EObject context, IAppendable tracedAppendable, boolean withoutConstraints, boolean paramsToWildcard, boolean paramsToObject) { if (!reference.getArguments().isEmpty()) { tracedAppendable.append("<"); for(int i = 0; i < reference.getArguments().size(); i++) { if (i != 0) { tracedAppendable.append(", "); } serialize(reference.getArguments().get(i), context, tracedAppendable, withoutConstraints, paramsToWildcard, paramsToObject, false); } tracedAppendable.append(">"); } }
/** Generate the given object. * * @param breakStatement the break statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ @SuppressWarnings("static-method") protected XExpression _generate(SarlBreakExpression breakStatement, IAppendable it, IExtraLanguageGeneratorContext context) { if (context.getExpectedExpressionType() == null) { it.append("break"); //$NON-NLS-1$ } else { it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return breakStatement; }
/** Generate the given object. * * @param continueStatement the continue statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ @SuppressWarnings("static-method") protected XExpression _generate(SarlContinueExpression continueStatement, IAppendable it, IExtraLanguageGeneratorContext context) { if (context.getExpectedExpressionType() == null) { it.append("continue"); //$NON-NLS-1$ } else { it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return continueStatement; }
/** Generate the given object. * * @param operator the instance-of operator. * @param it the target for the generated content. * @param context the context. * @return the expression. */ protected XExpression _generate(XInstanceOfExpression operator, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append("isinstance("); //$NON-NLS-1$ generate(operator.getExpression(), it, context); it.append(", "); //$NON-NLS-1$ it.append(operator.getType().getType()); it.append(")"); //$NON-NLS-1$ return operator; }
/** Generate the given object. * * @param closure the closure. * @param it the target for the generated content. * @param context the context. * @return the closure. */ @SuppressWarnings("static-method") protected XExpression _generate(XClosure closure, IAppendable it, IExtraLanguageGeneratorContext context) { if (it.hasName(closure)) { appendReturnIfExpectedReturnedExpression(it, context); it.append(it.getName(closure)).append("()"); //$NON-NLS-1$ } return closure; }
/** Generate the given object. * * @param returnStatement the return statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XReturnExpression returnStatement, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("return "); //$NON-NLS-1$ generate(returnStatement.getExpression(), it, context); return returnStatement; }
/** Generate the given object. * * @param throwStatement the throw statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XThrowExpression throwStatement, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("raise "); //$NON-NLS-1$ generate(throwStatement.getExpression(), it, context); return throwStatement; }
/** Generate the given object. * * @param literal the literal. * @param it the target for the generated content. * @param context the context. * @return the literal. */ @SuppressWarnings("static-method") protected XExpression _generate(XNumberLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append(literal.getValue()); return literal; }
/** Generate the given object. * * @param literal the type literal. * @param it the target for the generated content. * @param context the context. * @return the literal. */ @SuppressWarnings("static-method") protected XExpression _generate(XTypeLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append(literal.getType()); return literal; }
/** Generate the given object. * * @param assignment the assignment operator. * @param it the target for the generated content. * @param context the context. * @return the assignment. */ protected XExpression _generate(XAssignment assignment, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append("("); //$NON-NLS-1$ newFeatureCallGenerator(context, it).generate(assignment); it.append(" = "); //$NON-NLS-1$ generate(assignment.getValue(), it, context); it.append(")"); //$NON-NLS-1$ return assignment; }
/** Generate the given object. * * @param literal the boolean literal. * @param it the target for the generated content. * @param context the context. * @return the literal. */ @SuppressWarnings("static-method") protected XExpression _generate(XBooleanLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) { appendReturnIfExpectedReturnedExpression(it, context); it.append(literal.isIsTrue() ? "True" : "False"); //$NON-NLS-1$ //$NON-NLS-2$ return literal; }
/** Generate a Python block comment with the given comment. * * @param comment the comment. * @param it the receiver of the block comment. * @return {@code true} if the block comment is added, {@code false} otherwise. */ protected static boolean generateBlockComment(String comment, PyAppendable it) { final String cmt = comment == null ? null : comment.trim(); if (!Strings.isEmpty(cmt)) { assert cmt != null; for (final String line : cmt.split("[\n\r\f]+")) { //$NON-NLS-1$ it.append("# ").append(line).newLine(); //$NON-NLS-1$ } return true; } return false; }
/** 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 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 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(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 constructor the constructor. * @param it the target for the generated content. * @param context the context. */ protected void _generate(SarlConstructor constructor, PyAppendable it, IExtraLanguageGeneratorContext context) { if (constructor.isStatic()) { generateExecutable("___static_init___", constructor, false, false, null, //$NON-NLS-1$ getTypeBuilder().getDocumentation(constructor), it, context); it.newLine().append("___static_init___()"); //$NON-NLS-1$ } else { generateExecutable("__init__", constructor, true, false, null, //$NON-NLS-1$ getTypeBuilder().getDocumentation(constructor), it, context); } }