use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases in project titan.EclipsePlug-ins by eclipse.
the class SelectCoverage method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof SelectCase_Statement)) {
return;
}
final SelectCase_Statement s = (SelectCase_Statement) node;
final Value v = s.getExpression();
if (v == null || v.getIsErroneous(timestamp)) {
return;
}
// if there is an else branch, no smell will be reported
final SelectCases scs = s.getSelectCases();
if (scs == null || scs.getSelectCaseArray() == null) {
return;
}
for (final SelectCase sc : scs.getSelectCaseArray()) {
if (sc.hasElse()) {
return;
}
}
IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (itype instanceof Referenced_Type) {
itype = itype.getTypeRefdLast(timestamp);
}
if (itype == null || !(itype instanceof TTCN3_Enumerated_Type)) {
return;
}
final TTCN3_Enumerated_Type enumType = (TTCN3_Enumerated_Type) itype;
// count number of items in enum, get all items from enum
final EnumItemVisitor enumVisitor = new EnumItemVisitor();
enumType.accept(enumVisitor);
// count number of TemplateInstances in select, get used enum items
final CaseVisitor caseVisitor = new CaseVisitor();
scs.accept(caseVisitor);
if (caseVisitor.isContainsUnfoldable()) {
return;
}
final int casesSize = caseVisitor.getCount();
final int enumSize = enumVisitor.getCount();
if (enumSize > casesSize) {
final List<Identifier> allEnumItems = enumVisitor.getItemsFound();
final List<Identifier> usedEnumItems = caseVisitor.getItemsUsed();
final String enumName = itype.getTypename();
final String itemsNotCovered = getItemsNotCovered(allEnumItems, usedEnumItems);
problems.report(v.getLocation(), MessageFormat.format(ERR_MSG, enumName, enumSize, casesSize, itemsNotCovered));
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases in project titan.EclipsePlug-ins by eclipse.
the class ConvertToEnum method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof SelectCase_Statement)) {
return;
}
final SelectCase_Statement s = (SelectCase_Statement) node;
final Value v = s.getExpression();
if (v == null || v.getIsErroneous(timestamp)) {
return;
}
final IType.Type_type type = v.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!type.equals(Type_type.TYPE_TTCN3_ENUMERATED)) {
final IType governor = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (governor != null && !governor.getIsErroneous(timestamp)) {
problems.report(v.getLocation(), MessageFormat.format(ERROR_MSG_SELECT, governor.getTypename()));
}
}
final SelectCases scs = s.getSelectCases();
if (scs == null || scs.getSelectCaseArray() == null) {
return;
}
for (final SelectCase sc : scs.getSelectCaseArray()) {
if (sc.hasElse()) {
continue;
}
final CaseVisitor visitor = new CaseVisitor(problems);
sc.accept(visitor);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases in project titan.EclipsePlug-ins by eclipse.
the class SelectWithNumbersSorted method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof SelectCase_Statement)) {
return;
}
final SelectCase_Statement s = (SelectCase_Statement) node;
final Value v = s.getExpression();
if (v == null || v.getIsErroneous(timestamp)) {
return;
}
final SelectCases scs = s.getSelectCases();
if (scs == null || scs.getSelectCaseArray() == null) {
return;
}
// if there is an else branch, no smell will be reported
for (final SelectCase sc : scs.getSelectCaseArray()) {
if (sc.hasElse()) {
return;
}
}
IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
// TODO Kristof: az ellenorzes folosleges.
if (itype instanceof Referenced_Type) {
itype = itype.getTypeRefdLast(timestamp);
}
if (itype == null || !(itype instanceof Integer_Type)) {
return;
}
// count number of cases in select, get used integer type case-items
final CaseVisitorInteger caseVisitorInteger = new CaseVisitorInteger();
scs.accept(caseVisitorInteger);
if (caseVisitorInteger.containsUnfoldable()) {
return;
}
final List<Long> usedIntegerItems = caseVisitorInteger.getItemsUsed();
if (!checkIfIntegerCasesSorted(usedIntegerItems)) {
problems.report(s.getLocation(), ERR_MSG);
}
}
Aggregations