1 package com.stateofflow.eclipse.metrics.builder;
2
3 import java.io.IOException;
4
5 import org.eclipse.core.runtime.CoreException;
6
7 import com.stateofflow.eclipse.metrics.builder.list.CompilationUnitList;
8 import com.stateofflow.eclipse.metrics.calculators.Calculator;
9 import com.stateofflow.eclipse.metrics.util.ProgressMonitor;
10
11 public class CompilationUnitListMetricProcessor {
12 private final Calculator[] calculators;
13 private final MetricProcessor processor;
14
15 public CompilationUnitListMetricProcessor(final MetricProcessor processor, final Calculator[] calculators) {
16 this.processor = processor;
17 this.calculators = calculators;
18 }
19
20 public void process(final CompilationUnitList compilationUnits, final ProgressMonitor progressMonitor) throws CoreException, IOException {
21 if (processor.hasPostProcessingPhase()) {
22 progressMonitor.beginTask("Processing metrics", 2);
23 processCompilationUnits(compilationUnits, progressMonitor.newChild(1));
24 processor.afterMeasuringAllCompilationUnits(progressMonitor.newChild(1));
25 } else {
26 processCompilationUnits(compilationUnits, progressMonitor);
27 }
28 }
29
30 private void processCompilationUnits(final CompilationUnitList compilationUnits, final ProgressMonitor progressMonitor) throws CoreException {
31 progressMonitor.beginTask("Processing metrics", compilationUnits.size());
32 for (int i = 0; i < compilationUnits.size(); i++) {
33 new CompilationUnitMetricProcessor(calculators, processor).process(compilationUnits.get(i), progressMonitor.newChild(1));
34 }
35 }
36 }
37