Search in sources :

Example 1 with UnresolvableObjectDescription

use of org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription in project n4js by eclipse.

the class IsInScopeWithOptionalPositionPredicate method apply.

@Override
public boolean apply(String nameWithPosition) {
    String name = getNameFromNameWithPosition(nameWithPosition);
    String position = getPositionFromNameWithPosition(nameWithPosition);
    QualifiedName qualifiedName = converter.toQualifiedName(name);
    IEObjectDescription desc = scope.getSingleElement(qualifiedName);
    if (desc != null && !(desc instanceof IEObjectDescriptionWithError) && !(desc instanceof UnresolvableObjectDescription)) {
        if (!Strings.isNullOrEmpty(position)) {
            String nameWithPositionOfScopeELement = descriptionToNameWithPosition(currentURI, withLineNumber, desc);
            String positionOfScopeElement = getPositionFromNameWithPosition(nameWithPositionOfScopeELement);
            if (position.equals(positionOfScopeElement)) {
                return true;
            }
        } else {
            return true;
        }
    }
    return false;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) UnresolvableObjectDescription(org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)

Example 2 with UnresolvableObjectDescription

use of org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription 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

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