Search in sources :

Example 11 with IScope

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
}
Also used : ExportModel(com.avaloq.tools.ddk.xtext.export.export.ExportModel) IScope(org.eclipse.xtext.scoping.IScope) AbstractScopingTest(com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest) Test(org.junit.Test)

Example 12 with IScope

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;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) DataFilteringScope(com.avaloq.tools.ddk.xtext.scoping.impl.DataFilteringScope) IContainer(org.eclipse.xtext.resource.IContainer) BranchingScope(com.avaloq.tools.ddk.xtext.scoping.impl.BranchingScope)

Example 13 with IScope

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;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 14 with IScope

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;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) IContainer(org.eclipse.xtext.resource.IContainer)

Example 15 with IScope

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope)

Aggregations

IScope (org.eclipse.xtext.scoping.IScope)148 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)57 Test (org.junit.Test)53 EObject (org.eclipse.emf.ecore.EObject)43 QualifiedName (org.eclipse.xtext.naming.QualifiedName)26 XtextResource (org.eclipse.xtext.resource.XtextResource)19 EReference (org.eclipse.emf.ecore.EReference)17 EClass (org.eclipse.emf.ecore.EClass)15 StringInputStream (org.eclipse.xtext.util.StringInputStream)15 URI (org.eclipse.emf.common.util.URI)12 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)12 ArrayList (java.util.ArrayList)10 Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 AbstractScopingTest (com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)7 Predicate (com.google.common.base.Predicate)6 EClassifier (org.eclipse.emf.ecore.EClassifier)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6