Search in sources :

Example 61 with Procedure1

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

the class TokenSerializerTest method testConstructedCrossReferenceWithProxy.

@Test
public void testConstructedCrossReferenceWithProxy() {
    final XtextResourceSet resourceSet = this.resourceSetProvider.get();
    Resource _createResource = resourceSet.createResource(this.getFileURI("dummy"));
    final XtextResource resource = ((XtextResource) _createResource);
    Model _createModel = this.factory.createModel();
    final Procedure1<Model> _function = (Model it) -> {
        SingleCrossReference _createSingleCrossReference = this.factory.createSingleCrossReference();
        final Procedure1<SingleCrossReference> _function_1 = (SingleCrossReference it_1) -> {
            it_1.setName("myref");
        };
        SingleCrossReference _doubleArrow = ObjectExtensions.<SingleCrossReference>operator_doubleArrow(_createSingleCrossReference, _function_1);
        it.setX5(_doubleArrow);
    };
    final Model model = ObjectExtensions.<Model>operator_doubleArrow(_createModel, _function);
    EList<EObject> _contents = resource.getContents();
    _contents.add(model);
    SingleCrossReference _x5 = model.getX5();
    SingleCrossReference _createSingleCrossReference = this.factory.createSingleCrossReference();
    final Procedure1<SingleCrossReference> _function_1 = (SingleCrossReference it) -> {
        ((InternalEObject) it).eSetProxyURI(resource.getURI().appendFragment("foo"));
    };
    SingleCrossReference _doubleArrow = ObjectExtensions.<SingleCrossReference>operator_doubleArrow(_createSingleCrossReference, _function_1);
    _x5.setRef3(_doubleArrow);
    resource.setFragmentProvider(new DefaultFragmentProvider() {

        @Override
        public EObject getEObject(final Resource resource, final String fragment, final IFragmentProvider.Fallback fallback) {
            EObject _xifexpression = null;
            boolean _equals = Objects.equal(fragment, "foo");
            if (_equals) {
                _xifexpression = model.getX5();
            } else {
                _xifexpression = super.getEObject(resource, fragment, fallback);
            }
            return _xifexpression;
        }
    });
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#5 myref kw3 myref");
    _builder.newLine();
    this.assertSerializesTo(model, _builder);
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Model(org.eclipse.xtext.serializer.syntacticsequencertest.Model) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) SingleCrossReference(org.eclipse.xtext.serializer.syntacticsequencertest.SingleCrossReference) IFragmentProvider(org.eclipse.xtext.resource.IFragmentProvider) DefaultFragmentProvider(org.eclipse.xtext.resource.DefaultFragmentProvider) Test(org.junit.Test)

Example 62 with Procedure1

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

the class DefaultTaskFinderTest method test.

@Test
public void test() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("//TODO foo");
        _builder.newLine();
        _builder.append("/*");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* FIXME bar");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* Fixme no match");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* FOO also no match");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("/* TODO Get rid of this */");
        _builder.newLine();
        _builder.append("Hello notATODO!");
        _builder.newLine();
        Task _task = new Task();
        final Procedure1<Task> _function = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_1 = (TaskTag it_1) -> {
                it_1.setName("TODO");
                it_1.setPriority(Priority.NORMAL);
            };
            TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_1);
            it.setTag(_doubleArrow);
            it.setDescription(" foo");
            it.setOffset(2);
            it.setLineNumber(1);
        };
        Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
        Task _task_1 = new Task();
        final Procedure1<Task> _function_1 = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_2 = (TaskTag it_1) -> {
                it_1.setName("FIXME");
                it_1.setPriority(Priority.HIGH);
            };
            TaskTag _doubleArrow_1 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_2);
            it.setTag(_doubleArrow_1);
            it.setDescription(" bar");
            it.setOffset(17);
            it.setLineNumber(3);
        };
        Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_1);
        Task _task_2 = new Task();
        final Procedure1<Task> _function_2 = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_3 = (TaskTag it_1) -> {
                it_1.setName("TODO");
                it_1.setPriority(Priority.NORMAL);
            };
            TaskTag _doubleArrow_2 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_3);
            it.setTag(_doubleArrow_2);
            it.setDescription(" Get rid of this ");
            it.setOffset(73);
            it.setLineNumber(7);
        };
        Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_2, _function_2);
        this.assertContainsTasks(this.getResourceFromString(LineDelimiters.toUnix(_builder.toString())), Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1, _doubleArrow_2)));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Task(org.eclipse.xtext.tasks.Task) TaskTag(org.eclipse.xtext.tasks.TaskTag) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 63 with Procedure1

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

the class SerializableResourceDescriptionTest method testSerialization.

@Test
public void testSerialization() {
    try {
        final URI uri = URI.createURI("file:/foo/bar.baz.foo");
        SerializableResourceDescription _serializableResourceDescription = new SerializableResourceDescription();
        final Procedure1<SerializableResourceDescription> _function = (SerializableResourceDescription it) -> {
            it.setURI(uri);
            SerializableReferenceDescription _serializableReferenceDescription = new SerializableReferenceDescription();
            final Procedure1<SerializableReferenceDescription> _function_1 = (SerializableReferenceDescription it_1) -> {
                it_1.setSourceEObjectUri(uri.appendFragment("foo"));
                it_1.setTargetEObjectUri(uri.appendFragment("hubble"));
                it_1.setContainerEObjectURI(uri.appendFragment("baz"));
                it_1.setEReference(EcorePackage.eINSTANCE.getEAnnotation_Contents());
                it_1.setIndexInList(1);
            };
            SerializableReferenceDescription _doubleArrow = ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription, _function_1);
            SerializableReferenceDescription _serializableReferenceDescription_1 = new SerializableReferenceDescription();
            final Procedure1<SerializableReferenceDescription> _function_2 = (SerializableReferenceDescription it_1) -> {
                it_1.setSourceEObjectUri(uri.appendFragment("foo2"));
                it_1.setTargetEObjectUri(uri.appendFragment("hubble2"));
                it_1.setContainerEObjectURI(uri.appendFragment("baz2"));
                it_1.setEReference(EcorePackage.eINSTANCE.getEAnnotation_Contents());
                it_1.setIndexInList(2);
            };
            SerializableReferenceDescription _doubleArrow_1 = ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription_1, _function_2);
            it.setReferences(Collections.<SerializableReferenceDescription>unmodifiableList(CollectionLiterals.<SerializableReferenceDescription>newArrayList(_doubleArrow, _doubleArrow_1)));
            SerializableEObjectDescription _serializableEObjectDescription = new SerializableEObjectDescription();
            final Procedure1<SerializableEObjectDescription> _function_3 = (SerializableEObjectDescription it_1) -> {
                it_1.setEObjectURI(uri.appendFragment("baz"));
                it_1.qualifiedName = QualifiedName.create("foo", "baz");
                it_1.setEClass(EcorePackage.eINSTANCE.getEAttribute());
                Pair<String, String> _mappedTo = Pair.<String, String>of("myKey", "myValue");
                it_1.userData = CollectionLiterals.<String, String>newHashMap(_mappedTo);
            };
            SerializableEObjectDescription _doubleArrow_2 = ObjectExtensions.<SerializableEObjectDescription>operator_doubleArrow(_serializableEObjectDescription, _function_3);
            it.setDescriptions(Collections.<SerializableEObjectDescription>unmodifiableList(CollectionLiterals.<SerializableEObjectDescription>newArrayList(_doubleArrow_2)));
            QualifiedName _create = QualifiedName.create("foo");
            QualifiedName _create_1 = QualifiedName.create("foo", "bar");
            it.setImportedNames(Collections.<QualifiedName>unmodifiableList(CollectionLiterals.<QualifiedName>newArrayList(_create, _create_1)));
        };
        final SerializableResourceDescription before = ObjectExtensions.<SerializableResourceDescription>operator_doubleArrow(_serializableResourceDescription, _function);
        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        final ObjectOutputStream objectOut = new ObjectOutputStream(bout);
        objectOut.writeObject(before);
        byte[] _byteArray = bout.toByteArray();
        ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
        final ObjectInputStream in = new ObjectInputStream(_byteArrayInputStream);
        Object _readObject = in.readObject();
        final SerializableResourceDescription after = ((SerializableResourceDescription) _readObject);
        this.assertDescriptionsEqual(before, after);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) URI(org.eclipse.emf.common.util.URI) SerializableEObjectDescription(org.eclipse.xtext.resource.persistence.SerializableEObjectDescription) ByteArrayInputStream(java.io.ByteArrayInputStream) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) SerializableResourceDescription(org.eclipse.xtext.resource.persistence.SerializableResourceDescription) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 64 with Procedure1

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

the class CommentFormatterTest method MLSL_inline.

@Test
public void MLSL_inline() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  /*x*/  a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
            }
        };
        it.setFormatter(_function_1);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist /*x*/ a");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 65 with Procedure1

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

the class CommentFormatterTest method MLSL_paragraph.

@Test
public void MLSL_paragraph() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist");
        _builder.newLine();
        _builder.newLine();
        _builder.newLine();
        _builder.append("/*x*/");
        _builder.newLine();
        _builder.newLine();
        _builder.newLine();
        _builder.append("a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
            }
        };
        it.setFormatter(_function_1);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist /*x*/");
        _builder_1.newLine();
        _builder_1.append("a");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Aggregations

Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)173 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)99 Test (org.junit.Test)98 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)28 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 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 EList (org.eclipse.emf.common.util.EList)14 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)14 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)14 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 EObject (org.eclipse.emf.ecore.EObject)11 Method (java.lang.reflect.Method)10 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)10 Field (java.lang.reflect.Field)9