Java Code Examples for org.eclipse.xtext.xbase.compiler.output.ITreeAppendable#newLine()
The following examples show how to use
org.eclipse.xtext.xbase.compiler.output.ITreeAppendable#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: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ITreeAppendable _generateMember(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.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.generateTypeParameterDeclaration(it, tracedAppendable, config); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("("); this.generateParameters(it, tracedAppendable, config); tracedAppendable.append(")"); this.generateThrowsClause(it, tracedAppendable, config); tracedAppendable.append(" "); this.generateExecutableBody(it, tracedAppendable, config); appendable.closeScope(); _xblockexpression = appendable; } return _xblockexpression; }
Example 2
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * @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(");"); }
Example 3
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ITreeAppendable _generateMember(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); 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.getType(), "Object", tracedAppendable); tracedAppendable.append(" "); final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName())); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name); this.generateInitialization(it, tracedAppendable, config); _xblockexpression = tracedAppendable.append(";"); } return _xblockexpression; }
Example 4
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); appendable.openScope(); this.assignThisAndSuper(appendable, it, config); ITreeAppendable _xtrycatchfinallyexpression = null; try { _xtrycatchfinallyexpression = this.generateBody(it, appendable, config); } finally { appendable.closeScope(); } _xblockexpression = _xtrycatchfinallyexpression; } return _xblockexpression; }
Example 5
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void appendOperationVisibility(final ITreeAppendable b, JvmOperation operation) { b.newLine(); JvmDeclaredType declaringType = operation.getDeclaringType(); GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA6) || declaringType instanceof JvmGenericType && !((JvmGenericType) declaringType).isInterface()) { b.append("@").append(Override.class).newLine(); } switch(operation.getVisibility()) { case DEFAULT: break; case PUBLIC: b.append("public "); return; case PROTECTED: b.append("protected "); return; case PRIVATE: b.append("private "); return; } }
Example 6
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ITreeAppendable generateDocumentation(final String text, final List<INode> documentationNodes, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); final StringConcatenation doc = ((StringConcatenation) _builder); doc.newLine(); doc.append(" * "); doc.append(text, " * "); doc.newLine(); doc.append(" */"); ITreeAppendable _xifexpression = null; boolean _isEmpty = documentationNodes.isEmpty(); boolean _not = (!_isEmpty); if (_not) { ITreeAppendable _xblockexpression_1 = null; { ITextRegionWithLineInformation documentationTrace = ITextRegionWithLineInformation.EMPTY_REGION; for (final INode node : documentationNodes) { documentationTrace = documentationTrace.merge(node.getTextRegionWithLineInformation()); } LocationData _locationData = new LocationData(documentationTrace, null); appendable.trace(_locationData).append(doc.toString()); _xblockexpression_1 = appendable.newLine(); } _xifexpression = _xblockexpression_1; } else { _xifexpression = appendable.append(doc.toString()).newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example 7
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ITreeAppendable _generateMember(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.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.generateTypeParameterDeclaration(it, tracedAppendable, config); JvmTypeReference _returnType = it.getReturnType(); boolean _tripleEquals = (_returnType == null); if (_tripleEquals) { tracedAppendable.append("void"); } else { this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable); } tracedAppendable.append(" "); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("("); this.generateParameters(it, tracedAppendable, config); tracedAppendable.append(")"); this.generateThrowsClause(it, tracedAppendable, config); if ((it.isAbstract() || (!this.hasBody(it)))) { tracedAppendable.append(";"); } else { tracedAppendable.append(" "); this.generateExecutableBody(it, tracedAppendable, config); } appendable.closeScope(); _xblockexpression = appendable; } return _xblockexpression; }
Example 8
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ITreeAppendable _generateBody(final JvmAnnotationType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateJavaDoc(it, appendable, config); final ITreeAppendable childAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), childAppendable, true, config); this.generateModifier(it, childAppendable, config); childAppendable.append("@interface "); this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); childAppendable.append(" {"); Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(this.getMembersToBeCompiled(it), JvmDeclaredType.class); for (final JvmDeclaredType innerType : _filter) { { final ITreeAppendable innerTypeAppendable = childAppendable.trace(innerType); innerTypeAppendable.increaseIndentation(); this.generateMember(innerType, innerTypeAppendable, config); innerTypeAppendable.decreaseIndentation(); } } Iterable<JvmOperation> _filter_1 = Iterables.<JvmOperation>filter(this.getMembersToBeCompiled(it), JvmOperation.class); for (final JvmOperation operation : _filter_1) { this.generateAnnotationMethod(operation, childAppendable, config); } childAppendable.newLine().append("}"); ITreeAppendable _xifexpression = null; EObject _eContainer = it.eContainer(); boolean _not = (!(_eContainer instanceof JvmType)); if (_not) { _xifexpression = appendable.newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example 9
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateJavaDoc(it, appendable, config); final ITreeAppendable childAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), childAppendable, true, config); this.generateModifier(it, childAppendable, config); boolean _isInterface = it.isInterface(); if (_isInterface) { childAppendable.append("interface "); } else { childAppendable.append("class "); } this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); this.generateTypeParameterDeclaration(it, childAppendable, config); boolean _isEmpty = it.getTypeParameters().isEmpty(); if (_isEmpty) { childAppendable.append(" "); } this.generateExtendsClause(it, childAppendable, config); this.generateMembersInBody(it, childAppendable, config); ITreeAppendable _xifexpression = null; if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) { _xifexpression = appendable.newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example 10
Source File: XtendCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptForLoop(JvmFormalParameter parameter, /* @Nullable */ XExpression expression) { currentAppendable = null; super.acceptForLoop(parameter, expression); if (expression == null) throw new IllegalArgumentException("expression may not be null"); RichStringForLoop forLoop = (RichStringForLoop) expression.eContainer(); forStack.add(forLoop); appendable.newLine(); pushAppendable(forLoop); appendable.append("{").increaseIndentation(); ITreeAppendable debugAppendable = appendable.trace(forLoop, true); internalToJavaStatement(expression, debugAppendable, true); String variableName = null; if (forLoop.getBefore() != null || forLoop.getSeparator() != null || forLoop.getAfter() != null) { variableName = debugAppendable.declareSyntheticVariable(forLoop, "_hasElements"); debugAppendable.newLine(); debugAppendable.append("boolean "); debugAppendable.append(variableName); debugAppendable.append(" = false;"); } debugAppendable.newLine(); debugAppendable.append("for(final "); // TODO tracing if parameter was explicitly declared LightweightTypeReference paramType = getLightweightType(parameter); if (paramType != null) { debugAppendable.append(paramType); } else { debugAppendable.append("Object"); } debugAppendable.append(" "); String loopParam = debugAppendable.declareVariable(parameter, parameter.getName()); debugAppendable.append(loopParam); debugAppendable.append(" : "); internalToJavaExpression(expression, debugAppendable); debugAppendable.append(") {").increaseIndentation(); }
Example 11
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _toJavaStatement(final XFeatureCall expr, final ITreeAppendable b, boolean isReferenced) { // if it's a call to this() or super() make sure the arguments are forced to be compiled to expressions. if (expr.getFeature() instanceof JvmConstructor) { b.newLine(); featureCalltoJavaExpression(expr, b, false); b.append(";"); } else { _toJavaStatement((XAbstractFeatureCall) expr, b, isReferenced); } }
Example 12
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String declareSwitchResultVariable(XSwitchExpression expr, ITreeAppendable b, boolean isReferenced) { LightweightTypeReference type = getTypeForVariableDeclaration(expr); String switchResultName = b.declareSyntheticVariable(getSwitchExpressionKey(expr), "_switchResult"); if (isReferenced) { b.newLine(); b.append(type); b.append(" ").append(switchResultName).append(" = "); b.append(getDefaultValueLiteral(expr)); b.append(";"); } return switchResultName; }
Example 13
Source File: DynamicValidationContext.java From sarl with Apache License 2.0 | 5 votes |
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$ }
Example 14
Source File: XtendCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void appendExtensionAnnotation(EObject context, ITreeAppendable appendable, boolean newLine) { JvmType extension = findKnownTopLevelType(Extension.class, context); if (extension != null) { appendable.append("@"); appendable.append(extension); if (!newLine) appendable.append(" "); else appendable.newLine(); } }
Example 15
Source File: SARLJvmGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** Generate a static constructor from the given Jvm constructor. * * @param it the container of the code. * @param appendable the output. * @param config the generation configuration. * @return the appendable. */ protected ITreeAppendable generateStaticConstructor(JvmOperation it, ITreeAppendable appendable, GeneratorConfig config) { appendable.newLine(); appendable.openScope(); generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); tracedAppendable.append("static "); //$NON-NLS-1$ generateExecutableBody(it, tracedAppendable, config); return appendable; }
Example 16
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * @param isReferenced unused in this context but necessary for dispatch signature */ protected void _toJavaStatement(XWhileExpression expr, ITreeAppendable b, boolean isReferenced) { boolean needsStatement = !canCompileToJavaExpression(expr.getPredicate(), b); String varName = null; if (needsStatement) { internalToJavaStatement(expr.getPredicate(), b, true); varName = b.declareSyntheticVariable(expr, "_while"); b.newLine().append("boolean ").append(varName).append(" = "); internalToJavaExpression(expr.getPredicate(), b); b.append(";"); } b.newLine().append("while ("); if (needsStatement) { b.append(varName); } else { internalToJavaExpression(expr.getPredicate(), b); } b.append(") {").increaseIndentation(); b.openPseudoScope(); internalToJavaStatement(expr.getBody(), b, false); if (needsStatement && !isEarlyExit(expr.getBody())) { internalToJavaStatement(expr.getPredicate(), b, true); b.newLine(); b.append(varName).append(" = "); internalToJavaExpression(expr.getPredicate(), b); b.append(";"); } b.closeScope(); b.decreaseIndentation().newLine().append("}"); }
Example 17
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * @param isReferenced unused in this context but necessary for dispatch signature */ protected void _toJavaStatement(XVariableDeclaration varDeclaration, ITreeAppendable b, boolean isReferenced) { if (varDeclaration.getRight() != null) { internalToJavaStatement(varDeclaration.getRight(), b, true); } b.newLine(); LightweightTypeReference type = appendVariableTypeAndName(varDeclaration, b); b.append(" = "); if (varDeclaration.getRight() != null) { internalToConvertedExpression(varDeclaration.getRight(), b, type); } else { appendDefaultLiteral(b, type); } b.append(";"); }
Example 18
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void appendArgument(XExpression argument, ITreeAppendable b, boolean doLineWrappingIfSourceWasWrapped) { final String referenceName = getReferenceName(argument, b); /* * This is done to support better debugging experience. * Consider the following xbase expression: * * foo( * new String()) * * The compiler could translate that to a single line, but then the two lines in the source would map * to the same line in the Java code, so it's not possible to have two steps. * Therefore we add a newline in the Java if the user had one the expression defined in a new line. */ final boolean needsNewLine = doLineWrappingIfSourceWasWrapped && referenceName == null && isDeclaredInNewLine(argument); if (needsNewLine) { b.increaseIndentation(); b.newLine(); } if (referenceName == null && isVariableDeclarationRequired(argument, b, true)) { if (canCompileToJavaExpression(argument, b)) { internalToJavaExpression(argument, b); } else { LightweightTypeReference type = getLightweightExpectedType(argument); if (type == null) type = getLightweightType(argument); compileAsJavaExpression(argument, b, type); } } else { internalToJavaExpression(argument, b); } if (needsNewLine) { b.decreaseIndentation(); } }
Example 19
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public void generateEnumLiteral(final JvmEnumerationLiteral it, final ITreeAppendable appendable, final GeneratorConfig config) { appendable.newLine(); this.generateJavaDoc(it, appendable, config); this.generateAnnotations(it.getAnnotations(), appendable, true, config); appendable.append(this.makeJavaIdentifier(it.getSimpleName())); }
Example 20
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void toJavaWhileStatement(XBasicForLoopExpression expr, ITreeAppendable b, boolean isReferenced) { ITreeAppendable loopAppendable = b.trace(expr); boolean needBraces = !bracesAreAddedByOuterStructure(expr); if (needBraces) { loopAppendable.newLine().increaseIndentation().append("{"); loopAppendable.openPseudoScope(); } EList<XExpression> initExpressions = expr.getInitExpressions(); for (int i = 0; i < initExpressions.size(); i++) { XExpression initExpression = initExpressions.get(i); if (i < initExpressions.size() - 1) { internalToJavaStatement(initExpression, loopAppendable, false); } else { internalToJavaStatement(initExpression, loopAppendable, isReferenced); if (isReferenced) { loopAppendable.newLine().append(getVarName(expr, loopAppendable)).append(" = ("); internalToConvertedExpression(initExpression, loopAppendable, getLightweightType(expr)); loopAppendable.append(");"); } } } final String varName = loopAppendable.declareSyntheticVariable(expr, "_while"); XExpression expression = expr.getExpression(); if (expression != null) { internalToJavaStatement(expression, loopAppendable, true); loopAppendable.newLine().append("boolean ").append(varName).append(" = "); internalToJavaExpression(expression, loopAppendable); loopAppendable.append(";"); } else { loopAppendable.newLine().append("boolean ").append(varName).append(" = true;"); } loopAppendable.newLine(); loopAppendable.append("while ("); loopAppendable.append(varName); loopAppendable.append(") {").increaseIndentation(); loopAppendable.openPseudoScope(); XExpression eachExpression = expr.getEachExpression(); internalToJavaStatement(eachExpression, loopAppendable, false); EList<XExpression> updateExpressions = expr.getUpdateExpressions(); if (!updateExpressions.isEmpty()) { for (XExpression updateExpression : updateExpressions) { internalToJavaStatement(updateExpression, loopAppendable, false); } } if (!isEarlyExit(eachExpression)) { if (expression != null) { internalToJavaStatement(expression, loopAppendable, true); loopAppendable.newLine().append(varName).append(" = "); internalToJavaExpression(expression, loopAppendable); loopAppendable.append(";"); } else { loopAppendable.newLine().append(varName).append(" = true;"); } } loopAppendable.closeScope(); loopAppendable.decreaseIndentation().newLine().append("}"); if (needBraces) { loopAppendable.closeScope(); loopAppendable.decreaseIndentation().newLine().append("}"); } }