use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class NewDataCompilerTest method testExistingGetter2.
@Test
public void testExistingGetter2() {
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("boolean foo");
_builder.newLine();
_builder.append("\t");
_builder.append("def getFoo() {");
_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) -> {
try {
final Object instance = it.getCompiledClass().getDeclaredConstructor(boolean.class).newInstance(Boolean.valueOf(false));
final Method getFoo = it.getCompiledClass().getDeclaredMethod("getFoo");
Assert.assertEquals(Boolean.valueOf(true), getFoo.invoke(instance));
final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
String _name = it_1.getName();
return Boolean.valueOf(Objects.equal(_name, "isFoo"));
};
Assert.assertFalse(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
} 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.Functions.Function1 in project xtext-xtend by eclipse.
the class DelegateCompilerTest method testMethodWithReturnType.
@Test
public void testMethodWithReturnType() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.lib.annotations.Delegate");
_builder.newLine();
_builder.append("interface A {");
_builder.newLine();
_builder.append("\t");
_builder.append("def int m()");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class B implements A {");
_builder.newLine();
_builder.append("\t");
_builder.append("override m() {1}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class C implements A{");
_builder.newLine();
_builder.append("\t");
_builder.append("@Delegate B delegate");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String text = _builder.toString();
this._validationTestHelper.assertNoIssues(this.file(text));
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
return Boolean.valueOf(((Objects.equal(it_1.getName(), "m") && ((List<Class<?>>) Conversions.doWrapArray(it_1.getParameterTypes())).isEmpty()) && Objects.equal(it_1.getReturnType(), int.class)));
};
Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
};
this.compilationTestHelper.compile(text, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class DelegateCompilerTest method testDelegateField.
@Test
public void testDelegateField() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.lib.annotations.Delegate");
_builder.newLine();
_builder.append("interface A {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m()");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class B implements A {");
_builder.newLine();
_builder.append("\t");
_builder.append("override m() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class C implements A{");
_builder.newLine();
_builder.append("\t");
_builder.append("@Delegate B delegate");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String text = _builder.toString();
this._validationTestHelper.assertNoIssues(this.file(text));
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
return Boolean.valueOf(((Objects.equal(it_1.getName(), "m") && ((List<Class<?>>) Conversions.doWrapArray(it_1.getParameterTypes())).isEmpty()) && Objects.equal(it_1.getReturnType(), void.class)));
};
Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
};
this.compilationTestHelper.compile(text, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class DelegateCompilerTest method testDelegateMethod3.
@Test
public void testDelegateMethod3() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.lib.annotations.Delegate");
_builder.newLine();
_builder.append("interface A {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m(String foo)");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class B implements A {");
_builder.newLine();
_builder.append("\t");
_builder.append("override m(String foo) {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class C implements A{");
_builder.newLine();
_builder.append("\t");
_builder.append("@Delegate def B delegate(String name, Class<?>[] argTypes, Object... args) {null}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String text = _builder.toString();
this._validationTestHelper.assertNoIssues(this.file(text));
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
String _name = it_1.getName();
return Boolean.valueOf(Objects.equal(_name, "m"));
};
Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>) Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
};
this.compilationTestHelper.compile(text, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AbstractSingleEditorQueuedBuildTest method renameNestedTypesWithinDefaultPackage.
@Test
public void renameNestedTypesWithinDefaultPackage() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class Bar {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public class Foo { public class Foo3 {} }");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public static class Foo2 {}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.testHelper.createFile("Bar.java", _builder.toString());
final Procedure0 _function = () -> {
final Function1<ITextEditor, ITextEditor> _function_1 = (ITextEditor it) -> {
ITextEditor _xblockexpression = null;
{
this._javaEditorExtension.changeContent(it, " Foo ", " NewFoo ");
this._javaEditorExtension.changeContent(it, " Foo2 ", " NewFoo2 ");
_xblockexpression = this._javaEditorExtension.changeContent(it, " Foo3 ", " NewFoo3 ");
}
return _xblockexpression;
};
this.save("Bar.java", _function_1);
};
this.assertThereAreDeltas(_function, "Bar", "Bar$Foo", "Bar$Foo2", "Bar$NewFoo", "Bar$NewFoo2", "Bar$NewFoo$NewFoo3", "Bar$Foo$Foo3");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations