Search in sources :

Example 21 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class UnusedStartedFuncRetVal method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Start_Component_Statement) {
        final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
        final Start_Component_Statement s = (Start_Component_Statement) node;
        final Component_Type compType = Port_Utility.checkComponentReference(timestamp, s, s.getComponent(), false, false);
        final Assignment assignment = s.getFunctionInstanceReference().getRefdAssignment(timestamp, false);
        if (assignment == null) {
            return;
        }
        switch(assignment.getAssignmentType()) {
            case A_FUNCTION:
            case A_FUNCTION_RTEMP:
            case A_FUNCTION_RVAL:
                break;
            default:
                return;
        }
        final Def_Function function = (Def_Function) assignment;
        final IType runsOnType = function.getRunsOnType(timestamp);
        if (compType == null || runsOnType == null || !function.isStartable()) {
            return;
        }
        switch(function.getAssignmentType()) {
            case A_FUNCTION_RTEMP:
                break;
            case A_FUNCTION_RVAL:
                IType type = function.getType(timestamp);
                boolean returnTypeCorrect = false;
                while (!returnTypeCorrect) {
                    if (type.hasDoneAttribute()) {
                        returnTypeCorrect = true;
                        break;
                    }
                    if (type instanceof IReferencingType) {
                        final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        final IType refd = ((IReferencingType) type).getTypeRefd(timestamp, refChain);
                        refChain.release();
                        if (type != refd) {
                            type = refd;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (!returnTypeCorrect) {
                    final String msg = MessageFormat.format(PROBLEM, function.getDescription(), function.getType(timestamp).getTypename());
                    problems.report(s.getFunctionInstanceReference().getLocation(), msg);
                }
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Start_Component_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Start_Component_Statement) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType)

Example 22 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function 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)

Example 23 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class ModuleStatNode method getChildren.

@Override
public Object[] getChildren(final MetricData data) {
    if (initialized) {
        return children;
    }
    final List<? super IContentNode> c = new ArrayList<IContentNode>();
    if (metric instanceof FunctionMetric) {
        for (final Def_Function f : data.getFunctions().get(module)) {
            c.add(new FunctionNode((FunctionMetric) metric, f));
        }
    } else if (metric instanceof TestcaseMetric) {
        for (final Def_Testcase t : data.getTestcases().get(module)) {
            c.add(new TestcaseNode((TestcaseMetric) metric, t));
        }
    } else if (metric instanceof AltstepMetric) {
        for (final Def_Altstep a : data.getAltsteps().get(module)) {
            c.add(new AltstepNode((AltstepMetric) metric, a));
        }
    } else {
        throw new AssertionError("ModuleStatNode should have a subModule-metric");
    }
    children = c.toArray();
    initialized = true;
    return children;
}
Also used : TestcaseMetric(org.eclipse.titanium.metrics.TestcaseMetric) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) AltstepMetric(org.eclipse.titanium.metrics.AltstepMetric) ArrayList(java.util.ArrayList) FunctionMetric(org.eclipse.titanium.metrics.FunctionMetric) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 24 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class FMDefaultActivations method measure.

@Override
public Number measure(final MetricData data, final Def_Function function) {
    final Counter count = new Counter(0);
    function.accept(new CounterVisitor(count) {

        @Override
        public int visit(final IVisitableNode node) {
            if (node instanceof Activate_Statement) {
                count.inc();
            } else if (node instanceof Activate_Referenced_Statement) {
                count.inc();
            } else if (node instanceof ActivateDereferedExpression) {
                count.inc();
            } else if (node instanceof ActivateExpression) {
                count.inc();
            }
            return V_CONTINUE;
        }
    });
    return count.val();
}
Also used : ActivateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ActivateExpression) Counter(org.eclipse.titanium.metrics.visitors.Counter) Activate_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Activate_Statement) CounterVisitor(org.eclipse.titanium.metrics.visitors.CounterVisitor) Activate_Referenced_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Activate_Referenced_Statement) ActivateDereferedExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ActivateDereferedExpression) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Aggregations

Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)17 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)8 Assignment (org.eclipse.titan.designer.AST.Assignment)6 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)5 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)5 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)5 ArrayList (java.util.ArrayList)4 IType (org.eclipse.titan.designer.AST.IType)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)3 HashMap (java.util.HashMap)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2