use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class ConstructorBuilderTest method testXtendParameterNames.
@Test
public void testXtendParameterNames() {
AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
it.setContext(this.getXtendClass());
it.setVisibility(JvmVisibility.PROTECTED);
AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
final Procedure1<AbstractParameterBuilder> _function_1 = (AbstractParameterBuilder it_1) -> {
it_1.setType(this.createTypeRef(this.getXtendClass()));
it_1.setName("bar");
};
ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder, _function_1);
AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
final Procedure1<AbstractParameterBuilder> _function_2 = (AbstractParameterBuilder it_1) -> {
it_1.setType(this.createTypeRef(this.getJavaClass()));
it_1.setName("foo");
};
ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder_1, _function_2);
};
AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("protected new(Foo bar, Bar foo) {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 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());
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class MethodBuilderTest method testJavaNamedParameter.
@Test
public void testJavaNamedParameter() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getJavaClass());
it.setMethodName("foo");
AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
final Procedure1<AbstractParameterBuilder> _function_1 = (AbstractParameterBuilder it_1) -> {
it_1.setName("bar");
it_1.setType(this.createTypeRef(this.getXtendClass()));
};
ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder, _function_1);
AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
final Procedure1<AbstractParameterBuilder> _function_2 = (AbstractParameterBuilder it_1) -> {
it_1.setName("baz");
it_1.setType(this.createTypeRef(this.getXtendClass()));
};
ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder_1, _function_2);
};
AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("void foo(Foo bar, Foo baz) {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class MethodBuilderTest method testJavaTypeParameter.
@Test
public void testJavaTypeParameter() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getJavaClass());
it.setMethodName("foo");
JvmTypeParameter _createJvmTypeParameter = this._typesFactory.createJvmTypeParameter();
final Procedure1<JvmTypeParameter> _function_1 = (JvmTypeParameter it_1) -> {
it_1.setName("T");
};
JvmTypeParameter _doubleArrow = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter, _function_1);
JvmTypeParameter _createJvmTypeParameter_1 = this._typesFactory.createJvmTypeParameter();
final Procedure1<JvmTypeParameter> _function_2 = (JvmTypeParameter it_1) -> {
it_1.setName("U");
};
JvmTypeParameter _doubleArrow_1 = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter_1, _function_2);
it.setTypeParameters(Collections.<JvmTypeParameter>unmodifiableList(CollectionLiterals.<JvmTypeParameter>newArrayList(_doubleArrow, _doubleArrow_1)));
};
AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("<T,U> void foo() {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testModifyTypeParameters.
@Test
public void testModifyTypeParameters() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclarator");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(MyAnnotationProcessor)");
_builder.newLine();
_builder.append("annotation MyAnnotation {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class MyAnnotationProcessor implements TransformationParticipant<MutableTypeParameterDeclarator> {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(List<? extends MutableTypeParameterDeclarator> annotatedTargetElements,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("for (annotatedTargetElement : annotatedTargetElements) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("doTransform(annotatedTargetElement, context)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("def doTransform(MutableTypeParameterDeclarator it, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (typeParameters.size != 0) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new IllegalStateException(\"Before: typeParameters.size != 0\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("addTypeParameter(\"T\", String.newTypeReference)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (typeParameters.size != 1) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new IllegalStateException(\"After: typeParameters.size != 1\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val typeParameter = typeParameters.head");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!typeParameter.simpleName.equals(\"T\")) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new IllegalStateException(\"After: expected type name: \'T\', actual type name: \'\" + typeParameter.simpleName + \"\'\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/MyAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.MyAnnotation");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("class MyClass {");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("new() {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("interface MyInterface {");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("abstract def void foo();");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final Procedure1<MutableTypeParameterDeclarator> _function_1 = (MutableTypeParameterDeclarator it_1) -> {
Assert.assertEquals(1, IterableExtensions.size(it_1.getTypeParameters()));
final MutableTypeParameterDeclaration typeParameter = IterableExtensions.head(it_1.getTypeParameters());
Assert.assertEquals("T", typeParameter.getSimpleName());
Assert.assertEquals(1, IterableExtensions.size(typeParameter.getUpperBounds()));
Assert.assertEquals("java.lang.String", IterableExtensions.head(typeParameter.getUpperBounds()).getName());
};
final Procedure1<? super MutableTypeParameterDeclarator> assertMyAnnotationChanges = _function_1;
final MutableClassDeclaration clazz = it.getTypeLookup().findClass("myusercode.MyClass");
assertMyAnnotationChanges.apply(clazz);
assertMyAnnotationChanges.apply(IterableExtensions.head(clazz.getDeclaredConstructors()));
final MutableInterfaceDeclaration myInterface = it.getTypeLookup().findInterface("myusercode.MyInterface");
assertMyAnnotationChanges.apply(myInterface);
assertMyAnnotationChanges.apply(IterableExtensions.head(myInterface.getDeclaredMethods()));
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Aggregations