Search in sources :

Example 1 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError in project n4js by eclipse.

the class IntersectionMemberScope method getCheckedDescription.

@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);
    QualifiedName qn = QualifiedName.create(name);
    boolean allDescrWithError = true;
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        allDescrWithError &= descrWithError;
    }
    if (allDescrWithError) {
        return createComposedMemberDescriptionWithErrors(description);
    }
    return description;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError in project n4js by eclipse.

the class UnionMemberScope method getCheckedDescription.

@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);
    QualifiedName qn = QualifiedName.create(name);
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        if (descrWithError) {
            return createComposedMemberDescriptionWithErrors(description);
        }
    }
    return description;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError 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 4 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError in project n4js by eclipse.

the class ComposedMemberDescriptionWithError method initialize.

private boolean initialize() {
    if (message == null) {
        IEObjectDescription[] descriptions = new IEObjectDescription[subScopes.length];
        // use string here, since EnumLiteral is
        MapOfIndexes<String> indexesPerMemberType = new MapOfIndexes<>();
        // not a TMember!
        MapOfIndexes<String> indexesPerCode = new MapOfIndexes<>();
        List<String> missingFrom = new ArrayList<>();
        final QualifiedName name = getName();
        boolean readOnlyField = false;
        for (int i = 0; i < max; i++) {
            IEObjectDescription description = subScopes[i].getSingleElement(name);
            if (description != null) {
                descriptions[i] = description;
                EObject eobj = description.getEObjectOrProxy();
                String type = getMemberTypeName(eobj);
                indexesPerMemberType.add(type, i);
                if (description instanceof IEObjectDescriptionWithError) {
                    String subCode = ((IEObjectDescriptionWithError) description).getIssueCode();
                    indexesPerCode.add(subCode, i);
                }
                if ("field".equals(type)) {
                    readOnlyField |= !((TField) eobj).isWriteable();
                }
            } else {
                missingFrom.add(getNameForSubScope(i));
            }
        }
        return initMessageAndCode(missingFrom, indexesPerMemberType, name, readOnlyField, descriptions, indexesPerCode);
    }
    return false;
}
Also used : TField(org.eclipse.n4js.ts.types.TField) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EObject(org.eclipse.emf.ecore.EObject)

Example 5 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError in project n4js by eclipse.

the class ComposedMemberScope method getAllLocalElements.

/**
 * Returns all elements of union. No erroneous descriptions (instances of IEObjectDescriptionWithError) will be
 * considered here, as we assume this method to be called from content assist and we do not want to show wrong
 * elements. These descriptions will be returned by {@link #getSingleElement(QualifiedName)} though to show errors
 * in case of explicit references to these members.
 */
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
    // collect all names from subScopes
    final Set<String> names = new HashSet<>();
    for (IScope currSubScope : subScopes) {
        try {
            for (IEObjectDescription currDesc : currSubScope.getAllElements()) {
                // omit erroneous bindings (they will be provided in getSingleLocalElement... though)
                if (!(currDesc instanceof IEObjectDescriptionWithError)) {
                    String name = currDesc.getName().getLastSegment();
                    names.add(name);
                }
            }
        } catch (UnsupportedOperationException e) {
        // according to API doc of IScope#getAllElements(), scopes are free to throw an
        // UnsupportedOperationException --> therefore we catch and ignore this here
        }
    }
    List<IEObjectDescription> descriptions = new ArrayList<>(names.size());
    for (String name : names) {
        IEObjectDescription description = getSingleLocalElementByName(QualifiedName.create(name));
        if (description != null && !(description instanceof IEObjectDescriptionWithError)) {
            descriptions.add(description);
        }
    }
    return descriptions;
}
Also used : ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) HashSet(java.util.HashSet) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescriptionWithError (org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError)6 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)5 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 IScope (org.eclipse.xtext.scoping.IScope)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 UnresolvableObjectDescription (org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)1 TField (org.eclipse.n4js.ts.types.TField)1