use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class ConstructorBuilderTest method testJavaCustomBody.
@Test
public void testJavaCustomBody() {
AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
it.setContext(this.getJavaClass());
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("Bar() {");
_builder.newLine();
_builder.append(" ");
_builder.append("return;");
_builder.newLine();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class MethodBuilderTest method testXtendCustomBody.
@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());
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class MethodBuilderTest method testJavaCustomBody.
@Test
public void testJavaCustomBody() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getJavaClass());
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("void foo() {");
_builder.newLine();
_builder.append(" ");
_builder.append("return;");
_builder.newLine();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendOverrideFunction.
public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
methodBuilder.setOverrideFlag(true);
methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
if (_isSynchronized) {
methodBuilder.setSynchronizedFlag(true);
}
boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
newTypeParam.setName(typeParam.getName());
final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
upperBound.setTypeReference(it.toJavaCompliantTypeReference());
EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
_constraints.add(upperBound);
};
overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
typeParameters.add(newTypeParam);
};
IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
methodBuilder.setTypeParameters(typeParameters);
}
boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
boolean _not_1 = (!_isAbstract);
if (_not_1) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("super.");
{
List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
boolean _hasElements = false;
for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
if (!_hasElements) {
_hasElements = true;
_builder.append("<");
} else {
_builder.appendImmediate(", ", "");
}
String _simpleName = typeParam.getSimpleName();
_builder.append(_simpleName);
}
if (_hasElements) {
_builder.append(">");
}
}
String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
_builder.append(_simpleName_1);
_builder.append("(");
final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
return it.getSimpleName();
};
String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
_builder.append(_join);
_builder.append(")");
final String body = _builder.toString();
final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
if (superTypeRef != null) {
superTypeRef.apply(it);
}
it.append(body);
};
methodBuilder.setBodyGenerator(_function_2);
}
boolean _isValid = methodBuilder.isValid();
if (_isValid) {
methodBuilder.build(appendable);
}
}
use of org.eclipse.xtext.xbase.compiler.ISourceAppender in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendConstructorFromSuper.
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);
}
}
Aggregations