Search in sources :

Example 1 with ILocateableNode

use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method insertField.

public int insertField(final TTCN3_Set_Seq_Choice_BaseType ss, final ILocateableNode node, final MultiTextEdit rootEdit, int vmLen) {
    final Location nodeLocation = node.getLocation();
    final int noc = ss.getNofComponents();
    if (settings.getPosition() < noc) {
        vmLen += 6;
        final ILocateableNode cf = (ILocateableNode) ss.getComponentByIndex(settings.getPosition());
        final Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), cf.getLocation().getOffset(), cf.getLocation().getEndOffset() + vmLen);
        rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getType() + " " + settings.getId().getTtcnName() + ", \n  "));
    } else {
        vmLen += 5;
        final ILocateableNode cf = (ILocateableNode) ss.getComponentByIndex(noc - 1);
        final Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), cf.getLocation().getEndOffset(), cf.getLocation().getEndOffset() + vmLen);
        rootEdit.addChild(new InsertEdit(l.getOffset() - 1, ",\n  " + settings.getType() + " " + settings.getId().getTtcnName()));
    }
    return vmLen;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) Location(org.eclipse.titan.designer.AST.Location)

Example 2 with ILocateableNode

use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

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;
    }
    if (selection instanceof Def_Type) {
        final Def_Type df = (Def_Type) selection;
        type = df.getType(CompilationTimeStamp.getBaseTimestamp());
    }
    final DefinitionVisitor vis = new DefinitionVisitor(type);
    module.accept(vis);
    final NavigableSet<ILocateableNode> nodes = vis.getLocations();
    if (nodes.isEmpty()) {
        return null;
    }
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (!rootEdit.hasChildren()) {
        return null;
    }
    tfc.setEdit(rootEdit);
    return tfc;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CoreException(org.eclipse.core.runtime.CoreException) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Module(org.eclipse.titan.designer.AST.Module) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 3 with ILocateableNode

use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createTextEdit.

private TextEdit[] createTextEdit(final IFile toVisit, final String fileContent, final Edit e, final Map<Edit, InsertEdit> editsDone) {
    // check for multi-declaration statement
    if (e.declSt.isMultiDeclaration()) {
        final Location cutLoc = calculateMultiDeclarationCutLoc(fileContent, e.declSt);
        final String moveContent = calculateMultiDeclarationMoveContent(fileContent, e.declSt);
        // remove stmt from multi-declaration
        e.declSt.removeFromMultiDeclaration();
        // create remove edit
        final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
        final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
        // create insert edit
        InsertEdit insert = null;
        if (!e.isRemoveEdit()) {
            // update insert location if the insertionPoint stmt was moved
            int insertOffset = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation().getOffset();
            for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
                if (ed.getKey().declSt.equals(e.insertionPoint)) {
                    insertOffset = ed.getValue().getOffset();
                    break;
                }
            }
            // 
            insertOffset = findLineBeginningOffset(fileContent, insertOffset);
            insert = new InsertEdit(insertOffset, moveContent);
            editsDone.put(e, insert);
        }
        if (insert != null) {
            return new TextEdit[] { insert, cut };
        }
        return new TextEdit[] { cut };
    } else {
        // 
        final Location cutLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), true);
        InsertEdit insert = null;
        if (!e.isRemoveEdit()) {
            final Location copyLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), false);
            // update insert location if the insertionPoint stmt was moved
            final Location insPLoc = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation();
            int insertOffset = insPLoc.getOffset();
            for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
                if (ed.getKey().declSt.equals(e.insertionPoint)) {
                    insertOffset = ed.getValue().getOffset();
                    break;
                }
            }
            // 
            final int prefixStartOffset = findLineBeginningOffset(fileContent, insertOffset);
            final String insertText = fileContent.substring(copyLoc.getOffset(), copyLoc.getEndOffset()) + "\n";
            String insertPrefix = fileContent.substring(prefixStartOffset, insertOffset);
            // if prefix is not whitespace only, do not use the prefix
            if (!insertPrefix.trim().equals("")) {
                insertPrefix = "";
            }
            insert = new InsertEdit(prefixStartOffset, insertPrefix + insertText);
            editsDone.put(e, insert);
        }
        final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
        final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
        // System.err.println("DeleteEdit: " + fileContent.substring(cutLoc.getOffset(), cutLoc.getEndOffset()));
        if (insert != null) {
            return new TextEdit[] { insert, cut };
        }
        return new TextEdit[] { cut };
    }
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) 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) DeleteEdit(org.eclipse.text.edits.DeleteEdit) Map(java.util.Map) HashMap(java.util.HashMap) Location(org.eclipse.titan.designer.AST.Location)

Example 4 with ILocateableNode

use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.

the class StatementNode method toString.

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append("SN(").append(astNode.toString()).append("), loc: ");
    if (astNode instanceof ILocateableNode) {
        final Location loc = ((ILocateableNode) astNode).getLocation();
        sb.append(loc.getOffset()).append('-').append(loc.getEndOffset()).append(';');
    } else {
        sb.append("<none>;");
    }
    sb.append(" parent: ");
    if (parent == null) {
        sb.append("<null>; ");
    } else {
        sb.append("BN(").append(parent.astNode.toString()).append("); ");
    }
    if (moved) {
        sb.append("MOVED; ");
    }
    if (isDeclaration()) {
        sb.append("declaration: " + declaredVar);
    }
    return sb.toString();
}
Also used : ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) Location(org.eclipse.titan.designer.AST.Location)

Example 5 with ILocateableNode

use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.

the class FindDefinitionAction method doFindDefinition.

private void doFindDefinition() {
    final DefinitionListSelectionDialog dialog = new DefinitionListSelectionDialog(Display.getDefault().getActiveShell(), new DefinitionLabelProvider(), getCurrentProject());
    dialog.setTitle("Find Definition");
    dialog.setMessage("Type the name of a definition");
    dialog.setHelpAvailable(false);
    if (targetEditor instanceof TTCN3Editor) {
        selection = ((TTCN3Editor) targetEditor).getSelectionProvider().getSelection();
    }
    if (selection instanceof TextSelection && !selection.isEmpty()) {
        final IPreferencesService prefs = Platform.getPreferencesService();
        final boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        final TextSelection tSelection = (TextSelection) selection;
        dialog.setFilter(tSelection.getText());
    }
    dialog.init();
    if (dialog.open() == Window.CANCEL || dialog.getFirstResult() == null) {
        return;
    }
    final Object result = dialog.getFirstResult();
    if (!(result instanceof ILocateableNode)) {
        return;
    }
    showInEditor((ILocateableNode) result);
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) DefinitionListSelectionDialog(org.eclipse.titan.designer.finddefinition.DefinitionListSelectionDialog) TextSelection(org.eclipse.jface.text.TextSelection) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Aggregations

ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)11 Location (org.eclipse.titan.designer.AST.Location)8 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)5 InsertEdit (org.eclipse.text.edits.InsertEdit)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)3 Module (org.eclipse.titan.designer.AST.Module)3 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CoreException (org.eclipse.core.runtime.CoreException)2 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 IFile (org.eclipse.core.resources.IFile)1