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;
}
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;
}
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);
}
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));
}
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();
}
};
}
Aggregations