use of org.eclipse.titanium.metrics.implementation.Metrics in project titan.EclipsePlug-ins by eclipse.
the class MetricData method measure.
/**
* Execute the metrics on the project and compose the results.
* <p>
* Note that internally the project is locked.
*
* @param project
* the project to analyze
*
* @return the composed result of the measurements
*/
public static MetricData measure(final IProject project) {
synchronized (project) {
// reading the lists of altsteps, testcases, functions and modules
// that are to be measured
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
final Risks risks = new Risks();
final MutableMetricData data = new MutableMetricData(risks);
final List<Module> modules = new ArrayList<Module>();
final Map<Module, List<Def_Function>> functions = new HashMap<Module, List<Def_Function>>();
final Map<Module, List<Def_Testcase>> testcases = new HashMap<Module, List<Def_Testcase>>();
final Map<Module, List<Def_Altstep>> altsteps = new HashMap<Module, List<Def_Altstep>>();
for (final String modName : parser.getKnownModuleNames()) {
final Module module = parser.getModuleByName(modName);
modules.add(module);
}
for (final Module module : modules) {
final List<Def_Function> funs = new ArrayList<Def_Function>();
final List<Def_Testcase> tcs = new ArrayList<Def_Testcase>();
final List<Def_Altstep> als = new ArrayList<Def_Altstep>();
module.accept(new DefinitionCollector(funs, tcs, als));
functions.put(module, funs);
testcases.put(module, tcs);
altsteps.put(module, als);
}
data.modules = Collections.unmodifiableList(modules);
data.functions = Collections.unmodifiableMap(functions);
data.testcases = Collections.unmodifiableMap(testcases);
data.altsteps = Collections.unmodifiableMap(altsteps);
MetricData immutableData = new MetricData(project, data);
// initiate the metrics
final Metrics metrics = new Metrics();
for (final AltstepMetric am : AltstepMetric.values()) {
metrics.get(am).init(immutableData);
}
for (final FunctionMetric fm : FunctionMetric.values()) {
metrics.get(fm).init(immutableData);
}
for (final TestcaseMetric tm : TestcaseMetric.values()) {
metrics.get(tm).init(immutableData);
}
for (final ModuleMetric mm : ModuleMetric.values()) {
metrics.get(mm).init(immutableData);
}
for (final ProjectMetric pm : ProjectMetric.values()) {
metrics.get(pm).init(immutableData);
}
// altstep metrics and statistics
for (final AltstepMetric am : AltstepMetric.values()) {
final Statistics projectStats = measureEntities(data.altsteps, metrics.get(am), immutableData, data.altstepMetrics, data.altstepModuleStats);
data.altstepProjectStats.put(am, projectStats);
immutableData = new MetricData(project, data);
}
// function metrics and statistics
for (final FunctionMetric fm : FunctionMetric.values()) {
final Statistics projectStats = measureEntities(data.functions, metrics.get(fm), immutableData, data.functionMetrics, data.functionModuleStats);
data.functionProjectStats.put(fm, projectStats);
immutableData = new MetricData(project, data);
}
// testcase metrics and statistics
for (final TestcaseMetric tm : TestcaseMetric.values()) {
final Statistics projectStats = measureEntities(data.testcases, metrics.get(tm), immutableData, data.testcaseMetrics, data.testcaseModuleStats);
data.testcaseProjectStats.put(tm, projectStats);
immutableData = new MetricData(project, data);
}
// module metrics and statistics
for (final ModuleMetric mm : ModuleMetric.values()) {
final Map<Module, Number> metricResults = new HashMap<Module, Number>();
final int numberOfModules = data.modules.size();
double[] projectLevelResults = new double[numberOfModules];
int projectLevelCounter = 0;
for (final Module module : data.modules) {
final Number result = metrics.get(mm).measure(immutableData, module);
projectLevelResults[projectLevelCounter++] = result.doubleValue();
metricResults.put(module, result);
}
data.moduleMetrics.put(mm, metricResults);
data.moduleProjectStats.put(mm, new Statistics(projectLevelResults, mm, risks.getRisk(mm)));
}
// project metrics
for (final ProjectMetric pm : ProjectMetric.values()) {
final Number result = metrics.get(pm).measure(immutableData, project);
data.projectMetrics.put(pm, result);
}
return immutableData;
}
}
Aggregations