@Override public ITreeAppendable decreaseIndentation() { this.delegate.decreaseIndentation(); return this; }
/** * Close a block of code. * * @param appendable the receiver of the block closing code. */ protected void closeBlock(ITreeAppendable appendable) { appendable.decreaseIndentation(); appendable.newLine().append("}"); }
@Override public void acceptEndIf() { currentAppendable = null; RichStringIf richStringIf = ifStack.removeLast(); for (int i = 0; i < richStringIf.getElseIfs().size() + 2; i++) { appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}"); } popAppendable(); }
protected void writeElse() { currentAppendable = null; appendable.decreaseIndentation(); appendable.newLine(); appendable.append("} else {"); appendable.increaseIndentation(); }
public ITreeAppendable generateBodyWithIssues(final ITreeAppendable appendable, final Iterable<Issue> errors) { ITreeAppendable _xblockexpression = null; { appendable.append("{").increaseIndentation().newLine().append("throw new Error(\"Unresolved compilation problems:\""); appendable.increaseIndentation(); final Consumer<Issue> _function = (Issue it) -> { appendable.newLine().append("+ \"\\n").append(this.doConvertToJavaString(it.getMessage())).append("\""); }; errors.forEach(_function); _xblockexpression = appendable.append(");").decreaseIndentation().decreaseIndentation().newLine().append("}"); } return _xblockexpression; }
@Override public void acceptEndFor(/* @Nullable */ XExpression after, CharSequence indentation) { currentAppendable = null; super.acceptEndFor(after, indentation); appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}"); RichStringForLoop forLoop = forStack.removeLast(); if (after != null) { String varName = getVarName(forLoop, appendable); appendable.newLine(); appendable.append("if ("); appendable.append(varName); appendable.append(") {"); appendable.increaseIndentation(); writeExpression(after, indentation, false); appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}"); } appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}"); popAppendable(); }
protected void generateCheckedExceptionHandling(ITreeAppendable appendable) { String name = appendable.declareSyntheticVariable(new Object(), "_e"); appendable.decreaseIndentation().newLine().append("} catch (").append(Throwable.class).append(" ").append(name).append(") {").increaseIndentation(); appendable.newLine().append("throw "); appendable.append(Exceptions.class); appendable.append(".sneakyThrow("); appendable.append(name); appendable.append(");"); appendable.decreaseIndentation().newLine().append("}"); }
protected ITreeAppendable appendCloseIfStatement(XCasePart casePart, ITreeAppendable caseAppendable, XSwitchExpressionCompilationState state) { // close surrounding if statements if (state.caseNeedsIfNotMatchedCheck()) { if (casePart.getCase() != null) { caseAppendable.decreaseIndentation().newLine().append("}"); } if (casePart.getTypeGuard() != null) { caseAppendable.decreaseIndentation().newLine().append("}"); caseAppendable.closeScope(); } } else if (casePart.getCase() != null && casePart.getTypeGuard() != null) { caseAppendable.decreaseIndentation().newLine().append("}"); caseAppendable.closeScope(); } else if (casePart.getTypeGuard() != null) { caseAppendable.closeScope(); } state.finishProcessingCase(); return caseAppendable; }
private static void appendSafeFileExistenceTest(ITreeAppendable receiver, File fileInResource) { receiver.newLine(); receiver.append("{"); //$NON-NLS-1$ receiver.increaseIndentation().newLine(); receiver.append(File.class).append(" file = new ").append(File.class); //$NON-NLS-1$ receiver.append("(\"").append(Strings.convertToJavaString(fileInResource.toString())).append("\");"); //$NON-NLS-1$ //$NON-NLS-2$ receiver.newLine(); receiver.append("if (file.exists()) {"); //$NON-NLS-1$ receiver.increaseIndentation().newLine(); receiver.append("return;"); //$NON-NLS-1$ receiver.decreaseIndentation().newLine(); receiver.append("}"); //$NON-NLS-1$ receiver.decreaseIndentation().newLine(); receiver.append("}"); //$NON-NLS-1$ }
writeExpression(before, indentation, false); appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}"); appendable.increaseIndentation(); writeExpression(separator, indentation, true); appendable.decreaseIndentation(); appendable.newLine(); appendable.append("}");
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.append("{").increaseIndentation(); final Procedure1<LoopParams> _function = (LoopParams it_1) -> { final Function1<ITreeAppendable, ITreeAppendable> _function_1 = (ITreeAppendable it_2) -> { return it_2.newLine(); }; it_1.setSeparator(_function_1); }; final Procedure1<JvmMember> _function_1 = (JvmMember it_1) -> { final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1); memberAppendable.openScope(); this.generateMember(it_1, memberAppendable, config); memberAppendable.closeScope(); }; this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function, _function_1); _xblockexpression = appendable.decreaseIndentation().newLine().append("}"); } return _xblockexpression; }
b.append(Boolean.toString(binaryOperation.getConcreteSyntaxFeatureName().equals(expressionHelper.getOrOperator()))).append(";"); b.decreaseIndentation().newLine().append("} else {").increaseIndentation(); if (binaryOperation.getImplicitReceiver() != null) { internalToJavaStatement(binaryOperation.getImplicitReceiver(), b, true); toJavaExpression(rightOperand, b); b.append(";"); b.decreaseIndentation().newLine().append("}");
/** * @param isReferenced unused in this context but necessary for dispatch signature */ protected void _toJavaStatement(XForLoopExpression expr, ITreeAppendable b, boolean isReferenced) { internalToJavaStatement(expr.getForExpression(), b, true); b.newLine(); ITreeAppendable loopAppendable = b.trace(expr); loopAppendable.append("for ("); ITreeAppendable parameterAppendable = loopAppendable.trace(expr.getDeclaredParam()); appendForLoopParameter(expr, parameterAppendable); loopAppendable.append(" : "); internalToJavaExpression(expr.getForExpression(), loopAppendable); loopAppendable.append(") {").increaseIndentation(); internalToJavaStatement(expr.getEachExpression(), loopAppendable, false); loopAppendable.decreaseIndentation().newLine().append("}"); }
public void generateAnnotationMethod(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) { appendable.increaseIndentation().newLine(); appendable.openScope(); this.generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config); this.generateModifier(it, tracedAppendable, config); this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable); tracedAppendable.append(" "); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("()"); this.generateDefaultExpression(it, tracedAppendable, config); tracedAppendable.append(";"); appendable.decreaseIndentation(); appendable.closeScope(); }
protected void _toJavaStatement(XTryCatchFinallyExpression expr, ITreeAppendable outerAppendable, boolean isReferenced) { ITreeAppendable b = outerAppendable.trace(expr, false); if (isReferenced && !isPrimitiveVoid(expr)) { declareSyntheticVariable(expr, b); } b.newLine().append("try {").increaseIndentation(); final boolean canBeReferenced = isReferenced && !isPrimitiveVoid(expr.getExpression()); internalToJavaStatement(expr.getExpression(), b, canBeReferenced); if (canBeReferenced) { b.newLine().append(getVarName(expr, b)).append(" = "); internalToConvertedExpression(expr.getExpression(), b, getLightweightType(expr)); b.append(";"); } b.decreaseIndentation().newLine().append("}"); appendCatchAndFinally(expr, b, isReferenced); }
b.append(";"); b.decreaseIndentation().newLine().append("}"); if (expr.getElse() != null) { b.append(" else {").increaseIndentation(); b.append(";"); b.decreaseIndentation().newLine().append("}");
protected void _toJavaStatement(final XSynchronizedExpression synchronizedExpression, final ITreeAppendable b, boolean isReferenced) { if (isReferenced) { declareSyntheticVariable(synchronizedExpression, b); } ITreeAppendable synchronizedAppendable = b.trace(synchronizedExpression, true); XExpression param = synchronizedExpression.getParam(); if (!canCompileToJavaExpression(param, b)) internalToJavaStatement(param, synchronizedAppendable, isReferenced); synchronizedAppendable.newLine().append("synchronized ("); internalToJavaExpression(param, synchronizedAppendable); synchronizedAppendable.append(") {").increaseIndentation(); synchronizedAppendable.openPseudoScope(); XExpression expression = synchronizedExpression.getExpression(); internalToJavaStatement(expression, b, isReferenced); if (isReferenced) { b.newLine().append(getVarName(synchronizedExpression, synchronizedAppendable)).append(" = "); internalToConvertedExpression(expression, b, getLightweightType(synchronizedExpression)); b.append(";"); } synchronizedAppendable.closeScope(); synchronizedAppendable.decreaseIndentation().newLine().append("}"); }
private void wrapWithAssertionErrorHandler(final ITreeAppendable output, final Iterable<TestStepContext> contexts, final Procedure1<ITreeAppendable> strategy) { final Procedure1<ITreeAppendable> _function = (ITreeAppendable it) -> { strategy.apply(output); output.decreaseIndentation(); output.newLine(); StringConcatenation _builder = new StringConcatenation(); _builder.append("} catch (AssertionError e) {"); _builder.newLine(); _builder.append(" "); String _reporterFieldName = this.reporterFieldName(); _builder.append(_reporterFieldName, " "); _builder.append(".assertionExit(e);"); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append("finishedTestWith("); ITreeAppendable _appendTestRunReporterType = this.appendTestRunReporterType(output.append(_builder)); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append(".Status.ERROR);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("org.junit.Assert.fail(e.getMessage());"); _appendTestRunReporterType.append(_builder_1); output.increaseIndentation(); }; this.wrapWithExceptionHandler(output, contexts, _function); }
/** * @param isReferenced unused in this context but necessary for dispatch signature */ protected void _toJavaStatement(XDoWhileExpression expr, ITreeAppendable b, boolean isReferenced) { boolean needsStatement = !canCompileToJavaExpression(expr.getPredicate(), b); String variable = null; if (needsStatement) { variable = b.declareSyntheticVariable(expr, "_dowhile"); b.newLine().append("boolean ").append(variable).append(" = false;"); } b.newLine().append("do {").increaseIndentation(); internalToJavaStatement(expr.getBody(), b, false); if (needsStatement && !isEarlyExit(expr.getBody())) { internalToJavaStatement(expr.getPredicate(), b, true); b.newLine(); b.append(variable).append(" = "); internalToJavaExpression(expr.getPredicate(), b); b.append(";"); } b.decreaseIndentation().newLine().append("} while("); if (needsStatement) { b.append(variable); } else { internalToJavaExpression(expr.getPredicate(), b); } b.append(");"); }