Java Code Examples for org.eclipse.xtext.xbase.compiler.ISourceAppender#append()
The following examples show how to use
org.eclipse.xtext.xbase.compiler.ISourceAppender#append() .
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: ConstructorBuilderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testXtendCustomBody() { AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass()); final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> { it.setContext(this.getXtendClass()); final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> { it_1.append("return"); }; it.setBodyGenerator(_function_1); }; AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("new() {"); _builder.newLine(); _builder.append(" "); _builder.append("return"); _builder.newLine(); _builder.append("}"); this.assertBuilds(_doubleArrow, _builder.toString()); }
Example 2
Source File: SarlParameterBuilder.java From sarl with Apache License 2.0 | 6 votes |
@Override public ISourceAppender build(ISourceAppender appendable) { final ISourceAppender mAppender; if (appendable instanceof SourceAppenderWithTypeMapping) { mAppender = appendable; } else { mAppender = new SourceAppenderWithTypeMapping(appendable, this.keywords); } appendModifiers(mAppender); mAppender.append(this.keywords.protectKeyword(getName())).append(" "); //$NON-NLS-1$ mAppender.append(this.keywords.getColonKeyword()).append(" "); //$NON-NLS-1$ if (isVarArgsFlag()) { appendType(mAppender, ((ArrayTypeReference) getType()).getComponentType(), Object.class.getSimpleName()); mAppender.append(this.keywords.getWildcardAsteriskKeyword()); } else { appendType(mAppender, getType(), Object.class.getName()); final String defaultVal = getDefaultValue(); if (!Strings.isEmpty(defaultVal)) { mAppender.append(" ").append(this.keywords.getEqualsSignKeyword()); //$NON-NLS-1$ mAppender.append(" ").append(defaultVal); //$NON-NLS-1$ } } return mAppender; }
Example 3
Source File: SarlConstructorBuilder.java From sarl with Apache License 2.0 | 6 votes |
@Override public ISourceAppender build(ISourceAppender appendable) { final ISourceAppender mAppender; if (appendable instanceof SourceAppenderWithTypeMapping) { mAppender = appendable; } else { mAppender = new SourceAppenderWithTypeMapping(appendable, this.keywords); } final JvmVisibility defaultVisibility = this.visiblityProvider.getDefaultJvmVisibility(getOwner(), XtendPackage.eINSTANCE.getXtendConstructor()); appendVisibility(mAppender, getVisibility(), defaultVisibility); mAppender.append(this.keywords.getNewKeyword()); appendParameters(mAppender); appendThrowsClause(mAppender); appendBody(mAppender, ""); //$NON-NLS-1$ return mAppender; }
Example 4
Source File: SarlFieldBuilder.java From sarl with Apache License 2.0 | 6 votes |
@Override public ISourceAppender build(ISourceAppender appendable) { final ISourceAppender mAppender; if (appendable instanceof SourceAppenderWithTypeMapping) { mAppender = appendable; } else { mAppender = new SourceAppenderWithTypeMapping(appendable, this.keywords); } final JvmVisibility defaultVisibility = this.visiblityProvider.getDefaultJvmVisibility(getOwner(), XtendPackage.eINSTANCE.getXtendField()); appendVisibility(mAppender, getVisibility(), defaultVisibility); if (isStaticFlag()) { mAppender.append(this.keywords.getStaticStaticKeyword()).append(" "); //$NON-NLS-1$ } mAppender.append(this.keywords.protectKeyword(getFieldName())); mAppender.append(" ").append(this.keywords.getColonKeyword()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ appendType(mAppender, getFieldType(), Object.class.getName()); return mAppender; }
Example 5
Source File: MemberFromSuperImplementor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void appendConstructorFromSuper(final XtendClass overrider, final IResolvedConstructor superConstructor, final ISourceAppender appendable) { final JvmGenericType inferredType = this.associations.getInferredType(overrider); final AbstractConstructorBuilder constructorBuilder = this.codeBuilderFactory.createConstructorBuilder(inferredType); this.initializeExecutableBuilder(constructorBuilder, inferredType, superConstructor); final Procedure1<ISourceAppender> _function = (ISourceAppender it) -> { boolean _isEmpty = superConstructor.getResolvedParameterTypes().isEmpty(); boolean _not = (!_isEmpty); if (_not) { StringConcatenation _builder = new StringConcatenation(); _builder.append("super("); final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it_1) -> { return it_1.getSimpleName(); }; String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(superConstructor.getDeclaration().getParameters(), _function_1), ", "); _builder.append(_join); _builder.append(")"); it.append(_builder); } }; constructorBuilder.setBodyGenerator(_function); boolean _isValid = constructorBuilder.isValid(); if (_isValid) { constructorBuilder.build(appendable); } }
Example 6
Source File: AbstractExecutableBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected ISourceAppender appendThrowsClause(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { final Iterator<LightweightTypeReference> iterator = this.exceptions.iterator(); boolean _hasNext = iterator.hasNext(); if (_hasNext) { appendable.append(" throws "); do { { final LightweightTypeReference typeRef = iterator.next(); if ((typeRef != null)) { this.appendType(appendable, typeRef, "Exception"); } boolean _hasNext_1 = iterator.hasNext(); if (_hasNext_1) { appendable.append(", "); } } } while(iterator.hasNext()); } _xblockexpression = appendable; } return _xblockexpression; }
Example 7
Source File: MethodBuilderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testXtendCustomBody() { AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass()); final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> { it.setContext(this.getXtendClass()); it.setMethodName("foo"); final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> { it_1.append("return"); }; it.setBodyGenerator(_function_1); }; AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("def foo() {"); _builder.newLine(); _builder.append(" "); _builder.append("return"); _builder.newLine(); _builder.append("}"); this.assertBuilds(_doubleArrow, _builder.toString()); }
Example 8
Source File: SarlMethodBuilder.java From sarl with Apache License 2.0 | 6 votes |
/** Append the "fires" clause. * * @param appendable the receiver. * @return the appendable. */ protected ISourceAppender appendFiresClause(ISourceAppender appendable) { final List<LightweightTypeReference> types = getFires(); final Iterator<LightweightTypeReference> iterator = types.iterator(); if (iterator.hasNext()) { appendable.append(" ").append(this.keywords.getFiresKeyword()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ do { final LightweightTypeReference type = iterator.next(); appendable.append(type); if (iterator.hasNext()) { appendable.append(this.keywords.getCommaKeyword()).append(" "); //$NON-NLS-1$ } } while (iterator.hasNext()); } return appendable; }
Example 9
Source File: SarlMethodBuilder.java From sarl with Apache License 2.0 | 5 votes |
@Override protected ISourceAppender appendTypeParameters(ISourceAppender appendable, List<JvmTypeParameter> typeParameters) { final Iterator<JvmTypeParameter> iterator = typeParameters.iterator(); if (iterator.hasNext()) { appendable.append(" ").append(this.keywords.getWithKeyword()).append(" "); //$NON-NLS-1$//$NON-NLS-2$ final String objectId = Object.class.getName(); do { final JvmTypeParameter typeParameter = iterator.next(); appendable.append(this.keywords.protectKeyword(typeParameter.getName())); final Iterable<JvmUpperBound> upperBounds = Iterables.filter(Iterables.filter(typeParameter.getConstraints(), JvmUpperBound.class), it -> !it.getTypeReference().getIdentifier().equals(objectId)); final Iterator<JvmUpperBound> iterator2 = upperBounds.iterator(); if (iterator2.hasNext()) { appendable.append(" ").append(this.keywords.getExtendsKeyword()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ boolean isFirst = true; final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, getContext()); for (final JvmUpperBound upperBound: upperBounds) { if (!isFirst) { appendable.append(" ").append(this.keywords.getAmpersandKeyword()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ } isFirst = false; appendType(appendable, owner.toLightweightTypeReference(upperBound.getTypeReference()), Object.class.getSimpleName()); } } if (iterator.hasNext()) { appendable.append(this.keywords.getCommaKeyword()).append(" "); //$NON-NLS-1$ } } while (iterator.hasNext()); } return appendable; }
Example 10
Source File: AbstractExecutableBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public ISourceAppender appendBody(final ISourceAppender appendable, final String statementSeparator) { ISourceAppender _xblockexpression = null; { appendable.append(" {").increaseIndentation().newLine(); if ((this.bodyGenerator != null)) { this.bodyGenerator.apply(appendable); } else { appendable.append(this.defaultBody()); } _xblockexpression = appendable.append(statementSeparator).decreaseIndentation().newLine().append("}"); } return _xblockexpression; }
Example 11
Source File: JavaFieldBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ISourceAppender build(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { this.appendVisibility(appendable, this.getVisibility(), JvmVisibility.DEFAULT); boolean _isStaticFlag = this.isStaticFlag(); if (_isStaticFlag) { appendable.append("static "); } _xblockexpression = this.appendType(appendable, this.getFieldType(), "Object").append(" ").append(this.getFieldName()).append(";"); } return _xblockexpression; }
Example 12
Source File: XtendParameterBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected ISourceAppender appendModifiers(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { boolean _isExtensionFlag = this.isExtensionFlag(); if (_isExtensionFlag) { appendable.append("extension "); } _xblockexpression = appendable; } return _xblockexpression; }
Example 13
Source File: JavaParameterBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected ISourceAppender appendModifiers(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { boolean _isFinalFlag = this.isFinalFlag(); if (_isFinalFlag) { appendable.append("final "); } _xblockexpression = appendable; } return _xblockexpression; }
Example 14
Source File: XtendFieldBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ISourceAppender build(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { this.appendVisibility(appendable, this.getVisibility(), JvmVisibility.PRIVATE); boolean _isStaticFlag = this.isStaticFlag(); if (_isStaticFlag) { appendable.append("static "); } _xblockexpression = this.appendType(appendable, this.getFieldType(), "Object").append(" ").append(this.getFieldName()); } return _xblockexpression; }
Example 15
Source File: SarlMethodBuilder.java From sarl with Apache License 2.0 | 5 votes |
@Override public ISourceAppender build(ISourceAppender appendable) { final ISourceAppender mAppender; if (appendable instanceof SourceAppenderWithTypeMapping) { mAppender = appendable; } else { mAppender = new SourceAppenderWithTypeMapping(appendable, this.keywords); } final JvmVisibility defaultVisibility = this.visiblityProvider.getDefaultJvmVisibility(getOwner(), XtendPackage.eINSTANCE.getXtendFunction()); appendVisibility(mAppender, getVisibility(), defaultVisibility); if (isStaticFlag()) { mAppender.append(this.keywords.getStaticStaticKeyword()).append(" "); //$NON-NLS-1$ } else if (isAbstractFlag()) { mAppender.append(this.keywords.getAbstractKeyword()).append(" "); //$NON-NLS-1$ } if (isOverrideFlag()) { mAppender.append(this.keywords.getOverrideKeyword()); } else { mAppender.append(this.keywords.getDefKeyword()); } mAppender.append(" "); //$NON-NLS-1$ mAppender.append(this.keywords.protectKeyword(getMethodName())); appendParameters(mAppender); final LightweightTypeReference retType = getReturnType(); if (retType != null && !retType.isPrimitiveVoid()) { mAppender.append(" "); //$NON-NLS-1$ mAppender.append(this.keywords.getColonKeyword()); mAppender.append(" "); //$NON-NLS-1$ appendType(mAppender, retType, void.class.getSimpleName()); } appendTypeParameters(mAppender, getTypeParameters()); appendThrowsClause(mAppender); appendFiresClause(mAppender); if (!isAbstractFlag()) { appendBody(mAppender, ""); //$NON-NLS-1$ } return mAppender; }
Example 16
Source File: JavaMethodBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ISourceAppender build(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { boolean _isOverrideFlag = this.isOverrideFlag(); if (_isOverrideFlag) { appendable.append("@Override").newLine(); } this.appendVisibility(appendable, this.getVisibility(), JvmVisibility.DEFAULT); boolean _isAbstractFlag = this.isAbstractFlag(); if (_isAbstractFlag) { appendable.append("abstract "); } boolean _isStaticFlag = this.isStaticFlag(); if (_isStaticFlag) { appendable.append("static "); } boolean _isSynchronizedFlag = this.isSynchronizedFlag(); if (_isSynchronizedFlag) { appendable.append("synchronized "); } this.appendThrowsClause(this.appendParameters(this.appendType(this.appendTypeParameters(appendable, this.getTypeParameters()), this.getReturnType(), "void").append(" ").append(this.getMethodName()))); boolean _isAbstractFlag_1 = this.isAbstractFlag(); if (_isAbstractFlag_1) { appendable.append(";"); } else { this.appendBody(appendable, ";"); } _xblockexpression = appendable; } return _xblockexpression; }
Example 17
Source File: XtendMethodBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ISourceAppender build(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { String _xifexpression = null; boolean _isOverrideFlag = this.isOverrideFlag(); if (_isOverrideFlag) { _xifexpression = "override "; } else { _xifexpression = "def "; } this.appendVisibility(appendable.append(_xifexpression), this.getVisibility(), JvmVisibility.PUBLIC); boolean _isStaticFlag = this.isStaticFlag(); if (_isStaticFlag) { appendable.append("static "); } boolean _isSynchronizedFlag = this.isSynchronizedFlag(); if (_isSynchronizedFlag) { appendable.append("synchronized "); } this.appendTypeParameters(appendable, this.getTypeParameters()); boolean _isAbstractFlag = this.isAbstractFlag(); if (_isAbstractFlag) { this.appendType(appendable, this.getReturnType(), "void").append(" "); } this.appendThrowsClause(this.appendParameters(appendable.append(this.getMethodName()))); boolean _isAbstractFlag_1 = this.isAbstractFlag(); boolean _not = (!_isAbstractFlag_1); if (_not) { this.appendBody(appendable, ""); } _xblockexpression = appendable; } return _xblockexpression; }
Example 18
Source File: AbstractCodeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected ISourceAppender appendVisibility(final ISourceAppender appendable, final JvmVisibility visibility, final JvmVisibility skippableDefault) { String _switchResult = null; boolean _matched = false; if (Objects.equal(visibility, skippableDefault)) { _matched=true; _switchResult = ""; } if (!_matched) { if (Objects.equal(visibility, JvmVisibility.PRIVATE)) { _matched=true; _switchResult = "private "; } } if (!_matched) { if (Objects.equal(visibility, JvmVisibility.PROTECTED)) { _matched=true; _switchResult = "protected "; } } if (!_matched) { if (Objects.equal(visibility, JvmVisibility.PUBLIC)) { _matched=true; _switchResult = "public "; } } if (!_matched) { _switchResult = ""; } return appendable.append(_switchResult); }
Example 19
Source File: AbstractCodeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected ISourceAppender appendType(final ISourceAppender appendable, final LightweightTypeReference typeRef, final String surrogate) { ISourceAppender _xblockexpression = null; { if ((typeRef == null)) { appendable.append(surrogate); } else { appendable.append(typeRef); } _xblockexpression = appendable; } return _xblockexpression; }
Example 20
Source File: ExtractVariableRefactoring.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void appendDeclaration(ISourceAppender section, ITextRegion expressionRegion) throws BadLocationException { section .append((isFinal) ? "val" : "var") .append(" ") .append(variableName) .append(" = "); String expressionAsString = document.get(expressionRegion.getOffset(), expressionRegion.getLength()); if(expression instanceof XClosure) { XClosure closure = (XClosure) expression; if(expressionAsString.startsWith("[") && expressionAsString.endsWith("]")) { expressionAsString = expressionAsString.substring(1, expressionAsString.length()-1); } section.append("["); boolean isFirst = true; if(!closure.getFormalParameters().isEmpty()) { IResolvedTypes types = typeResolver.resolveTypes(closure); for(JvmFormalParameter parameter: closure.getFormalParameters()) { if(!isFirst) section.append(", "); isFirst = false; LightweightTypeReference parameterType = types.getActualType(parameter); section.append(parameterType); section .append(" ") .append(parameter.getIdentifier()); } } section.append(" | "); if(!closure.getDeclaredFormalParameters().isEmpty()) section.append(expressionAsString.substring(expressionAsString.indexOf("|")+1)); else section.append(expressionAsString); section.append("]"); } else { section.append(expressionAsString); } }