Java Code Examples for org.eclipse.xtext.xbase.compiler.IAppendable#decreaseIndentation()
The following examples show how to use
org.eclipse.xtext.xbase.compiler.IAppendable#decreaseIndentation() .
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 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; }
Example 2
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(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; }
Example 3
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; }
Example 4
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** 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; }
Example 5
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** Generate the given object. * * @param ifStatement the if-then-else statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XIfExpression ifStatement, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("if "); //$NON-NLS-1$ generate(ifStatement.getIf(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); if (ifStatement.getThen() != null) { generate(ifStatement.getThen(), context.getExpectedExpressionType(), it, context); } else if (context.getExpectedExpressionType() == null) { it.append("pass"); //$NON-NLS-1$ } else { 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(); } return ifStatement; }