Search in sources :

Example 31 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class ConsecutiveAssignments method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof StatementBlock)) {
        return;
    }
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    int count = 0;
    boolean limitReached = false;
    Location smellLoc = null;
    Assignment_Statement lastAs = null;
    Assignment toMatch = null;
    final StatementBlock sb = (StatementBlock) node;
    // iterate statements in block
    for (int i = 0; i < sb.getSize(); i++) {
        final Statement s = sb.getStatementByIndex(i);
        if (!(s instanceof Assignment_Statement)) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        final Assignment_Statement as = (Assignment_Statement) s;
        final Reference ref = as.getReference();
        final Assignment a = ref.getRefdAssignment(timestamp, false);
        if (a == null) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        // consecutive assignments: consecutive Assignment_Statements have the same definition
        if (toMatch == null) {
            toMatch = a;
        } else if (toMatch != a) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = a;
        }
        if (count == 0) {
            smellLoc = new Location(as.getLocation());
        }
        lastAs = as;
        count++;
        if (count >= minCountToMark) {
            limitReached = true;
        }
    }
    if (limitReached) {
        smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
        problems.report(smellLoc, ERROR_MESSAGE);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Reference(org.eclipse.titan.designer.AST.Reference) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 32 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class TMLinesOfCode method measure.

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

        @Override
        public int visit(final IVisitableNode node) {
            if (node instanceof Def_Testcase) {
                return V_CONTINUE;
            }
            if (node instanceof StatementBlock) {
                count.set(((LargeLocation) ((StatementBlock) node).getLocation()).getEndLine());
            }
            return V_SKIP;
        }
    });
    return count.val() - testcase.getLocation().getLine() + 1;
}
Also used : Counter(org.eclipse.titanium.metrics.visitors.Counter) LargeLocation(org.eclipse.titan.designer.AST.LargeLocation) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CounterVisitor(org.eclipse.titanium.metrics.visitors.CounterVisitor) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 33 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class AMLinesOfCode method measure.

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

        @Override
        public int visit(final IVisitableNode node) {
            if (node instanceof Def_Altstep) {
                return V_CONTINUE;
            }
            if (node instanceof StatementBlock) {
                count.set(((LargeLocation) ((StatementBlock) node).getLocation()).getEndLine());
            }
            return V_SKIP;
        }
    });
    return count.val() - altstep.getLocation().getLine() + 1;
}
Also used : Counter(org.eclipse.titanium.metrics.visitors.Counter) LargeLocation(org.eclipse.titan.designer.AST.LargeLocation) CounterVisitor(org.eclipse.titanium.metrics.visitors.CounterVisitor) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Aggregations

StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)21 IValue (org.eclipse.titan.designer.AST.IValue)11 Assignment (org.eclipse.titan.designer.AST.Assignment)8 Reference (org.eclipse.titan.designer.AST.Reference)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)7 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)6 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)5 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)5 Assignment_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement)4 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Location (org.eclipse.titan.designer.AST.Location)3 Module (org.eclipse.titan.designer.AST.Module)3 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)3 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)3 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)3 Map (java.util.Map)2