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();
}
Aggregations