@Override ISelection makeReplaceSelection(ISelection selection, String replacement) { ITextSelection ts= (ITextSelection)selection; return new TextSelection(fDocument, ts.getOffset() + replacement.length(), 0); } };
@Override public void selectionChanged(IEditorPart part, ITextSelection selection, CompilationUnit astRoot) { doSelectionChanged(selection.getOffset(), selection.getLength(), astRoot); } };
@Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection= event.getSelection(); if (selection instanceof ITextSelection) { ITextSelection ts= (ITextSelection) selection; int offset= ts.getOffset(); setSelectedRevision(fPainter.getRevision(offset)); } }
public static IJavaElement[] codeResolve(IJavaElement input, ITextSelection selection) throws JavaModelException { if (input instanceof ICodeAssist) { if (input instanceof ICompilationUnit) { JavaModelUtil.reconcile((ICompilationUnit) input); } IJavaElement[] elements= ((ICodeAssist)input).codeSelect(selection.getOffset() + selection.getLength(), 0); if (elements.length > 0) { return elements; } } return EMPTY_RESULT; }
public void run(ITextSelection selection) { try{ run(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); } catch (JavaModelException e){ ExceptionHandler.handle(e, RefactoringMessages.ConvertAnonymousToNestedAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); } }
private ILineRange getLineRange(IDocument document, ITextSelection selection) throws BadLocationException { final int offset= selection.getOffset(); int startLine= document.getLineOfOffset(offset); int endOffset= offset + selection.getLength(); int endLine= document.getLineOfOffset(endOffset); final int nLines= endLine - startLine + 1; return new LineRange(startLine, nLines); }
/** * Determines the current prefix that should be used for completion. */ private String getCurrentPrefix() { if (currentPrefix != null) { return currentPrefix; } ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection(); IDocument doc = viewer.getDocument(); return getPrefixFromDocument(doc.get(), selection.getOffset() + selection.getLength()).toLowerCase(); }
@Override protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) { super.openEditor(editorDescriptor, openUsingDescriptor); ISelection selection= getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { revealInEditor(page.getActiveEditor(), ((ITextSelection)selection).getOffset(), ((ITextSelection)selection).getLength()); } } });
public void run(ITextSelection selection) { if (!ActionUtil.isEditable(fEditor)) return; try{ ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(fEditor); RefactoringExecutionStarter.startIntroduceParameter(unit, selection.getOffset(), selection.getLength(), getShell()); } catch (CoreException e){ ExceptionHandler.handle(e, RefactoringMessages.IntroduceParameterAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); } } }
protected IDocumentRange getRangeElement(ITextSelection selection) { if (selection.isEmpty()) return null; IBuildModel model = (IBuildModel) getInputContext().getModel(); return findBuildNode(model.getBuild().getBuildEntries(), selection.getOffset()); }
@Override public void run(ITextSelection selection) { if (!ActionUtil.isEditable(fEditor)) return; ExtractConstantRefactoring refactoring= new ExtractConstantRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); new RefactoringStarter().activate(new ExtractConstantWizard(refactoring), getShell(), RefactoringMessages.ExtractConstantAction_extract_constant, RefactoringSaveHelper.SAVE_NOTHING); } }
@Override public void run(ITextSelection selection) { if (!checkEnabled(selection)) return; IRegion region= new Region(selection.getOffset(), selection.getLength()); PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); detector.setContext(fEditor); IHyperlink[]hyperlinks= detector.detectHyperlinks(fEditor.internalGetSourceViewer(), region, false); if (hyperlinks != null && hyperlinks.length == 1) hyperlinks[0].open(); } }
@Override public final void run() { ITextSelection selection= getTextSelection(); ISourceRange newRange= getNewSelectionRange(createSourceRange(selection), null); // Check if new selection differs from current selection if (selection.getOffset() == newRange.getOffset() && selection.getLength() == newRange.getLength()) return; fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength()); }
public void run(ITextSelection selection) { if (!ActionUtil.isEditable(fEditor)) return; try{ final ExtractTempRefactoring refactoring= new ExtractTempRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); new RefactoringStarter().activate(refactoring, new ExtractTempWizard(refactoring), getShell(), RefactoringMessages.ExtractTempAction_extract_temp, RefactoringSaveHelper.SAVE_NOTHING); } catch (JavaModelException e){ ExceptionHandler.handle(e, RefactoringMessages.ExtractTempAction_extract_temp, RefactoringMessages.NewTextRefactoringAction_exception); } } }
public final void run() { ITextSelection selection= getTextSelection(); ISourceRange newRange= getNewSelectionRange(createSourceRange(selection), null); // Check if new selection differs from current selection if (selection.getOffset() == newRange.getOffset() && selection.getLength() == newRange.getLength()) return; fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength()); }
private ISelection getEditorSelection(JavaEditor editor) { ITypeRoot element= SelectionConverter.getInput(editor); if (element == null) return null; if (editor.isBreadcrumbActive()) return editor.getBreadcrumb().getSelectionProvider().getSelection(); else { ITextSelection textSelection= (ITextSelection) editor.getSelectionProvider().getSelection(); IDocument document= JavaUI.getDocumentProvider().getDocument(editor.getEditorInput()); return new JavaTextSelection(element, document, textSelection.getOffset(), textSelection.getLength()); } }