Search in sources :

Example 1 with ISelectable

use of org.eclipse.xtext.resource.ISelectable in project xtext-core by eclipse.

the class ImportScope method getLocalElementsByName.

@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
    List<IEObjectDescription> result = newArrayList();
    QualifiedName resolvedQualifiedName = null;
    ISelectable importFrom = getImportFrom();
    for (ImportNormalizer normalizer : normalizers) {
        final QualifiedName resolvedName = normalizer.resolve(name);
        if (resolvedName != null) {
            Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(type, resolvedName, isIgnoreCase());
            for (IEObjectDescription resolvedElement : resolvedElements) {
                if (resolvedQualifiedName == null)
                    resolvedQualifiedName = resolvedName;
                else if (!resolvedQualifiedName.equals(resolvedName)) {
                    if (result.get(0).getEObjectOrProxy() != resolvedElement.getEObjectOrProxy()) {
                        return emptyList();
                    }
                }
                QualifiedName alias = normalizer.deresolve(resolvedElement.getName());
                if (alias == null)
                    throw new IllegalStateException("Couldn't deresolve " + resolvedElement.getName() + " with import " + normalizer);
                final AliasedEObjectDescription aliasedEObjectDescription = new AliasedEObjectDescription(alias, resolvedElement);
                result.add(aliasedEObjectDescription);
            }
        }
    }
    return result;
}
Also used : AliasedEObjectDescription(org.eclipse.xtext.resource.impl.AliasedEObjectDescription) ISelectable(org.eclipse.xtext.resource.ISelectable) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with ISelectable

use of org.eclipse.xtext.resource.ISelectable in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProvider method getLocalElementsScope.

protected IScope getLocalElementsScope(IScope parent, final EObject context, final EReference reference) {
    IScope result = parent;
    ISelectable allDescriptions = getAllDescriptions(context.eResource());
    QualifiedName name = getQualifiedNameOfLocalElement(context);
    boolean ignoreCase = isIgnoreCase(reference);
    final List<ImportNormalizer> namespaceResolvers = getImportedNamespaceResolvers(context, ignoreCase);
    if (!namespaceResolvers.isEmpty()) {
        if (isRelativeImport() && name != null && !name.isEmpty()) {
            ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
            result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
        }
        result = createImportScope(result, namespaceResolvers, null, reference.getEReferenceType(), isIgnoreCase(reference));
    }
    if (name != null) {
        ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
        result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
    }
    return result;
}
Also used : ISelectable(org.eclipse.xtext.resource.ISelectable) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope)

Example 3 with ISelectable

use of org.eclipse.xtext.resource.ISelectable 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 4 with ISelectable

use of org.eclipse.xtext.resource.ISelectable in project xtext-core by eclipse.

the class SimpleLocalScopeProvider method getScope.

@Override
public IScope getScope(final EObject context, final EReference reference) {
    ISelectable resourceContent = cache.get(Tuples.pair(SimpleLocalScopeProvider.class.getName(), reference), context.eResource(), new Provider<ISelectable>() {

        @Override
        public ISelectable get() {
            return getAllDescriptions(context.eResource());
        }
    });
    IScope globalScope = getGlobalScope(context.eResource(), reference);
    return createScope(globalScope, resourceContent, reference.getEReferenceType(), isIgnoreCase(reference));
}
Also used : ISelectable(org.eclipse.xtext.resource.ISelectable) IScope(org.eclipse.xtext.scoping.IScope)

Example 5 with ISelectable

use of org.eclipse.xtext.resource.ISelectable in project xtext-core by eclipse.

the class ResourceDescriptionsBasedContainerTest method setUp.

@Before
public void setUp() throws Exception {
    eClass = EcoreFactory.eINSTANCE.createEClass();
    eClass.setName("SomeName");
    uri = URI.createURI("myURI");
    ((InternalEObject) eClass).eSetProxyURI(uri.appendFragment("SomeName"));
    resourceDescription = new ResourceDescription(uri);
    container = createContainer();
    selectableDelegate = new AbstractCompoundSelectable() {

        @Override
        protected Iterable<? extends ISelectable> getSelectables() {
            return getAllResourceDescriptions();
        }
    };
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ISelectable(org.eclipse.xtext.resource.ISelectable) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Before(org.junit.Before)

Aggregations

ISelectable (org.eclipse.xtext.resource.ISelectable)5 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 IScope (org.eclipse.xtext.scoping.IScope)2 Function (com.google.common.base.Function)1 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)1 Before (org.junit.Before)1