Search in sources :

Example 1 with ASTFlowInfo

use of org.eclipse.n4js.postprocessing.ASTFlowInfo in project n4js by eclipse.

the class N4JSProjectBuilder method newBuildRequest.

@Override
protected XBuildRequest newBuildRequest(IBuildRequestFactory buildRequestFactory, Set<URI> changedFiles, Set<URI> deletedFiles, List<Delta> externalDeltas, CancelIndicator cancelIndicator) {
    XBuildRequest request = super.newBuildRequest(buildRequestFactory, changedFiles, deletedFiles, externalDeltas, cancelIndicator);
    ProjectDescription pd = getProjectConfig().getProjectDescription();
    if (N4JSLanguageUtils.isDtsGenerationActive(pd)) {
        request.addAfterBuildRequestListener(new DtsAfterBuildListener(getProjectConfig()));
    }
    request.addAfterBuildFileListener((uri) -> {
        Resource resource = getResource(uri);
        if (resource instanceof N4JSResource) {
            N4JSResource n4jsResource = (N4JSResource) resource;
            ASTFlowInfo flowInfo = n4jsResource.getASTMetaInfoCache().getFlowInfo();
            // release memory
            flowInfo.reset();
            n4jsResource.unloadAST();
        }
    });
    return request;
}
Also used : N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) ASTFlowInfo(org.eclipse.n4js.postprocessing.ASTFlowInfo) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) XBuildRequest(org.eclipse.n4js.xtext.ide.server.build.XBuildRequest)

Example 2 with ASTFlowInfo

use of org.eclipse.n4js.postprocessing.ASTFlowInfo in project n4js by eclipse.

the class N4JSFlowgraphValidator method checkFlowGraphs.

/**
 * Triggers all flow graph related validations
 */
@Check
public void checkFlowGraphs(Script script) {
    N4JSResource resource = (N4JSResource) script.eResource();
    ASTFlowInfo flowInfo = resource.getASTMetaInfoCache().getFlowInfo();
    if (!flowInfo.canPerformBackwardAnalysis()) {
        return;
    }
    flowInfo.performBackwardAnalysis(this::checkCancelled);
    FlowValidator[] fValidators = { new DeadCodeValidator(flowInfo.deadCodeAnalyser, keywordProvider), new UsedBeforeDeclaredValidator(flowInfo.usedBeforeDeclaredAnalyser), new NullUndefinedValidator(flowInfo.nullDereferenceAnalyser, workspaceAccess, findReferenceHelper), new MissingReturnOrThrowValidator(flowInfo.missingReturnOrThrowAnalyser) };
    String uriString = script.eResource().getURI().toString();
    try (Measurement m1 = N4JSDataCollectors.dcFlowGraphs.getMeasurement("flowGraphs_" + uriString);
        Measurement m2 = N4JSDataCollectors.dcFlowGraphPostprocessing.getMeasurement("createGraph_" + uriString)) {
        for (FlowValidator fValidator : fValidators) {
            fValidator.checkResults(this);
        }
    }
// note that releasing memory is done in AfterBuildFileListener added in N4JSProjectBuilder#newBuildRequest
}
Also used : Measurement(org.eclipse.n4js.smith.Measurement) NullUndefinedValidator(org.eclipse.n4js.validation.validators.flowgraphs.NullUndefinedValidator) MissingReturnOrThrowValidator(org.eclipse.n4js.validation.validators.flowgraphs.MissingReturnOrThrowValidator) UsedBeforeDeclaredValidator(org.eclipse.n4js.validation.validators.flowgraphs.UsedBeforeDeclaredValidator) N4JSResource(org.eclipse.n4js.resource.N4JSResource) FlowValidator(org.eclipse.n4js.validation.validators.flowgraphs.FlowValidator) ASTFlowInfo(org.eclipse.n4js.postprocessing.ASTFlowInfo) DeadCodeValidator(org.eclipse.n4js.validation.validators.flowgraphs.DeadCodeValidator) Check(org.eclipse.xtext.validation.Check)

Aggregations

ASTFlowInfo (org.eclipse.n4js.postprocessing.ASTFlowInfo)2 N4JSResource (org.eclipse.n4js.resource.N4JSResource)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)1 Measurement (org.eclipse.n4js.smith.Measurement)1 DeadCodeValidator (org.eclipse.n4js.validation.validators.flowgraphs.DeadCodeValidator)1 FlowValidator (org.eclipse.n4js.validation.validators.flowgraphs.FlowValidator)1 MissingReturnOrThrowValidator (org.eclipse.n4js.validation.validators.flowgraphs.MissingReturnOrThrowValidator)1 NullUndefinedValidator (org.eclipse.n4js.validation.validators.flowgraphs.NullUndefinedValidator)1 UsedBeforeDeclaredValidator (org.eclipse.n4js.validation.validators.flowgraphs.UsedBeforeDeclaredValidator)1 XBuildRequest (org.eclipse.n4js.xtext.ide.server.build.XBuildRequest)1 Check (org.eclipse.xtext.validation.Check)1