Search in sources :

Example 31 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class _TESTDATA_InternalClassProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    String _qualifiedName = annotatedClass.getQualifiedName();
    String _plus = (_qualifiedName + ".InternalClass");
    MutableClassDeclaration _findClass = context.findClass(_plus);
    final Procedure1<MutableClassDeclaration> _function = (MutableClassDeclaration it) -> {
        final Procedure1<MutableFieldDeclaration> _function_1 = (MutableFieldDeclaration it_1) -> {
            it_1.setType(context.getString());
        };
        it.addField("myField", _function_1);
    };
    ObjectExtensions.<MutableClassDeclaration>operator_doubleArrow(_findClass, _function);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)

Example 32 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendFormatterBugTests method bug462628.

@Test
public void bug462628() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(120));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void format() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("mmmmmmmmmmmmmmmcontainsBlockExprmmmmmmmexprcasesemptymmmmexprmmdefaultmmmmmmmm &&");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("mexprmcasesmexists[multiline] && mexprmmdefaultmmultilineOrInNewLine");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this.tester.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractXtendFormatterTest(org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest) Test(org.junit.Test)

Example 33 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendFormatterBugTests method bug403823_1.

@Test
public void bug403823_1() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(120));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void format(String a, String b, String c) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (a != b) ");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("(");
        _builder.append("�", "\t\t");
        _builder.append("c");
        _builder.append("�", "\t\t");
        _builder.append(")");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append(" else \'\'");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this.tester.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractXtendFormatterTest(org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest) Test(org.junit.Test)

Example 34 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendFormatterBugTests method bug403340_1.

@Test
public void bug403340_1() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(120));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void format(String v1, String v2) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (v1 === v2) ");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("Same");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append(" else ");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("Not the Same");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.append("\'", "\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this.tester.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractXtendFormatterTest(org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest) Test(org.junit.Test)

Example 35 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class AccessorsCompilerTest method testCreateGenericSingleSetter.

@Test
public void testCreateGenericSingleSetter() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import org.eclipse.xtend.lib.annotations.Accessors");
        _builder.newLine();
        _builder.append("class Foo<T extends CharSequence> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("@Accessors T foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
            try {
                Assert.assertTrue(it.getSingleGeneratedCode().contains("setFoo(final T foo)"));
                final Object instance = it.getCompiledClass().newInstance();
                final Method setFoo = it.getCompiledClass().getDeclaredMethod("setFoo", CharSequence.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, "bar");
                Assert.assertEquals("bar", 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)

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