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