use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class AbstractCodeBuilder method appendTypeParameters.
protected ISourceAppender appendTypeParameters(final ISourceAppender appendable, final List<JvmTypeParameter> typeParameters) {
ISourceAppender _xblockexpression = null;
{
final Iterator<JvmTypeParameter> iterator = typeParameters.iterator();
boolean _hasNext = iterator.hasNext();
if (_hasNext) {
appendable.append("<");
do {
{
final JvmTypeParameter typeParameter = iterator.next();
appendable.append(typeParameter.getName());
final Function1<JvmUpperBound, Boolean> _function = (JvmUpperBound it) -> {
String _identifier = it.getTypeReference().getIdentifier();
return Boolean.valueOf((!Objects.equal(_identifier, "java.lang.Object")));
};
final Iterable<JvmUpperBound> upperBounds = IterableExtensions.<JvmUpperBound>filter(Iterables.<JvmUpperBound>filter(typeParameter.getConstraints(), JvmUpperBound.class), _function);
boolean _isEmpty = IterableExtensions.isEmpty(upperBounds);
boolean _not = (!_isEmpty);
if (_not) {
appendable.append(" extends ");
boolean isFirst = true;
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, this.context);
for (final JvmUpperBound upperBound : upperBounds) {
{
if ((!isFirst)) {
appendable.append(" & ");
}
isFirst = false;
this.appendType(appendable, owner.toLightweightTypeReference(upperBound.getTypeReference()), "Object");
}
}
}
boolean _hasNext_1 = iterator.hasNext();
if (_hasNext_1) {
appendable.append(",");
}
}
} while (iterator.hasNext());
appendable.append("> ");
}
_xblockexpression = appendable;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class AbstractExecutableBuilder method appendThrowsClause.
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;
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class AbstractExecutableBuilder method appendParameters.
protected ISourceAppender appendParameters(final ISourceAppender appendable) {
ISourceAppender _xblockexpression = null;
{
appendable.append("(");
final HashSet<String> notAllowed = CollectionLiterals.<String>newHashSet();
boolean _isEmpty = this.parameterBuilders.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
AbstractParameterBuilder _last = IterableExtensions.<AbstractParameterBuilder>last(this.parameterBuilders);
_last.setVarArgsFlag(this.varArgsFlag);
}
int _size = this.parameterBuilders.size();
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
for (final Integer i : _doubleDotLessThan) {
{
final AbstractParameterBuilder parameterBuilder = this.parameterBuilders.get((i).intValue());
final VariableNameAcceptor acceptor = new VariableNameAcceptor(notAllowed);
String _name = parameterBuilder.getName();
boolean _tripleEquals = (_name == null);
if (_tripleEquals) {
this._jdtVariableCompletions.getVariableProposals(parameterBuilder.getType().getIdentifier(), this.getContext(), JdtVariableCompletions.VariableType.PARAMETER, notAllowed, acceptor);
parameterBuilder.setName(acceptor.getVariableName());
}
parameterBuilder.build(appendable);
int _size_1 = this.parameterBuilders.size();
int _minus = (_size_1 - 1);
boolean _notEquals = ((i).intValue() != _minus);
if (_notEquals) {
appendable.append(", ");
}
}
}
_xblockexpression = appendable.append(")");
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method getImplementedInterface.
private Procedure1<? super ISourceAppender> getImplementedInterface(final JvmDeclaredType subType, final JvmDeclaredType superInterface) {
if (((superInterface instanceof JvmGenericType) && ((JvmGenericType) superInterface).isInterface())) {
final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> {
JvmType _type = it.getType();
return Boolean.valueOf(Objects.equal(_type, superInterface));
};
boolean _exists = IterableExtensions.<JvmTypeReference>exists(subType.getSuperTypes(), _function);
if (_exists) {
final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it) -> {
it.append(superInterface).append(".");
};
return _function_1;
}
final Function1<JvmTypeReference, Boolean> _function_2 = (JvmTypeReference it) -> {
return Boolean.valueOf(this.isInterface(it.getType()));
};
final Function1<JvmTypeReference, JvmDeclaredType> _function_3 = (JvmTypeReference it) -> {
JvmType _type = it.getType();
return ((JvmDeclaredType) _type);
};
final Function1<JvmDeclaredType, Boolean> _function_4 = (JvmDeclaredType it) -> {
Procedure1<? super ISourceAppender> _implementedInterface = this.getImplementedInterface(it, superInterface);
return Boolean.valueOf((_implementedInterface != null));
};
final JvmDeclaredType interfaze = IterableExtensions.<JvmDeclaredType>findFirst(IterableExtensions.<JvmTypeReference, JvmDeclaredType>map(IterableExtensions.<JvmTypeReference>filter(subType.getSuperTypes(), _function_2), _function_3), _function_4);
if ((interfaze != null)) {
final Procedure1<ISourceAppender> _function_5 = (ISourceAppender it) -> {
it.append(interfaze).append(".");
};
return _function_5;
}
}
return null;
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class ConstructorBuilderTest method testXtendCustomBody.
@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());
}
Aggregations