Search in sources :

Example 41 with Statement

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

the class SuperfluousTemplate method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Operation_Altguard) {
        final Operation_Altguard ag = (Operation_Altguard) node;
        final Statement action = ag.getGuardStatement();
        if (action instanceof Receive_Port_Statement) {
            final Receive_Port_Statement receive = (Receive_Port_Statement) action;
            final SuperfluousTemplate st = new SuperfluousTemplate(receive);
            receive.accept(st);
            if (st.canReceiveAny() && st.hasValueRedirect()) {
                if (st.getReceivable() == null) {
                    problems.report(receive.getLocation(), CAN_RECEIVE_ANY_OF_MULTIPLE);
                } else {
                    problems.report(receive.getLocation(), CAN_RECEIVE_ANY_OF_ONE);
                }
            }
        }
    }
}
Also used : Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard)

Example 42 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement 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)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)13 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IValue (org.eclipse.titan.designer.AST.IValue)11 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)11 Reference (org.eclipse.titan.designer.AST.Reference)10 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Location (org.eclipse.titan.designer.AST.Location)6 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Module (org.eclipse.titan.designer.AST.Module)5 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)4 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)4 Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)4 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)4 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)4 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3