use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class UserDataAwareScope method resolve.
private IEObjectDescription resolve(IEObjectDescription original) {
if (original != null && original.getEObjectOrProxy().eIsProxy() && EcoreUtil2.isAssignableFrom(type, original.getEClass())) {
final URI objectURI = original.getEObjectURI();
final URI resourceURI = objectURI.trimFragment();
Resource resource = resourceSet.getResource(resourceURI, false);
if (resource != null && resource.isLoaded()) {
return original;
}
final boolean mustLoadFromSource = canLoadFromDescriptionHelper.mustLoadFromSource(resourceURI, resourceSet);
resource = resourceSet.getResource(resourceURI, mustLoadFromSource);
if (resource != null && resource.isLoaded()) {
return original;
}
if (mustLoadFromSource) {
// --> still avoid loading from index; instead simply return 'original' as in other error cases
return original;
}
if (resource == null) {
resource = resourceSet.createResource(resourceURI);
}
if (resource instanceof N4JSResource) {
if (resource.getContents().isEmpty()) {
N4JSResource casted = (N4JSResource) resource;
IResourceDescription resourceDescription = container.getResourceDescription(resourceURI);
if (resourceDescription != null) {
if (casted.isLoaded()) {
// will load that stuff on #getResourceDescription
return original;
}
try {
if (!casted.loadFromDescription(resourceDescription)) {
return original;
}
} catch (Exception e) {
casted.unload();
return original;
}
} else {
return original;
}
}
// resolveProxy is implemented recursively thus we have to avoid
// that here by decorating the
// description and return the resolved instance instead
EObject resolved = resolveObject(objectURI, resource);
if (resolved == null) {
return original;
}
return new ResolvedDescription(resolved, original);
}
}
return original;
}
Aggregations