use of org.eclipse.n4js.flowgraphs.FlowAnalyser 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.flowgraphs.FlowAnalyser in project n4js by eclipse.
the class GraphVisitorAnalysis method getGraphVisitors.
private List<GraphVisitorInternal> getGraphVisitors(FlowAnalyser[] flowAnalysers, TraverseDirection direction) {
List<GraphVisitorInternal> graphVisitors = new LinkedList<>();
List<DataFlowVisitor> dataflowVisitorList = new LinkedList<>();
for (FlowAnalyser flowAnalyser : flowAnalysers) {
if (flowAnalyser instanceof GraphVisitorInternal) {
GraphVisitorInternal graphVisitor = (GraphVisitorInternal) flowAnalyser;
if (graphVisitor.getDirection() == direction) {
graphVisitors.add(graphVisitor);
}
}
if (flowAnalyser instanceof DataFlowVisitor) {
DataFlowVisitor dataflowVisitor = (DataFlowVisitor) flowAnalyser;
if (dataflowVisitor.getDirection() == direction) {
dataflowVisitorList.add(dataflowVisitor);
}
}
}
if (!dataflowVisitorList.isEmpty()) {
DataFlowVisitorHost dfvh = new DataFlowVisitorHost(direction, dataflowVisitorList);
graphVisitors.add(dfvh);
}
return graphVisitors;
}
Aggregations