Java Code Examples for org.eclipse.xtext.xbase.compiler.IAppendable#newLine()
The following examples show how to use
org.eclipse.xtext.xbase.compiler.IAppendable#newLine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** 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; }
Example 2
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** Generate the given object. * * @param varDeclaration the variable declaration. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XVariableDeclaration varDeclaration, IAppendable it, IExtraLanguageGeneratorContext context) { final String name = it.declareUniqueNameVariable(varDeclaration, varDeclaration.getName()); it.append(name); it.append(" = "); //$NON-NLS-1$ if (varDeclaration.getRight() != null) { generate(varDeclaration.getRight(), it, context); } else if (varDeclaration.getType() != null) { it.append(toDefaultValue(varDeclaration.getType())); } else { it.append("None"); //$NON-NLS-1$ } if (context.getExpectedExpressionType() != null) { it.newLine(); it.append("return ").append(name); //$NON-NLS-1$ } return varDeclaration; }
Example 3
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** Generate the given object. * * @param block the block expression. * @param it the target for the generated content. * @param context the context. * @return the last expression in the block or {@code null}. */ protected XExpression _generate(XBlockExpression block, IAppendable it, IExtraLanguageGeneratorContext context) { XExpression last = block; if (block.getExpressions().isEmpty()) { it.append("pass"); //$NON-NLS-1$ } else { it.openScope(); if (context.getExpectedExpressionType() == null) { boolean first = true; for (final XExpression expression : block.getExpressions()) { if (first) { first = false; } else { it.newLine(); } last = generate(expression, it, context); } } else { final List<XExpression> exprs = block.getExpressions(); if (!exprs.isEmpty()) { for (int i = 0; i < exprs.size() - 1; ++i) { if (i > 0) { it.newLine(); } last = generate(exprs.get(i), it, context); } last = generate(exprs.get(exprs.size() - 1), context.getExpectedExpressionType(), it, context); } } it.closeScope(); } return last; }
Example 4
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** 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; }