Search in sources :

Example 36 with Procedure1

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

Example 37 with Procedure1

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

Example 38 with Procedure1

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

Example 39 with Procedure1

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());
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 40 with Procedure1

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());
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Aggregations

Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)188 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)101 Test (org.junit.Test)100 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)32 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 EList (org.eclipse.emf.common.util.EList)18 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)18 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)16 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)16 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)15 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)14 EObject (org.eclipse.emf.ecore.EObject)13 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)11 Method (java.lang.reflect.Method)10 Resource (org.eclipse.emf.ecore.resource.Resource)10 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10