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