Search in sources :

Example 16 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.
 *
 * @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 nameFunctions
 *          The name functions to apply
 * @param originalResource
 *          The original resource
 * @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 EObject context, final ContainerQuery query, final Resource originalResource, 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 ContainerBasedScope(id, result, container, query, nameFunctions, caseInsensitive);
    }
    return result;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) IContainer(org.eclipse.xtext.resource.IContainer)

Example 17 with IScope

use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.

the class DelegatingScope method toString.

@SuppressWarnings("nls")
@Override
public String toString() {
    final StringBuilder result = new StringBuilder(getClass().getName());
    result.append('@');
    result.append(Integer.toHexString(hashCode()));
    result.append(" (id: ");
    result.append(getId());
    final Iterable<IScope> delegateScopes = getDelegates();
    if (delegateScopes != null && !Iterables.isEmpty(delegateScopes)) {
        result.append(", delegates: ");
        result.append(Iterables.toString(delegateScopes));
    }
    result.append(')');
    final IScope outerScope = getParent();
    if (outerScope != IScope.NULLSCOPE) {
        result.append("\n  >> ");
        result.append(outerScope.toString().replaceAll("\\\n", "\n  "));
    }
    return result.toString();
}
Also used : IScope(org.eclipse.xtext.scoping.IScope)

Example 18 with IScope

use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.

the class PrefixedContainerBasedScope method toString.

@SuppressWarnings("nls")
@Override
public String toString() {
    final StringBuilder result = new StringBuilder(getClass().getName());
    result.append('@');
    result.append(Integer.toHexString(hashCode()));
    result.append(" (id: ");
    result.append(getId());
    result.append(", prefix: ");
    result.append(prefix);
    result.append(", query: ");
    result.append(criteria);
    result.append(", container: ");
    result.append(container);
    result.append(')');
    final IScope parent = getParent();
    if (parent != IScope.NULLSCOPE) {
        result.append("\n  >> ");
        result.append(parent.toString().replaceAll("\\\n", "\n  "));
    }
    return result.toString();
}
Also used : IScope(org.eclipse.xtext.scoping.IScope)

Example 19 with IScope

use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.

the class ValidScopingTest method testEStructuralFeatureScope.

/**
 * Tests that validations may be declared on existing EClass and EStructuralFeature instances.
 */
@Test
public void testEStructuralFeatureScope() throws IOException {
    final ValidModel validModel = (ValidModel) getTestSource().getModel();
    final NativeContext context = getXtextTestUtil().getFirstInstanceOf(validModel, NativeContext.class);
    // Check context feature reference
    IScope scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_FEATURE);
    IEObjectDescription name = scope.getSingleElement(QualifiedName.create("name"));
    assertNotNull("Found valid EStructuralFeature \"name\"", name);
    final EObject resolvedName = name.getEObjectOrProxy();
    assertNotNull("Valid EStructuralFeature \"name\" can be resolved", resolvedName);
    // Check context type reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_TYPE);
    assertEquals("Scope provider returns correct context type", context.getContextType(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
    assertEquals("Container of \"name\" reference instance is \"Model\" instance", resolvedName.eContainer(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
    // Check marker type reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_TYPE);
    assertEquals("Scope provider returns correct marker type", context.getMarkerType(), scope.getSingleElement(QualifiedName.create("Element")).getEObjectOrProxy());
    // Check marker feature reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_FEATURE);
    assertEquals("Scope provider returns correct marker feature", context.getMarkerFeature(), scope.getSingleElement(QualifiedName.create("name")).getEObjectOrProxy());
}
Also used : ValidModel(com.avaloq.tools.ddk.xtext.valid.valid.ValidModel) NativeContext(com.avaloq.tools.ddk.xtext.valid.valid.NativeContext) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) AbstractScopingTest(com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest) Test(org.junit.Test)

Example 20 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class OperationOverloadingLinkingService method getLinkedOperation.

public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null) {
        return Collections.<EObject>emptyList();
    }
    final String crossRefString = getCrossRefNodeAsString(node);
    if (crossRefString == null || crossRefString.equals("")) {
        return Collections.<EObject>emptyList();
    }
    final IScope scope = getScope(context, ref);
    final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
    // Adoption to super class implementation here to return multi elements
    final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName);
    int size = Iterables.size(eObjectDescription);
    if (size == 0)
        return Collections.emptyList();
    if (size == 1)
        return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
    // Two operation with same name found here
    List<IEObjectDescription> candidates = new ArrayList<>();
    for (IEObjectDescription currentDescription : eObjectDescription) {
        if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) {
            candidates.add(currentDescription);
        }
    }
    Optional<Operation> operation = operationsLinker.linkOperation(candidates, context);
    if (operation.isPresent()) {
        return Collections.singletonList(operation.get());
    }
    // Link to first operation to get parameter errors instead of linking errors
    return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) Operation(org.yakindu.base.types.Operation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

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