use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class AbstractN4JSCore method loadModuleFromIndex.
@Override
public TModule loadModuleFromIndex(final ResourceSet resourceSet, final IResourceDescription resourceDescription, boolean allowFullLoad) {
final URI resourceURI = resourceDescription.getURI();
Resource resource = resourceSet.getResource(resourceURI, false);
if (resource instanceof N4JSResource) {
final N4JSResource resourceCasted = (N4JSResource) resource;
final Script existingScript = resourceCasted.getScript();
final TModule existingModule = resourceCasted.getModule();
if (existingModule != null) {
// -> simply return that
return existingModule;
} else if (existingScript != null && !existingScript.eIsProxy()) {
// resource exists already and it already has its AST loaded (though no TModule yet)
// -> we have to create the TModule from that AST instead of loading it from index
// trigger installation of derived state (i.e. types builder)
resourceCasted.installDerivedState(false);
return resourceCasted.getModule();
}
}
if (resource == null) {
resource = resourceSet.createResource(resourceURI);
}
if (resource instanceof N4JSResource) {
if (resource.getContents().isEmpty()) {
final N4JSResource casted = (N4JSResource) resource;
try {
if (casted.loadFromDescription(resourceDescription)) {
casted.performPostProcessing();
return casted.getModule();
} else if (allowFullLoad) {
casted.unload();
casted.load(resourceSet.getLoadOptions());
casted.installDerivedState(false);
return casted.getModule();
}
} catch (final Exception e) {
casted.unload();
return null;
}
}
}
return null;
}
use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class N4JSPostProcessor method performPostProcessing.
@Override
public void performPostProcessing(PostProcessingAwareResource resource, CancelIndicator cancelIndicator) {
final N4JSResource resourceCasted = (N4JSResource) resource;
final ASTMetaInfoCache cache = createASTMetaInfoCache(resourceCasted);
try {
postProcessN4JSResource(resourceCasted, cancelIndicator);
} catch (Throwable th) {
operationCanceledManager.propagateIfCancelException(th);
if (cache.hasBrokenAST()) {
// swallow exception, AST is broken due to parse error anyway
} else {
// make sure this error is being reported, even if exception will be suppressed by calling code!
UtilN4.reportError("exception while post-processing resource " + resource.getURI(), th);
throw th;
}
} finally {
cache.clearTemporaryData();
}
}
use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class ResourceLoadingStatistics method countN4JSResourcesLoadedFromAST.
private int countN4JSResourcesLoadedFromAST(ResourceSet resSet) {
int n = 0;
for (Resource res : resSet.getResources()) {
if (!isBuiltInResource(res)) {
if (res instanceof N4JSResource) {
final N4JSResource resCasted = (N4JSResource) res;
final Script script = resCasted.getScript();
if (script != null && !script.eIsProxy()) {
n++;
}
}
}
}
return n;
}
use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class ResourceLoadingStatistics method investigate.
private FileLoadInfo investigate(IN4JSProject project, URI fileURI, IProgressMonitor monitor) {
final CancelIndicator cancelIndicator = new MonitorBasedCancelIndicator(monitor);
operationCanceledManager.checkCanceled(cancelIndicator);
final ResourceSet resSet = n4jsCore.createResourceSet(Optional.of(project));
final N4JSResource res = (N4JSResource) resSet.createResource(fileURI);
try {
res.load(Collections.emptyMap());
} catch (IOException e) {
e.printStackTrace();
}
// trigger loading of AST
res.getContents();
res.resolveLazyCrossReferences(cancelIndicator);
// now start counting what was loaded incidentally ...
return investigate(resSet);
}
use of org.eclipse.n4js.resource.N4JSResource in project n4js by eclipse.
the class ResourceLoadingStatistics method countN4JSResourcesLoadedFromIndex.
private int countN4JSResourcesLoadedFromIndex(ResourceSet resSet) {
int n = 0;
for (Resource res : resSet.getResources()) {
if (!isBuiltInResource(res)) {
if (res instanceof N4JSResource) {
final N4JSResource resCasted = (N4JSResource) res;
final Script script = resCasted.getScript();
final TModule module = resCasted.getModule();
if (script != null && script.eIsProxy() && module != null && !module.eIsProxy()) {
n++;
}
}
}
}
return n;
}
Aggregations