/** * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the * produced scope would be empty. * * @param canLoadFromDescriptionHelper * utility to decide if a resource must be loaded from source or may be loaded from the index. */ public static IScope createScope( IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper, IContainer container) { if (selectable == null || selectable.isEmpty()) return outer; IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet, canLoadFromDescriptionHelper, container); return scope; }
@Override protected ISelectable getAllDescriptions(final Resource resource) { List<IEObjectDescription> descriptions = null; final Iterator<EObject> iterator = resource.getAllContents(); while (iterator.hasNext()) { final EObject from = iterator.next(); final QualifiedName qualifiedName = getNameProvider().apply(from); if (qualifiedName != null) { if (descriptions == null) descriptions = new ArrayList<>(); descriptions.add(new EObjectDescription(qualifiedName, from, null)); } } return new MultimapBasedSelectable(descriptions); }
@Override protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) { List<IEObjectDescription> result = newArrayList(); 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) { 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; }
@Override protected ISelectable internalGetAllDescriptions(Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>() { @Override public Iterator<EObject> iterator() { return EcoreUtil.getAllContents(resource, false); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, this.getQualifiedNameProvider()); Iterable<IEObjectDescription> allAliasedDescriptions = new Iterable<IEObjectDescription>() { @Override public Iterator<IEObjectDescription> iterator() { return Streams.stream(allDescriptions) .map(CooperateImportedNamespaceAwareLocalScopeProvider::createAliasedDescription).iterator(); } }; return new MultimapBasedSelectable(allAliasedDescriptions); }
UserDataAwareScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper, IContainer container) { super(outer, selectable, filter, type, ignoreCase); this.resourceSet = resourceSet; this.canLoadFromDescriptionHelper = canLoadFromDescriptionHelper; this.container = container; this.type = type; }
protected IScope getResourceScope(IScope globalScope, @SuppressWarnings("unused") Resource res, EReference reference) { IScope result = globalScope; ISelectable globalScopeSelectable = new ScopeBasedSelectable(result); // implicit imports (i.e. java.lang.*) List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference)); if (!normalizers.isEmpty()) { result = createImportScope(result, normalizers, globalScopeSelectable, reference.getEReferenceType(), isIgnoreCase(reference)); } return result; }
protected ISelectable getAllDescriptions(final Resource resource) { return cache.get("internalGetAllDescriptions", resource, new Provider<ISelectable>() { @Override public ISelectable get() { return internalGetAllDescriptions(resource); } }); }
protected ISelectable internalGetAllDescriptions(final Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>(){ @Override public Iterator<EObject> iterator() { return EcoreUtil.getAllContents(resource, false); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider); return new MultimapBasedSelectable(allDescriptions); }
@Override public Iterable<IEObjectDescription> getExportedObjects() { return Iterables.concat(Iterables.transform(getSelectables(), new Function<ISelectable, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(ISelectable from) { if (from != null) return from.getExportedObjects(); return Collections.emptyList(); } })); }
@Override public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) { return Iterables.concat(Iterables.transform(getSelectables(), new Function<ISelectable, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(ISelectable from) { if (from != null) return from.getExportedObjectsByType(type); return Collections.emptyList(); } })); }
@Override public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) { return Iterables.concat(Iterables.transform(getSelectables(), new Function<ISelectable, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(ISelectable from) { if (from != null) return from.getExportedObjectsByObject(object); return Collections.emptyList(); } })); }
@Override public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName qualifiedName, final boolean ignoreCase) { return Iterables.concat(Iterables.transform(getSelectables(), new Function<ISelectable, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(ISelectable from) { if (from != null) return from.getExportedObjects(type, qualifiedName, ignoreCase); return Collections.emptyList(); } })); }
@Override public Iterable<IEObjectDescription> getExportedObjects() { return Iterables.concat(Iterables.transform(getAllResourceDescriptions(), new Function<ISelectable, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(ISelectable from) { if (from != null) return from.getExportedObjects(); return ImmutableSet.of(); } })); }
@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)); }
protected ISelectable getAllDescriptions(final Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>(){ @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider); return new MultimapBasedSelectable(allDescriptions); }
public ImportScope(List<ImportNormalizer> namespaceResolvers, IScope parent, ISelectable importFrom, EClass type, boolean ignoreCase) { super(parent, ignoreCase); this.type = type; this.normalizers = removeDuplicates(namespaceResolvers); this.importFrom = importFrom; }
@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; }
protected ISelectable getImportFrom() { ISelectable importFrom = this.importFrom; if (importFrom == null) { importFrom = new ScopeBasedSelectable(getParent()); } return importFrom; }
protected IScope getResourceScope(final IScope parent, final EObject context, final EReference reference) { // TODO: SZ - context may not be a proxy, may it? if (context.eResource() == null) return parent; ISelectable allDescriptions = getAllDescriptions(context.eResource()); return SelectableBasedScope.createScope(parent, allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference)); }
@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(); } }; }
@Override protected Iterable<? extends ISelectable> getSelectables() { return getAllResourceDescriptions(); }
/** * Delegates to super constructor. */ protected PolyfillAwareSelectableBasedScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) { super(outer, selectable, filter, type, ignoreCase); }
/** * Creates new scope with given ISelectable. */ public static IScope createMainModuleAwareScope(IScope parent, ISelectable selectable, EClass type) { return new MainModuleAwareSelectableBasedScope(parent, selectable, null, type, true); }
/** * Delegates to super constructor. */ protected MainModuleAwareSelectableBasedScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) { super(outer, selectable, filter, type, ignoreCase); }
protected ImportScope createImportScope(IScope parent, List<ImportNormalizer> namespaceResolvers, ISelectable importFrom, EClass type, boolean ignoreCase) { if (importFrom == null) throw new NullPointerException("importFrom"); return new ImportScope(namespaceResolvers, parent, importFrom, type, ignoreCase); }
protected IScope createScope(IScope parent, ISelectable resourceContent, EClass type, boolean ignoreCase) { return SelectableBasedScope.createScope(parent, resourceContent, type, ignoreCase); }
public static IScope createScope(IScope outer, ISelectable selectable, EClass type, boolean ignoreCase) { return createScope(outer, selectable, null, type, ignoreCase); }
public static IScope createScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) { if (selectable == null || selectable.isEmpty()) return outer; return new SelectableBasedScope(outer, selectable, filter, type, ignoreCase); }
protected SelectableBasedScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) { super(outer, ignoreCase); this.filter = filter; this.selectable = selectable; this.type = type; }
protected ISelectable getSelectable() { return selectable; }
protected ImportScope createImportScope(IScope parent, List<ImportNormalizer> namespaceResolvers, ISelectable importFrom, EClass type, boolean ignoreCase) { return new ImportScope(namespaceResolvers, parent, importFrom, type, ignoreCase); }
@Override protected Iterable<? extends ISelectable> getSelectables() { return this.chunk2resourceDescriptions.values(); }