use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class AccessorsCompilerTest method testCreateSingleSetter.
@Test
public void testCreateSingleSetter() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.lib.annotations.Accessors");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("@Accessors int foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
try {
final Object instance = it.getCompiledClass().newInstance();
final Method setFoo = it.getCompiledClass().getDeclaredMethod("setFoo", int.class);
Field _declaredField = it.getCompiledClass().getDeclaredField("foo");
final Procedure1<Field> _function_1 = (Field it_1) -> {
it_1.setAccessible(true);
};
final Field fooField = ObjectExtensions.<Field>operator_doubleArrow(_declaredField, _function_1);
setFoo.invoke(instance, Integer.valueOf(1));
Assert.assertEquals(Integer.valueOf(1), fooField.get(instance));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
this.compilationTestHelper.compile(_builder, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class NewDataCompilerTest method testExistingMethodsNotMatchingExactly.
@Test
public void testExistingMethodsNotMatchingExactly() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.lib.annotations.Data");
_builder.newLine();
_builder.append("@Data class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("int foo");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def getFoo(String bar) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("1");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def toString(String bar) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\"1\"");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def hashCode(String bar) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("1");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def equals(String bar) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("true");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def equals(Object foo, String bar) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("true");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
Class<?> _compiledClass = it.getCompiledClass();
final Procedure1<Class<?>> _function_1 = (Class<?> it_1) -> {
try {
it_1.getDeclaredConstructor(int.class);
it_1.getDeclaredMethod("equals", Object.class);
it_1.getDeclaredMethod("hashCode");
it_1.getDeclaredMethod("toString");
it_1.getDeclaredMethod("getFoo");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
ObjectExtensions.<Class<?>>operator_doubleArrow(_compiledClass, _function_1);
};
this.compilationTestHelper.compile(_builder, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class OldDataCompilerTest method testBooleanProperties.
@Test
public void testBooleanProperties() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@Data class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("boolean foo");
_builder.newLine();
_builder.append("\t");
_builder.append("Boolean bar");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
Class<?> _compiledClass = it.getCompiledClass();
final Procedure1<Class<?>> _function_1 = (Class<?> it_1) -> {
final Function1<Field, Boolean> _function_2 = (Field it_2) -> {
String _name = it_2.getName();
return Boolean.valueOf(Objects.equal(_name, "_foo"));
};
Assert.assertTrue(IterableExtensions.<Field>exists(((Iterable<Field>) Conversions.doWrapArray(it_1.getDeclaredFields())), _function_2));
final Function1<Field, Boolean> _function_3 = (Field it_2) -> {
String _name = it_2.getName();
return Boolean.valueOf(Objects.equal(_name, "_bar"));
};
Assert.assertTrue(IterableExtensions.<Field>exists(((Iterable<Field>) Conversions.doWrapArray(it_1.getDeclaredFields())), _function_3));
final Function1<Method, Boolean> _function_4 = (Method it_2) -> {
String _name = it_2.getName();
return Boolean.valueOf(Objects.equal(_name, "isFoo"));
};
Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it_1.getDeclaredMethods())), _function_4));
final Function1<Method, Boolean> _function_5 = (Method it_2) -> {
String _name = it_2.getName();
return Boolean.valueOf(Objects.equal(_name, "getBar"));
};
Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it_1.getDeclaredMethods())), _function_5));
};
ObjectExtensions.<Class<?>>operator_doubleArrow(_compiledClass, _function_1);
};
this.compilationTestHelper.compile(_builder, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 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.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.
the class ConstructorBuilderTest method testJavaParameterNames.
@Test
public void testJavaParameterNames() {
AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
it.setContext(this.getJavaClass());
it.setVisibility(JvmVisibility.PRIVATE);
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("private Bar(Foo bar, Bar foo) {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
Aggregations