use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class ExportScopingTest method testEStructuralFeatureScope.
@Test
public void testEStructuralFeatureScope() throws IOException {
ExportModel model = (ExportModel) getTestSource().getModel();
IScope scope = scopeProvider.scope_EStructuralFeature(model.getInterfaces().get(0), null);
// CHECKSTYLE:OFF (DuplicateString)
assertNotNull("Could not locate EStructuralFeature.", scope.getSingleElement(QualifiedName.create("unordered")));
assertNull("Located non-existent EStructuralFeature.", scope.getSingleElement(QualifiedName.create("unorderedX")));
// CHECKSTYLE:ON
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method newDataMatchScope.
/**
* Create a new container scope using the results of a given query as its contents.
*
* @param id
* Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
* @param outer
* The outer scope of the new scope.
* @param context
* The context
* @param query
* The query that defines the scope's contents
* @param originalResource
* The original resource
* @param filters
* to apply
* @param nameFunctions
* The name functions to apply
* @param caseInsensitive
* indicates whether the new scope shall be case insensitive
* @return The new scope
*/
protected IScope newDataMatchScope(final String id, final IScope outer, final EObject context, final ContainerQuery query, final Resource originalResource, final Iterable<Predicate<IEObjectDescription>> filters, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
IScope result = outer;
final List<String> domains = query.getDomains();
for (final IContainer container : Lists.reverse(getVisibleContainers(context, originalResource))) {
if (!domains.isEmpty()) {
final IDomain domain = domainMapper.map(container);
if (domain != null && !domains.contains(domain.getName())) {
// Query not applicable to this container.
continue;
}
}
// Build a branch in the scope chain so that we can filter each container query separately.
IScope contents = new ContainerBasedScope(id, IScope.NULLSCOPE, container, query, nameFunctions, caseInsensitive);
contents = new DataFilteringScope(contents, filters);
result = new BranchingScope(contents, result);
}
return result;
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method getScope.
/**
* Returns a scope for a given context object and EReference, using a named scope definition. If none is found
* tries to find a scope (using the same name) for the type of the reference.
*
* @param context
* the context
* @param reference
* the reference
* @param scopeName
* the scope name
* @param originalResource
* the original resource
* @return the scope
*/
public IScope getScope(final EObject context, final EReference reference, final String scopeName, final Resource originalResource) {
if (context.eResource() != originalResource && context.eResource() instanceof XtextResource) {
registerForeignObject(context, (XtextResource) context.eResource(), originalResource);
}
String nameToFind = scopeName == null ? SCOPE_STRING : scopeName;
IScope scope = internalGetScope(context, reference, nameToFind, originalResource);
if (scope == null) {
scope = internalGetScope(context, reference.getEReferenceType(), nameToFind, originalResource);
}
return (scope == null) ? IScope.NULLSCOPE : scope;
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method newPrefixedContainerScope.
/**
* Create a new prefixed container scope using the results of a given query as its contents.
*
* @param id
* Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
* @param outer
* The outer scope of the new scope.
* @param context
* The context
* @param query
* The query that defines the scope's contents
* @param originalResource
* The original resource
* @param prefix
* prefix to apply for single element lookups
* @param recursive
* whether the qualified name pattern used to search the index should be
* {@link com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern#RECURSIVE_WILDCARD_SEGMENT recursive}
* @param nameFunctions
* The name functions to apply
* @param caseInsensitive
* indicates whether the new scope shall be case insensitive
* @return The new scope
*/
protected IScope newPrefixedContainerScope(final String id, final IScope outer, final EObject context, final ContainerQuery.Builder query, final Resource originalResource, final String prefix, final boolean recursive, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
IScope result = outer;
final List<String> domains = query.getDomains();
for (final IContainer container : Lists.reverse(getVisibleContainers(context, originalResource))) {
if (!domains.isEmpty()) {
final IDomain domain = domainMapper.map(container);
if (domain != null && !domains.contains(domain.getName())) {
// Query not applicable to this container.
continue;
}
}
result = new PrefixedContainerBasedScope(id, result, container, query, nameFunctions, QualifiedNames.safeQualifiedName(prefix), recursive, caseInsensitive);
}
return result;
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method newContainerScope.
/**
* Create a new container scope using the results of a given query as its contents, using the root object of the given resource
* as its context.
*
* @param id
* Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
* @param outer
* The outer scope of the new scope.
* @param rsc
* The context resource
* @param query
* The query that defines the scope's contents
* @param originalResource
* The original resource
* @param nameFunctions
* The name functions to apply
* @param caseInsensitive
* indicates whether the new scope shall be case insensitive
* @return The new scope
*/
protected IScope newContainerScope(final String id, final IScope outer, final Resource rsc, final ContainerQuery query, final Resource originalResource, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
IScope result = outer;
// We always need a context. Default to the top element of the resource.
final EList<EObject> contents = rsc.getContents();
if (contents.size() > 0) {
result = newContainerScope(id, result, contents.get(0), query, originalResource, nameFunctions, caseInsensitive);
}
return result;
}
Aggregations