Search in sources :

Example 21 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor 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 22 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class InsertFieldActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("InsertField");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // getting selected file
    final IFile selectedFile = Utils.getSelectedFileInEditor("InsertField");
    if (selectedFile == null) {
        return null;
    }
    final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
    final InsertFieldRefactoring refactoring = new InsertFieldRefactoring(structSelection, null);
    // open wizard
    final InsertFieldWizard wiz = new InsertFieldWizard(refactoring, refactoring.getSelection());
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("InsertFieldActionFromEditor: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    // update AST again
    Activator.getDefault().resumeHandlingResourceChanges();
    final IProject project = selectedFile.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject)

Example 23 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class UngroupModuleparActionFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // update AST
    Utils.updateASTForProjectActiveInEditor("UngroupModulepar");
    Activator.getDefault().pauseHandlingResourceChanges();
    // getting the active editor
    final TTCN3Editor targetEditor = Utils.getActiveEditor();
    if (targetEditor == null) {
        return null;
    }
    // getting selected file
    final IFile selectedFile = Utils.getSelectedFileInEditor("UngroupModulepar");
    if (selectedFile == null) {
        return null;
    }
    final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
    final UngroupModuleparRefactoring refactoring = new UngroupModuleparRefactoring(structSelection);
    // open wizard
    final UngroupModuleparWizard wiz = new UngroupModuleparWizard(refactoring);
    final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
    // operation was cancelled
    } catch (Exception e) {
        ErrorReporter.logError("UngroupModuleparActionFromEditor: Error while performing refactoring change! ");
        ErrorReporter.logExceptionStackTrace(e);
    }
    // update AST again
    Activator.getDefault().resumeHandlingResourceChanges();
    final IProject project = selectedFile.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject)

Example 24 with TTCN3Editor

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.

the class OrganizeFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof TTCN3Editor || editor instanceof TTCNPPEditor)) {
        ErrorReporter.logError("The editor is not found or not a Titan TTCN-3 editor");
        return null;
    }
    final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    TextFileChange change = null;
    try {
        change = OrganizeImports.organizeImportsChange(file);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("Error while creating the needed import changes", e);
        return null;
    }
    try {
        change.perform(new NullProgressMonitor());
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("Error while performing the needed import changes", e);
    }
    final IProject project = file.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(file);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IEditorPart(org.eclipse.ui.IEditorPart) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) IProject(org.eclipse.core.resources.IProject)

Aggregations

TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)24 IProject (org.eclipse.core.resources.IProject)15 IFile (org.eclipse.core.resources.IFile)14 ExecutionException (org.eclipse.core.commands.ExecutionException)13 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 TextSelection (org.eclipse.jface.text.TextSelection)7 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)5 IResource (org.eclipse.core.resources.IResource)4 Module (org.eclipse.titan.designer.AST.Module)4 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)4 ISelectionService (org.eclipse.ui.ISelectionService)4 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)2 Reconciler (org.eclipse.titan.designer.editors.ttcn3editor.Reconciler)2 HashSet (java.util.HashSet)1