Search in sources :

Example 1 with TypeVisibility

use of org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility in project n4js by eclipse.

the class VisibilityAwareTypeScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance instanceof Type) {
        Type type = (Type) proxyOrInstance;
        if (type.eIsProxy() && contextResource != null) {
            // we found a proxy. Only valid precondition for a proxy that was returned from a
            // UserDataAwareScope is that the resource that contains the real instance is already
            // available in the resource set and loaded.
            // thus it's save to use resourceSet.getEObject(uri, false) and it has to return a proper instance
            // 
            ResourceSet resourceSet = contextResource.getResourceSet();
            // don't load on demand
            EObject fromResourceSet = resourceSet.getEObject(description.getEObjectURI(), false);
            if (fromResourceSet instanceof Type) {
                type = (Type) fromResourceSet;
            } else {
                // assume the unresolved proxy to be visible to reduce number of follow-up problems.
                return true;
            }
        }
        // paranoid double check - object from resource set should never be a proxy
        if (!type.eIsProxy()) {
            TypeVisibility typeVisibility = checker.isVisible(contextResource, type);
            if (typeVisibility.visibility) {
                accessModifierSuggestionStore.put(description.getEObjectURI().toString(), typeVisibility.accessModifierSuggestion);
            }
            return typeVisibility.visibility;
        } else {
            throw new IllegalStateException("Unexpected proxy:" + type);
        }
    }
    return true;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TypeVisibility(org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 2 with TypeVisibility

use of org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility in project n4js by eclipse.

the class TopLevelElementsCollector method getTopLevelElements.

/**
 * Returns an iterable of all top-level elements of the given module, given that they are accessed from the given
 * context resource.
 *
 * @param module
 *            The module
 * @param contextResource
 *            The context resource
 */
public Iterable<IEObjectDescription> getTopLevelElements(TModule module, Resource contextResource) {
    List<IEObjectDescription> visible = new ArrayList<>();
    List<IEObjectDescription> invisible = new ArrayList<>();
    module.getTopLevelTypes().forEach(it -> {
        TypeVisibility typeVisiblity = typeVisibilityChecker.isVisible(contextResource, it);
        if (typeVisiblity.visibility) {
            visible.add(createObjectDescription(it));
        } else {
            invisible.add(new InvisibleTypeOrVariableDescription(createObjectDescription(it), typeVisiblity.accessModifierSuggestion));
        }
    });
    module.getVariables().forEach(it -> {
        TypeVisibility typeVisiblity = variableVisibilityChecker.isVisible(contextResource, it);
        if (typeVisiblity.visibility) {
            visible.add(createObjectDescription(it));
        } else {
            invisible.add(new InvisibleTypeOrVariableDescription(createObjectDescription(it), typeVisiblity.accessModifierSuggestion));
        }
    });
    return Iterables.concat(visible, invisible);
}
Also used : TypeVisibility(org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility) ArrayList(java.util.ArrayList) InvisibleTypeOrVariableDescription(org.eclipse.n4js.scoping.accessModifiers.InvisibleTypeOrVariableDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with TypeVisibility

use of org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility in project n4js by eclipse.

the class VisibilityAwareIdentifiableScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance instanceof TVariable && !proxyOrInstance.eIsProxy()) {
        TVariable type = (TVariable) proxyOrInstance;
        TypeVisibility visibility = checker.isVisible(this.contextResource, type);
        if (!visibility.visibility) {
            this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(), visibility.accessModifierSuggestion);
        }
        return visibility.visibility;
    }
    return super.isAccepted(description);
}
Also used : TVariable(org.eclipse.n4js.ts.types.TVariable) TypeVisibility(org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

TypeVisibility (org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility)3 EObject (org.eclipse.emf.ecore.EObject)2 ArrayList (java.util.ArrayList)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 InvisibleTypeOrVariableDescription (org.eclipse.n4js.scoping.accessModifiers.InvisibleTypeOrVariableDescription)1 TVariable (org.eclipse.n4js.ts.types.TVariable)1 Type (org.eclipse.n4js.ts.types.Type)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1