Search in sources :

Example 1 with WrappingTypedScope

use of com.avaloq.tools.ddk.xtext.linking.ImportedNamesTypesAdapter.WrappingTypedScope in project dsl-devkit by dsldevkit.

the class LinkingService method getSingleElement.

/**
 * Gets an {@link EObject} that best matches a given context, reference, and qualified name.
 * <p>
 * The concept of a "best match" is "in the eye of the beholder", that is, the context and reference. The default case is the first element returned from the
 * scope for the given context and reference that matches the given qualified name.
 * </p>
 *
 * @param context
 *          the context of the {@code reference}, must not be {@code null}
 * @param reference
 *          the reference for which the result element should be suitable, must not be {@code null}
 * @param qualifiedLinkName
 *          the name that the result element should match, must not be {@code null}
 * @return an eObject that best matches {@code qualifiedLinkName} in {@code scope} given the {@code context} and {@code reference},
 *         may by {@code null}
 */
protected EObject getSingleElement(final EObject context, final EReference reference, final QualifiedName qualifiedLinkName) {
    IEObjectDescription desc = null;
    IScope scope = getScope(context, reference);
    if (scope instanceof WrappingTypedScope) {
        desc = ((WrappingTypedScope) scope).getSingleElement(qualifiedLinkName, reference);
    } else {
        desc = scope.getSingleElement(qualifiedLinkName);
    }
    return desc == null ? null : desc.getEObjectOrProxy();
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) WrappingTypedScope(com.avaloq.tools.ddk.xtext.linking.ImportedNamesTypesAdapter.WrappingTypedScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

WrappingTypedScope (com.avaloq.tools.ddk.xtext.linking.ImportedNamesTypesAdapter.WrappingTypedScope)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1