Search in sources :

Example 36 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class SelectionFinder method createDebugInfo.

private String createDebugInfo() {
    final StringBuilder sb = new StringBuilder();
    sb.append("ExtractToFunctionRefactoring->SelectionFinder debug info: \n");
    sb.append("  Runs on reference: ");
    sb.append(runsOnRef == null ? "null" : runsOnRef.getId());
    sb.append(", enclosing function: ");
    if (parentFunc == null) {
        sb.append("null");
    } else if (parentFunc instanceof Definition) {
        sb.append(((Definition) parentFunc).getIdentifier());
    } else if (parentFunc instanceof ControlPart) {
        sb.append("<controlpart>");
    } else {
        sb.append("<invalid: ").append(parentFunc).append('>');
    }
    sb.append('\n');
    sb.append("  Return clause: ");
    sb.append(returnType == null ? "null" : returnType.getIdentifier());
    sb.append("  Warnings: ");
    for (RefactoringStatusEntry rse : warnings) {
        sb.append("severity: " + rse.getSeverity() + "; msg: " + rse.getMessage());
        sb.append('\n');
    }
    return sb.toString();
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) ControlPart(org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart)

Example 37 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method analyzeFunction.

/**
 * Analyze a function or testcase
 */
private List<Edit> analyzeFunction(final Definition def) {
    if (!(def instanceof Def_Function || def instanceof Def_Testcase)) {
        ErrorReporter.logError("ChangeCreator.analyzeFunction(): def must be a Def_Function or a Def_Testcase! def type: " + def.getClass());
        return null;
    }
    final FunctionAnalyzer vis = new FunctionAnalyzer();
    def.accept(vis);
    final Environment env = vis.getResult();
    final List<Edit> eds = env.refactor();
    return eds;
}
Also used : Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Environment(org.eclipse.titanium.refactoring.scope.nodes.Environment) 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) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 38 with Definition

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

Example 39 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class MinimizeScopeActionFromEditor method findSelection.

private Definition findSelection() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    TTCN3Editor targetEditor;
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return null;
    } else {
        targetEditor = (TTCN3Editor) editor;
    }
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final TextSelection textSelection = extractSelection(selectionService.getSelection());
    // iterating through part of the module
    final IResource selectedRes = extractResource(targetEditor);
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("SelectionFinder.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return null;
    }
    final IFile selectedFile = (IFile) selectedRes;
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(selectedFile.getProject());
    final Module selectedModule = projectSourceParser.containedModule(selectedFile);
    // getting current selection nodes
    final int selectionOffset = textSelection.getOffset() + textSelection.getLength();
    final SelectionFinderVisitor selVisitor = new SelectionFinderVisitor(selectionOffset);
    selectedModule.accept(selVisitor);
    final Definition selectedDef = selVisitor.getSelection();
    if (selectedDef == null) {
        ErrorReporter.logWarning("SelectionFinder.findSelection(): Visitor did not find a definition in the selection.");
        statusLineManager.setErrorMessage(ERR_MSG_NO_SELECTION);
        return null;
    }
    return selectedDef;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) Module(org.eclipse.titan.designer.AST.Module) IResource(org.eclipse.core.resources.IResource) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 40 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class DependencyCollector method collectDependencies.

private void collectDependencies(final Definition start, final Set<ILocateableNode> allDefs, final Set<IResource> imports, final Set<IResource> asnFiles) {
    Set<Definition> currDefs;
    Set<Definition> prevDefs = new HashSet<Definition>();
    prevDefs.add(start);
    // TODO containsAll(): is this ok for sure?
    while (!(allDefs.containsAll(prevDefs))) {
        currDefs = new HashSet<Definition>();
        allDefs.addAll(prevDefs);
        for (Definition d : prevDefs) {
            final DependencyFinderVisitor vis = new DependencyFinderVisitor(currDefs, imports, asnFiles);
            d.accept(vis);
        }
        prevDefs = currDefs;
    }
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) HashSet(java.util.HashSet)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)52 Assignment (org.eclipse.titan.designer.AST.Assignment)16 IValue (org.eclipse.titan.designer.AST.IValue)12 Location (org.eclipse.titan.designer.AST.Location)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)10 IType (org.eclipse.titan.designer.AST.IType)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 Module (org.eclipse.titan.designer.AST.Module)10 ArrayList (java.util.ArrayList)9 Reference (org.eclipse.titan.designer.AST.Reference)9 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)6 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)6 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)5 IFile (org.eclipse.core.resources.IFile)4 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)4