Search in sources :

Example 21 with Statement

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

the class StatementList method createDebugInfo.

public String createDebugInfo() {
    final StringBuilder sb = new StringBuilder();
    sb.append("ExtractToFunctionRefactoring->StatementList debug info:");
    sb.append("\n  Loc: ");
    if (location == null) {
        sb.append("null");
    } else {
        sb.append(location.getFile().getFullPath());
        sb.append(": ");
        sb.append(location.getOffset());
        sb.append("->");
        sb.append(location.getEndOffset());
    }
    sb.append("\n  MySB info: ");
    if (myStatementBlock == null || myStatementBlock.getMyDefinition() == null) {
        sb.append("null");
    } else {
        sb.append(myStatementBlock.getMyDefinition().getIdentifier());
    }
    sb.append("\n  Statements: ");
    if (statements == null) {
        sb.append("null");
    } else {
        sb.append("(count: ");
        sb.append(statements.size());
        sb.append(") \n");
        for (Statement s : statements) {
            sb.append("    ");
            sb.append(s.getStatementName());
            sb.append(", loc: ");
            if (s.getLocation() == null) {
                sb.append("null");
            } else {
                sb.append(s.getLocation().getOffset());
                sb.append("->");
                sb.append(s.getLocation().getEndOffset());
                sb.append(" in line ");
                sb.append(s.getLocation().getLine());
            }
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement)

Example 22 with Statement

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

the class IfContext method process_internal.

protected void process_internal() {
    final If_Statement st = getNode();
    final If_Clauses ics = st.getIfClauses();
    final Context child = getChild();
    if (child != null && child.getNode().equals(ics)) {
        // the log statement is in one of the conditional clauses
        final List<If_Clause> icl = ics.getClauses();
        final Context clauseContext = child.getChild();
        if (clauseContext != null && icl.contains(clauseContext.getNode())) {
            final IVisitableNode ic = clauseContext.getNode();
            final ClauseVisitor vis = new ClauseVisitor();
            ic.accept(vis);
            final List<Reference> refs = vis.getResult();
            for (Reference ref : refs) {
                varNamesInConditions.add(ref.getDisplayName());
            }
        }
    } else {
        // the log statement is in the else block
        final List<Reference> refs = extractAllIdsFromClauses(ics);
        for (Reference ref : refs) {
            varNamesInConditions.add(ref.getDisplayName());
        }
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) If_Clauses(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clauses) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 23 with Statement

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

the class IfInsteadAltguard method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof AltGuard) {
        final AltGuard ag = (AltGuard) node;
        final StatementBlock statements = ag.getStatementBlock();
        if (statements != null && !statements.isEmpty()) {
            final Statement firstStatement = statements.getStatementByIndex(0);
            if (firstStatement instanceof If_Statement) {
                final Value condition = ((If_Statement) firstStatement).getIfClauses().getClauses().get(0).getExpression();
                Location reportAt;
                if (condition != null) {
                    reportAt = condition.getLocation();
                } else {
                    reportAt = firstStatement.getLocation();
                }
                problems.report(reportAt, MIGHT_ALTGUARD);
            }
        }
    }
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Value(org.eclipse.titan.designer.AST.Value) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 24 with Statement

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

the class ContainsRef 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 SuspiciouslyUsedIf susp = new SuspiciouslyUsedIf(receive);
            ag.accept(susp);
            if (susp.doesSmell()) {
                problems.report(susp.getSuspicious().getLocation(), SHOULD_BRANCH);
            }
        }
    }
}
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) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard)

Example 25 with Statement

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

the class ChangeCreator method createFileChange.

/**
 * Creates the {@link #change} object, which contains all the inserted and edited texts
 * in the selected resources.
 */
private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    // 
    // collect functions
    Set<Definition> funcs;
    final FunctionCollector vis = new FunctionCollector();
    if (defSelection == null) {
        module.accept(vis);
        funcs = vis.getResult();
    } else {
        if (defSelection instanceof Def_Function || defSelection instanceof Def_Testcase) {
            // TODO any other possibilities for the type of 'defSelection'?
            funcs = new HashSet<Definition>();
            funcs.add(defSelection);
        } else {
            ErrorReporter.logError("Variable scope reduction called for " + defSelection.getIdentifier().getDisplayName() + ", but it is only supported for functions and testcases. ");
            return null;
        }
    }
    // create edits
    final List<Edit> allEdits = new ArrayList<Edit>();
    for (Definition def : funcs) {
        final List<Edit> edits = analyzeFunction(def);
        if (edits == null) {
            continue;
        }
        allEdits.addAll(edits);
    }
    if (allEdits.isEmpty()) {
        return null;
    }
    final String fileContents = loadFileContent(toVisit);
    // create text edits
    // 
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    // TODO this is an O(n^2) algorithm
    // merge overlapping DeleteEdits
    // used, when removing all parts of a multi-declaration statement:
    // the DeleteEdit for removing the last part covers all the DeleteEdits for the other parts
    // WARNING merging edits might make debugging more difficult, since the overlapping edit errors are avoided
    final List<TextEdit> allTes = new LinkedList<TextEdit>();
    // collect processed (insert) edits with their created insert edit
    final Map<Edit, InsertEdit> editsDone = new HashMap<Edit, InsertEdit>();
    for (Edit e : allEdits) {
        final TextEdit[] tes = createTextEdit(toVisit, fileContents, e, editsDone);
        for (TextEdit te : tes) {
            if (!(te instanceof DeleteEdit)) {
                allTes.add(te);
                // System.err.println("$ nonde added: " + te.getOffset() + "-" + te.getExclusiveEnd());
                continue;
            }
            DeleteEdit dte = (DeleteEdit) te;
            final ListIterator<TextEdit> it = allTes.listIterator();
            while (it.hasNext()) {
                final TextEdit currTe = it.next();
                if (!(currTe instanceof DeleteEdit)) {
                    continue;
                }
                final DeleteEdit currDte = (DeleteEdit) currTe;
                // if the new edit (dte) overlaps currDte, merge them
                if (doesDeleteEditsOverlap(dte, currDte)) {
                    // System.err.println("$ de removed: " + currDte.getOffset() + "-" + currDte.getExclusiveEnd());
                    it.remove();
                    dte = mergeDeleteEdits(dte, currDte);
                // System.err.println("$ merged des: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
                }
            }
            // System.err.println("$ de added: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
            allTes.add(dte);
        }
    }
    Collections.reverse(allTes);
    for (TextEdit te : allTes) {
        rootEdit.addChild(te);
    }
    return tfc;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) HashMap(java.util.HashMap) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) Edit(org.eclipse.titanium.refactoring.scope.nodes.Edit) InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DeleteEdit(org.eclipse.text.edits.DeleteEdit) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) LinkedList(java.util.LinkedList) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

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