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;
}
}
}
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;
}
}
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;
}
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();
}
Aggregations