Search in sources :

Example 76 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class PartialSerializationTestLanguageReferenceUpdater method update.

@Override
public void update(final IReferenceUpdaterContext context) {
    super.update(context);
    final Node node = IterableExtensions.<Node>head(Iterables.<Node>filter(context.getResource().getContents(), Node.class));
    if ((node == null)) {
        return;
    }
    final HashSet<Import> toDelete = CollectionLiterals.<Import>newHashSet();
    final HashSet<QualifiedName> toAdd = CollectionLiterals.<QualifiedName>newHashSet();
    final HashMap<Import, QualifiedName> toChange = CollectionLiterals.<Import, QualifiedName>newHashMap();
    final Function1<Import, QualifiedName> _function = (Import it) -> {
        return this.converter.toQualifiedName(it.getImportedNamespace());
    };
    final Map<QualifiedName, Import> imports = IterableExtensions.<QualifiedName, Import>toMap(node.getImports(), _function);
    List<IUpdatableReference> _updatableReferences = context.getUpdatableReferences();
    for (final IUpdatableReference target : _updatableReferences) {
        {
            final EObjectDescriptionDeltaProvider.Delta delta = this.findContainingDelta(context.getEObjectDescriptionDeltas(), target.getTargetEObject());
            if ((delta != null)) {
                final QualifiedName original = IterableExtensions.<IEObjectDescription>head(delta.getSnapshot().getDescriptions()).getQualifiedName();
                final QualifiedName modified = IterableExtensions.<IEObjectDescription>head(delta.getDescriptions()).getQualifiedName();
                boolean _notEquals = (!Objects.equal(original, modified));
                if (_notEquals) {
                    final Import imp = imports.get(original);
                    if ((imp != null)) {
                        toChange.put(imp, modified);
                    }
                }
            }
        }
    }
    final Runnable _function_1 = () -> {
        for (final Import toDel : toDelete) {
            EcoreUtil.remove(toDel);
        }
        Set<Map.Entry<Import, QualifiedName>> _entrySet = toChange.entrySet();
        for (final Map.Entry<Import, QualifiedName> toCh : _entrySet) {
            {
                final Import imp = toCh.getKey();
                final QualifiedName name = toCh.getValue();
                imp.setImportedNamespace(this.converter.toString(name));
            }
        }
        for (final QualifiedName toA : toAdd) {
            EList<Import> _imports = node.getImports();
            Import _createImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport();
            final Procedure1<Import> _function_2 = (Import it) -> {
                it.setImportedNamespace(this.converter.toString(toA));
            };
            Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_2);
            _imports.add(_doubleArrow);
        }
    };
    context.modifyModel(_function_1);
}
Also used : Import(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class DefaultReferenceDescriptionTest method createResourceDescription.

protected IResourceDescription createResourceDescription(Resource testResource) {
    DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj);
            return (name != null) ? QualifiedName.create(name) : null;
        }
    });
    strategy.setLazyURIEncoder(new LazyURIEncoder());
    IResourceDescription resourceDescription = new DefaultResourceDescription(testResource, strategy);
    return resourceDescription;
}
Also used : IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) LazyURIEncoder(org.eclipse.xtext.linking.lazy.LazyURIEncoder)

Example 78 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class DefaultResourceDescription2Test method testValidExternalLink.

@Test
public void testValidExternalLink() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
    res1.load(new StringInputStream("type Foo"), null);
    XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
    res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Bar extends Foo"), null);
    EcoreUtil.resolveAll(res2);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertEquals(QualifiedName.create("foo"), names.iterator().next());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 79 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class DefaultResourceDescription2Test method testValidLocalLink.

@Test
public void testValidLocalLink() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
    res1.load(new StringInputStream("type Foo"), null);
    XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
    res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Foo type Bar extends Foo"), null);
    EcoreUtil.resolveAll(res2);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertFalse(names.iterator().hasNext());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 80 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class DefaultResourceDescription2Test method testNotYetLinked.

@Test
public void testNotYetLinked() throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
    res1.load(new StringInputStream("type Foo"), null);
    XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
    res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Bar extends Foo"), null);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertTrue(names.iterator().hasNext());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)97 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)32 Test (org.junit.Test)31 EObject (org.eclipse.emf.ecore.EObject)27 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)16 EClass (org.eclipse.emf.ecore.EClass)12 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 IScope (org.eclipse.xtext.scoping.IScope)10 Set (java.util.Set)9 URI (org.eclipse.emf.common.util.URI)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 JvmType (org.eclipse.xtext.common.types.JvmType)6 Function (com.google.common.base.Function)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4