Search in sources :

Example 1 with Metrics

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;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Metrics(org.eclipse.titanium.metrics.implementation.Metrics) ArrayList(java.util.ArrayList) List(java.util.List) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Module (org.eclipse.titan.designer.AST.Module)1 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)1 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)1 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1 Metrics (org.eclipse.titanium.metrics.implementation.Metrics)1