Search in sources :

Example 11 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class VerdictWithoutReason method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Setverdict_Statement)) {
        return;
    }
    final Setverdict_Statement s = (Setverdict_Statement) node;
    final Value verdictValue = s.getVerdictValue();
    if (verdictValue == null) {
        return;
    }
    final CompilationTimeStamp ct = CompilationTimeStamp.getBaseTimestamp();
    final Type_type temp = verdictValue.getExpressionReturntype(ct, Expected_Value_type.EXPECTED_TEMPLATE);
    if (Type_type.TYPE_VERDICT != temp) {
        return;
    }
    final LogArguments verdictReason = s.getVerdictReason();
    if (Value_type.VERDICT_VALUE.equals(verdictValue.getValuetype()) && !Verdict_type.PASS.equals(((Verdict_Value) verdictValue).getValue()) && verdictReason == null) {
        final String msg = MessageFormat.format(WITHOUT_REASON, ((Verdict_Value) verdictValue).getValue());
        problems.report(s.getLocation(), msg);
    }
}
Also used : LogArguments(org.eclipse.titan.designer.AST.TTCN3.statements.LogArguments) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Value(org.eclipse.titan.designer.AST.Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 12 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp in project titan.EclipsePlug-ins by eclipse.

the class UnnecessaryValueof method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof ValueofExpression) {
        final ValueofExpression exp = (ValueofExpression) node;
        final CompilationTimeStamp stamp = CompilationTimeStamp.getBaseTimestamp();
        if (exp.getIsErroneous(stamp) || exp.isUnfoldable(stamp, null)) {
            return;
        }
        final TemplateInstance inst = exp.getTemplateInstance();
        if (inst != null && inst.getDerivedReference() == null && inst.getTemplateBody().isValue(stamp)) {
            final String msg = MessageFormat.format(TEXT, inst.getTemplateBody().getValue().createStringRepresentation());
            problems.report(exp.getLocation(), msg);
        }
    }
}
Also used : CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ValueofExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ValueofExpression) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 13 with CompilationTimeStamp

use of org.eclipse.titan.designer.parsers.CompilationTimeStamp 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

CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)13 IType (org.eclipse.titan.designer.AST.IType)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 Module (org.eclipse.titan.designer.AST.Module)3 Type (org.eclipse.titan.designer.AST.Type)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Location (org.eclipse.titan.designer.AST.Location)2 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)2 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)2 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)2 Value (org.eclipse.titan.designer.AST.Value)2 HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1