Search in sources :

Example 66 with Location

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

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final List<FormalParameter> fparamlist, final IFile file, final List<Location> locations_out) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("LazyficationRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            for (FormalParameter fparam : fparamlist) {
                System.out.println("reading: " + file.getName());
                Location typeloc = fparam.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
                locations_out.add(0, new Location(fparam.getLocation().getFile(), fparam.getLocation().getLine(), typeloc.getOffset(), typeloc.getOffset()));
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Location(org.eclipse.titan.designer.AST.Location)

Example 67 with Location

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

the class ChangeCreator method performOnSelectionOnly.

private void performOnSelectionOnly(final Module module) {
    final Location selLoc = new Location(file, textSelection.getStartLine(), textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
    final SelectionVisitor vis = new SelectionVisitor(selLoc);
    module.accept(vis);
    final Map<Log_Statement, Context> res = vis.getResult();
    final MultiTextEdit rootEdit = new MultiTextEdit();
    for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
        final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
        if (edit != null) {
            rootEdit.addChild(edit);
        }
    }
    if (rootEdit.hasChildren()) {
        change = new TextFileChange("Context logging", file);
        change.setEdit(rootEdit);
    }
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) Map(java.util.Map) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Location(org.eclipse.titan.designer.AST.Location)

Example 68 with Location

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

the class SelectionFinder method performHeadless.

void performHeadless(final IFile selFile, final ITextSelection textSel) {
    selectedFile = selFile;
    final String fileContents = readFileContents(selFile);
    if (fileContents == null) {
        ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): selFile does not exist at: " + selFile.getFullPath());
        return;
    }
    final IDocument doc = new Document(fileContents);
    textSelection = new TextSelection(doc, textSel.getOffset(), textSel.getLength());
    // 
    project = selFile.getProject();
    sourceParser = GlobalParser.getProjectSourceParser(project);
    selectedModule = sourceParser.containedModule(selectedFile);
    if (selectedModule == null) {
        ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): The module in the file " + selectedFile.getName() + " has no name.");
        return;
    }
    // iterating through the module for the selected statements
    final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
    selectedModule.accept(selectionVisitor);
    selectedStatements = selectionVisitor.createStatementList(textSelection);
    if (selectedStatements.isEmpty()) {
        ErrorReporter.logError(ERR_MSG_NO_SELECTION);
        return;
    }
    if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
        ErrorReporter.logError(selectedStatements.createDebugInfo());
        ErrorReporter.logError(createDebugInfo());
    }
    // finding return type & runs on clause
    final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
    selectedModule.accept(runsonVisitor);
    runsOnRef = runsonVisitor.getRunsOnRef();
    parentFunc = runsonVisitor.getFuncDef();
    // finding insert location
    if (parentFunc instanceof Definition) {
        insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
    } else if (parentFunc instanceof ControlPart) {
        final ControlPart cp = (ControlPart) parentFunc;
        final Location commentLoc = cp.getCommentLocation();
        insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
    }
    // 
    final ReturnVisitor retVis = new ReturnVisitor();
    selectedStatements.accept(retVis);
    returnCertainty = retVis.getCertainty();
    if (retVis.getCertainty() != ReturnCertainty.NO) {
        returnType = runsonVisitor.getReturnType();
    }
    // checking erroneousness of selection
    checkErroneousGoto();
    if (containsBreakWithoutLoop()) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
    }
    if (containsContinueWithoutLoop()) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
    }
    if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
    }
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) 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) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) Location(org.eclipse.titan.designer.AST.Location)

Example 69 with Location

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

the class SelectionFinder method perform.

void perform() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return;
    }
    final TTCN3Editor targetEditor = (TTCN3Editor) editor;
    statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    textSelection = extractSelection(selectionService.getSelection());
    if (textSelection == null) {
        ErrorReporter.logError("No valid statements were found in the selection.");
        ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
        return;
    }
    // getting selected module
    final IResource selectedRes = extractResource(targetEditor);
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return;
    }
    selectedFile = (IFile) selectedRes;
    project = selectedFile.getProject();
    sourceParser = GlobalParser.getProjectSourceParser(project);
    selectedModule = sourceParser.containedModule(selectedFile);
    // iterating through the module for the selected statements
    final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
    selectedModule.accept(selectionVisitor);
    selectedStatements = selectionVisitor.createStatementList(textSelection);
    if (selectedStatements.isEmpty()) {
        ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
        return;
    }
    if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
        ErrorReporter.logError(selectedStatements.createDebugInfo());
        ErrorReporter.logError(createDebugInfo());
    }
    // finding return type & runs on clause
    final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
    selectedModule.accept(runsonVisitor);
    runsOnRef = runsonVisitor.getRunsOnRef();
    parentFunc = runsonVisitor.getFuncDef();
    // finding insert location
    if (parentFunc instanceof Definition) {
        insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
    } else if (parentFunc instanceof ControlPart) {
        final ControlPart cp = (ControlPart) parentFunc;
        final Location commentLoc = cp.getCommentLocation();
        insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
    }
    // 
    final ReturnVisitor retVis = new ReturnVisitor();
    selectedStatements.accept(retVis);
    returnCertainty = retVis.getCertainty();
    if (retVis.getCertainty() != ReturnCertainty.NO) {
        returnType = runsonVisitor.getReturnType();
    }
    // checking erroneousness of selection
    checkErroneousGoto();
    if (containsBreakWithoutLoop()) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
    }
    if (containsContinueWithoutLoop()) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
    }
    if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
        warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
    }
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) ISelectionService(org.eclipse.ui.ISelectionService) ControlPart(org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart) IEditorPart(org.eclipse.ui.IEditorPart) IResource(org.eclipse.core.resources.IResource) Location(org.eclipse.titan.designer.AST.Location)

Example 70 with Location

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

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            for (ILocateableNode node : nodes) {
                int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
                if (node instanceof Def_Type) {
                    Def_Type df = (Def_Type) node;
                    Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
                    if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
                        vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
                    }
                } else if (node instanceof Sequence_Value) {
                    Sequence_Value sv = (Sequence_Value) node;
                    vmLen += 6;
                    final Location nodeLocation = node.getLocation();
                    if (settings.getPosition() < sv.getNofComponents()) {
                        final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                    } else {
                        int max = sv.getNofComponents();
                        final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                    }
                } else if (node instanceof TTCN3Template) {
                    TTCN3Template template = (TTCN3Template) node;
                    vmLen += 6;
                    if (template instanceof Named_Template_List) {
                        Named_Template_List ntl = (Named_Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < ntl.getNofTemplates()) {
                            final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                        } else {
                            int max = ntl.getNofTemplates();
                            final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                        }
                    } else if (template instanceof Template_List) {
                        Template_List tl = (Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < tl.getNofTemplates()) {
                            final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
                        } else {
                            int max = tl.getNofTemplates();
                            final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
                        }
                    }
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) InsertEdit(org.eclipse.text.edits.InsertEdit) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7