@Override public void run(ITextSelection currentSelection) { if (currentSelection != null && editor != null) { GroovyCompilationUnit unit = editor.getGroovyCompilationUnit(); if (unit != null) { ModuleNode node = unit.getModuleNode(); if (node != null) { FindSurroundingNode finder = new FindSurroundingNode( new Region(currentSelection.getOffset(), currentSelection.getLength())); IASTFragment result = finder.doVisitSurroundingNode(node); if (result != null) { TextSelection newSelection = new TextSelection(result.getStart(), result.getLength()); if (!newSelection.equals(currentSelection)) { history.remember( new SourceRange(currentSelection.getOffset(), currentSelection.getLength())); try { history.ignoreSelectionChanges(); editor.selectAndReveal(result.getStart(), result.getLength()); } finally { history.listenToSelectionChanges(); } } editor.getSelectionProvider().setSelection(newSelection); } } } } }
/* (non-Javadoc) * Method declared on SelectionDispatchAction. */ @Override public void run(ITextSelection selection) { IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); if (doc != null && unit != null) { DefaultGroovyFormatter formatter = new DefaultGroovyFormatter( selection, doc, new FormatterPreferences(unit), kind == FormatKind.INDENT_ONLY); TextEdit edit = formatter.format(); try { unit.applyTextEdit(edit, new NullProgressMonitor()); } catch (MalformedTreeException e) { GroovyCore.logException("Exception when formatting", e); } catch (JavaModelException e) { GroovyCore.logException("Exception when formatting", e); } } }
@Override public void run(ITextSelection selection) { if (!ActionUtil.isEditable(fEditor)) return; ConvertGroovyLocalToFieldRefactoring refactoring = new ConvertGroovyLocalToFieldRefactoring( fEditor.getGroovyCompilationUnit(), selection.getOffset(), selection.getLength()); new RefactoringStarter() .activate( new PromoteTempWizard(refactoring), getShell(), RefactoringMessages.ConvertLocalToField_title, RefactoringSaveHelper.SAVE_NOTHING); }
public ExpandSelectionAction(GroovyEditor editor, SelectionHistory history) { super(editor.getEditorSite()); this.editor = editor; this.history = history; setText("Enclosing Element"); }