Search in sources :

Example 46 with QualifiedName

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

the class MultimapBasedScope method isShadowed.

@Override
protected boolean isShadowed(IEObjectDescription fromParent) {
    QualifiedName name = fromParent.getName();
    if (isIgnoreCase()) {
        name = name.toLowerCase();
    }
    boolean result = elements.containsKey(name);
    return result;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 47 with QualifiedName

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

the class ResourceSetGlobalScopeProvider method createScopeWithQualifiedNames.

protected IScope createScopeWithQualifiedNames(final IScope parent, final Resource resource, final Predicate<IEObjectDescription> filter, ResourceSet resourceSet, EClass type, boolean ignoreCase) {
    final Iterable<ISelectable> resourceDescriptions = Iterables.transform(resourceSet.getResources(), new Function<Resource, ISelectable>() {

        @Override
        public ISelectable apply(Resource from) {
            return resourceDecriptionProvider.getResourceDescription(from);
        }
    });
    ISelectable compound = new ISelectable() {

        @Override
        public boolean isEmpty() {
            for (ISelectable description : resourceDescriptions) {
                if (!description.isEmpty())
                    return false;
            }
            return true;
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjectsByType(type);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjectsByObject(object);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName name, final boolean ignoreCase) {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjects(type, name, ignoreCase);
                }
            }));
        }

        @Override
        public Iterable<IEObjectDescription> getExportedObjects() {
            return Iterables.concat(Iterables.transform(resourceDescriptions, new Function<ISelectable, Iterable<IEObjectDescription>>() {

                @Override
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    return from.getExportedObjects();
                }
            }));
        }
    };
    return SelectableBasedScope.createScope(parent, compound, filter, type, ignoreCase);
}
Also used : Function(com.google.common.base.Function) EClass(org.eclipse.emf.ecore.EClass) ISelectable(org.eclipse.xtext.resource.ISelectable) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 48 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName 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 49 with QualifiedName

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

the class DefaultResourceDescription2Test 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;
        }
    });
    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) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 50 with QualifiedName

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

the class DefaultResourceDescription2Test method testBrokenLink.

@Test
public void testBrokenLink() 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 Baz"), null);
    EcoreUtil.resolveAll(res2);
    Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
    assertEquals(QualifiedName.create("baz"), 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)

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