Search in sources :

Example 1 with ClosableMeasurement

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);
        }
    }
}
Also used : ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) NullUndefinedValidator(org.eclipse.n4js.validation.validators.flowgraphs.NullUndefinedValidator) MissingReturnOrThrowValidator(org.eclipse.n4js.validation.validators.flowgraphs.MissingReturnOrThrowValidator) N4JSFlowAnalyser(org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser) UsedBeforeDeclaredValidator(org.eclipse.n4js.validation.validators.flowgraphs.UsedBeforeDeclaredValidator) FlowValidator(org.eclipse.n4js.validation.validators.flowgraphs.FlowValidator) FlowAnalyser(org.eclipse.n4js.flowgraphs.FlowAnalyser) N4JSFlowAnalyser(org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser) DeadCodeValidator(org.eclipse.n4js.validation.validators.flowgraphs.DeadCodeValidator) Check(org.eclipse.xtext.validation.Check)

Example 2 with ClosableMeasurement

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);
                }
            }
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) LinkingDiagnosticProducer(org.eclipse.xtext.linking.impl.LinkingDiagnosticProducer) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) TreeIterator(org.eclipse.emf.common.util.TreeIterator) N4JSValueConverterWithValueException(org.eclipse.n4js.conversion.N4JSValueConverterWithValueException) N4JSValueConverterException(org.eclipse.n4js.conversion.N4JSValueConverterException) BadEscapementException(org.eclipse.n4js.conversion.AbstractN4JSStringValueConverter.BadEscapementException)

Example 3 with ClosableMeasurement

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);
    }
}
Also used : ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) GraphVisitorAnalysis(org.eclipse.n4js.flowgraphs.analysis.GraphVisitorAnalysis) SuccessorPredecessorAnalysis(org.eclipse.n4js.flowgraphs.analysis.SuccessorPredecessorAnalysis) SymbolFactory(org.eclipse.n4js.flowgraphs.dataflow.symbols.SymbolFactory) DirectPathAnalyses(org.eclipse.n4js.flowgraphs.analysis.DirectPathAnalyses)

Example 4 with ClosableMeasurement

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) HashMap(java.util.HashMap) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) FlowGraph(org.eclipse.n4js.flowgraphs.model.FlowGraph) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 5 with ClosableMeasurement

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();
    }
}
Also used : ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) URI(java.net.URI) Collection(java.util.Collection) File(java.io.File)

Aggregations

ClosableMeasurement (org.eclipse.n4js.smith.ClosableMeasurement)7 File (java.io.File)1 URI (java.net.URI)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 TreeIterator (org.eclipse.emf.common.util.TreeIterator)1 EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 BadEscapementException (org.eclipse.n4js.conversion.AbstractN4JSStringValueConverter.BadEscapementException)1 N4JSValueConverterException (org.eclipse.n4js.conversion.N4JSValueConverterException)1 N4JSValueConverterWithValueException (org.eclipse.n4js.conversion.N4JSValueConverterWithValueException)1 FlowAnalyser (org.eclipse.n4js.flowgraphs.FlowAnalyser)1 N4JSFlowAnalyser (org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser)1 DirectPathAnalyses (org.eclipse.n4js.flowgraphs.analysis.DirectPathAnalyses)1 GraphVisitorAnalysis (org.eclipse.n4js.flowgraphs.analysis.GraphVisitorAnalysis)1