Search in sources :

Example 1 with IUsageAwareEObjectDescription

use of org.eclipse.n4js.scoping.IUsageAwareEObjectDescription in project n4js by eclipse.

the class ErrorAwareLinkingService method getLinkedObjects.

@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null)
        return Collections.<EObject>emptyList();
    final String crossRefString = getCrossRefNodeAsString(context, ref, node);
    if (crossRefString != null && !crossRefString.equals("")) {
        final IScope scope = getScope(context, ref);
        QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
        IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
        if (IEObjectDescriptionWithError.isErrorDescription(eObjectDescription) && context.eResource() != null && !n4jsCore.isNoValidate(context.eResource().getURI())) {
            addError(context, node, IEObjectDescriptionWithError.getDescriptionWithError(eObjectDescription));
        } else if (eObjectDescription instanceof UnresolvableObjectDescription) {
            return Collections.<EObject>singletonList((EObject) context.eGet(ref, false));
        }
        if (eObjectDescription != null) {
            EObject candidate = eObjectDescription.getEObjectOrProxy();
            if (!candidate.eIsProxy() && candidate.eResource() == null) {
                // Error is necessary since EMF catches all exceptions in EcoreUtil#resolve
                throw new AssertionError("Found an instance without resource and without URI");
            }
            // if supported, mark object description as used
            if (eObjectDescription instanceof IUsageAwareEObjectDescription) {
                ((IUsageAwareEObjectDescription) eObjectDescription).markAsUsed();
            }
            return Collections.singletonList(candidate);
        }
    }
    return Collections.emptyList();
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IUsageAwareEObjectDescription(org.eclipse.n4js.scoping.IUsageAwareEObjectDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) UnresolvableObjectDescription(org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 IUsageAwareEObjectDescription (org.eclipse.n4js.scoping.IUsageAwareEObjectDescription)1 UnresolvableObjectDescription (org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1