Search in sources :

Example 1 with SelectCase

use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase 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));
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 2 with SelectCase

use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase 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);
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Value(org.eclipse.titan.designer.AST.Value) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with SelectCase

use of org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase 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);
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)3 SelectCase (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase)3 SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)3 SelectCases (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases)3 Value (org.eclipse.titan.designer.AST.Value)3 IValue (org.eclipse.titan.designer.AST.IValue)2 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)1 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)1 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)1 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)1 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)1