Search in sources :

Example 1 with DefaultFragmentProvider

use of org.eclipse.xtext.resource.DefaultFragmentProvider 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)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 DefaultFragmentProvider (org.eclipse.xtext.resource.DefaultFragmentProvider)1 IFragmentProvider (org.eclipse.xtext.resource.IFragmentProvider)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 Model (org.eclipse.xtext.serializer.syntacticsequencertest.Model)1 SingleCrossReference (org.eclipse.xtext.serializer.syntacticsequencertest.SingleCrossReference)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1 Test (org.junit.Test)1