Search in sources :

Example 41 with Function1

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);
    }
}
Also used : CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Method(java.lang.reflect.Method) Test(org.junit.Test) AbstractXtendCompilerTest(org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)

Example 42 with Function1

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);
    }
}
Also used : CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Method(java.lang.reflect.Method) Test(org.junit.Test) AbstractXtendCompilerTest(org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)

Example 43 with Function1

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);
    }
}
Also used : CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Method(java.lang.reflect.Method) Test(org.junit.Test) AbstractXtendCompilerTest(org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)

Example 44 with Function1

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);
    }
}
Also used : CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Method(java.lang.reflect.Method) Test(org.junit.Test) AbstractXtendCompilerTest(org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)

Example 45 with Function1

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);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) AbstractQueuedBuildDataTest(org.eclipse.xtend.ide.tests.builder.AbstractQueuedBuildDataTest) Test(org.junit.Test)

Aggregations

Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)131 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)80 Test (org.junit.Test)54 List (java.util.List)20 ArrayList (java.util.ArrayList)19 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)17 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)17 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)13 Method (java.lang.reflect.Method)12 Set (java.util.Set)10 IMethod (org.eclipse.jdt.core.IMethod)10 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)9 ScreenListItemCell (org.applause.lang.applauseDsl.ScreenListItemCell)8 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)8 ColumnType (com.robotoworks.mechanoid.db.sqliteModel.ColumnType)7 URI (org.eclipse.emf.common.util.URI)7 Resource (org.eclipse.emf.ecore.resource.Resource)7