use of org.eclipse.n4js.smith.ClosableMeasurement in project n4js by eclipse.
the class N4JSFlowgraphValidator method checkFlowGraphs.
/**
* Triggers all flow graph related validations
*/
@Check
public void checkFlowGraphs(Script script) {
// Note: The Flow Graph is NOT stored in the meta info cache. Hence, it is created here at use site.
// In case the its creation is moved to the N4JSPostProcessor, care about an increase in memory consumption.
N4JSFlowAnalyser flowAnalyzer = new N4JSFlowAnalyser(this::checkCancelled);
FlowValidator[] fValidators = { new DeadCodeValidator(keywordProvider), new UsedBeforeDeclaredValidator(), new NullUndefinedValidator(n4jsCore, findReferenceHelper), new MissingReturnOrThrowValidator(typeSystemHelper, jsVariantHelper) };
FlowAnalyser[] fAnalysers = new FlowAnalyser[fValidators.length];
for (int i = 0; i < fValidators.length; i++) {
fAnalysers[i] = fValidators[i].getFlowAnalyser();
}
flowAnalyzer.createGraphs(script);
flowAnalyzer.accept(fAnalysers);
String uriString = script.eResource().getURI().toString();
try (ClosableMeasurement m1 = dcFlowGraphs.getClosableMeasurement("flowGraphs_" + uriString);
ClosableMeasurement m2 = dcPostprocessing.getClosableMeasurement("createGraph_" + uriString)) {
for (FlowValidator fValidator : fValidators) {
fValidator.checkResults(this);
}
}
}
use of org.eclipse.n4js.smith.ClosableMeasurement in project n4js by eclipse.
the class N4JSLinker method doLinkModel.
/**
* Clears the list of encoded URIs in {@link N4JSResource}, installs proxies for all cross references inside the
* parsed model. If validation is enabled finally the {@link ASTStructureValidator} is triggered, that checks the
* now linked AST structure.
*/
@Override
protected void doLinkModel(final EObject model, final IDiagnosticConsumer consumer) {
final LinkingDiagnosticProducer producer = new LinkingDiagnosticProducer(consumer);
getCache().execWithoutCacheClear((N4JSResource) model.eResource(), new IUnitOfWork.Void<N4JSResource>() {
@Override
public void process(N4JSResource resource) throws Exception {
// actual linking
resource.clearLazyProxyInformation();
clearReferences(model);
installProxies(resource, model, producer);
TreeIterator<EObject> iterator = model.eAllContents();
while (iterator.hasNext()) {
EObject eObject = iterator.next();
clearReferences(eObject);
installProxies(resource, eObject, producer);
}
// pre-processing of AST
String resourceName = resource.getURI().toString();
try (ClosableMeasurement mes = dcPreProcess.getClosableMeasurement(resourceName)) {
preProcessor.process(resource.getScript(), resource);
}
// AST structure validation
if (!resource.isValidationDisabled()) {
try (ClosableMeasurement m1 = dcValidations.getClosableMeasurement(resourceName);
ClosableMeasurement m2 = dcStructureValidations.getClosableMeasurement(resourceName)) {
getStructureValidator().validate(model, consumer);
}
}
}
});
}
use of org.eclipse.n4js.smith.ClosableMeasurement in project n4js by eclipse.
the class N4JSFlowAnalyser method createGraphs.
/**
* Creates the control flow graphs for all {@link ControlFlowElement}s in the given {@link Script}.
* <p/>
* Never completes abruptly, i.e. throws an exception.
*/
public void createGraphs(Script script) {
Objects.requireNonNull(script);
String uriString = script.eResource().getURI().toString();
try (ClosableMeasurement m1 = dcFlowGraphs.getClosableMeasurement("flowGraphs_" + uriString);
ClosableMeasurement m2 = dcCreateGraph.getClosableMeasurement("createGraph_" + uriString)) {
symbolFactory = new SymbolFactory();
cfg = ControlFlowGraphFactory.build(script);
dpa = new DirectPathAnalyses(cfg);
gva = new GraphVisitorAnalysis(this, cfg);
spa = new SuccessorPredecessorAnalysis(cfg);
}
}
use of org.eclipse.n4js.smith.ClosableMeasurement in project n4js by eclipse.
the class ControlFlowGraphFactory method build.
/**
* Builds and returns a control flow graph from a given {@link Script}.
*/
public static FlowGraph build(Script script) {
Set<ControlFlowElement> cfContainers = new LinkedHashSet<>();
Map<ControlFlowElement, ComplexNode> cnMap = new HashMap<>();
String uriString = script.eResource().getURI().toString();
ComplexNodeMapper cnMapper = null;
try (ClosableMeasurement m = dcCreateNodes.getClosableMeasurement("createNodes_" + uriString)) {
createComplexNodes(script, cfContainers, cnMap);
cnMapper = new ComplexNodeMapper(cnMap);
}
try (ClosableMeasurement m = dcConnectNodes.getClosableMeasurement("connectNodes_" + uriString)) {
connectComplexNodes(cnMapper);
}
try (ClosableMeasurement m = dcJumpEdges.getClosableMeasurement("jumpEdges_" + uriString)) {
createJumpEdges(cnMapper);
}
FlowGraph cfg = new FlowGraph(script, cfContainers, cnMap);
if (PRINT_EDGE_DETAILS)
printAllEdgeDetails(cnMapper);
return cfg;
}
use of org.eclipse.n4js.smith.ClosableMeasurement in project n4js by eclipse.
the class NpmManager method installDependenciesInternal.
private IStatus installDependenciesInternal(final Map<String, String> versionedNPMs, final IProgressMonitor monitor, boolean triggerCleanbuild) {
MultiStatus status = statusHelper.createMultiStatus("Status of installing multiple npm dependencies.");
IStatus binaryStatus = checkNPM();
if (!binaryStatus.isOK()) {
status.merge(binaryStatus);
return status;
}
Set<String> requestedNPMs = versionedNPMs.keySet();
try (ClosableMeasurement mes = dcLibMngr.getClosableMeasurement("installDependenciesInternal")) {
Set<String> oldNPMs = getOldNPMs(monitor, requestedNPMs);
installUninstallNPMs(versionedNPMs, monitor, status, requestedNPMs, oldNPMs);
Pair<Collection<String>, Iterable<java.net.URI>> changedDeps = getChangedDependencies(monitor, oldNPMs);
Collection<String> addedDependencies = changedDeps.getFirst();
Iterable<java.net.URI> toBeDeleted = changedDeps.getSecond();
Collection<File> adaptedPackages = adaptNPMPackages(monitor, status, addedDependencies);
cleanBuildDependencies(monitor, status, toBeDeleted, adaptedPackages, triggerCleanbuild);
return status;
} finally {
monitor.done();
}
}
Aggregations