Java Code Examples for org.eclipse.jface.text.IRegion#equals()
The following examples show how to use
org.eclipse.jface.text.IRegion#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopeSelectionAction.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public void perform(IDocument doc, ICoreTextSelection selection, BaseEditor editor) { FastStack<IRegion> cache = getCache(editor); Region initialRegion = new Region(selection.getOffset(), selection.getLength()); if (cache.size() > 0) { IRegion peek = cache.peek(); if (!peek.equals(initialRegion)) { cache.clear(); } } if (cache.size() == 0) { cache.push(initialRegion); } ICoreTextSelection newSelection = getNewSelection(doc, selection, editor); if (initialRegion.equals(new Region(newSelection.getOffset(), newSelection.getLength()))) { return; } editor.setSelection(newSelection.getOffset(), newSelection.getLength()); cache.push(new Region(newSelection.getOffset(), newSelection.getLength())); }
Example 2
Source File: ScopeSelectionAction.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public void deselect(BaseEditor editor) { FastStack<IRegion> stack = ScopeSelectionAction.getCache(editor); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); Region region = new Region(selection.getOffset(), selection.getLength()); Iterator<IRegion> it = stack.topDownIterator(); while (it.hasNext()) { IRegion iRegion = it.next(); stack.pop(); //After getting the latest, pop it. if (iRegion.equals(region)) { if (stack.size() > 0) { IRegion peek = stack.peek(); editor.setSelection(peek.getOffset(), peek.getLength()); } break; } } }
Example 3
Source File: RenameAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static IRegion getCorrespondingEditChangeRange(SearchMatch searchResult, TextChangeManager manager) { TextChange change= getTextChange(searchResult, manager); if (change == null) { return null; } IRegion oldMatchRange= createTextRange(searchResult); TextEditChangeGroup[] editChanges= change.getTextEditChangeGroups(); for (int i= 0; i < editChanges.length; i++) { if (oldMatchRange.equals(editChanges[i].getRegion())) { return TextEdit.getCoverage(change.getPreviewEdits(editChanges[i].getTextEdits())); } } return null; }
Example 4
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IRegion getCorrespondingEditChangeRange(SearchMatch searchResult, TextChangeManager manager) { TextChange change= getTextChange(searchResult, manager); if (change == null) return null; IRegion oldMatchRange= createTextRange(searchResult); TextEditChangeGroup[] editChanges= change.getTextEditChangeGroups(); for (int i= 0; i < editChanges.length; i++) { if (oldMatchRange.equals(editChanges[i].getRegion())) return TextEdit.getCoverage(change.getPreviewEdits(editChanges[i].getTextEdits())); } return null; }
Example 5
Source File: BufferLocal.java From e4macs with Eclipse Public License 1.0 | 5 votes |
public void handleDeactivate(IEditorPart epart) { if (hasVariable(epart, NARROW_REGION)) { ITextEditor editor = (ITextEditor)epart; IRegion region = (IRegion)get(editor, NARROW_REGION); IRegion cregion = editor.getHighlightRange(); if (!region.equals(cregion)) { set(editor,NARROW_REGION,cregion); } } }
Example 6
Source File: BufferLocal.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private void handleNarrowActivate(ITextEditor editor) { IRegion region = (IRegion)get(editor, NARROW_REGION); if (region != null) { IRegion cregion = editor.getHighlightRange(); if (!region.equals(cregion)) { // if (java) global flag is set, and used from outline // permit the new range to override the narrowed range region = cregion; } // narrow to selection editor.resetHighlightRange(); editor.showHighlightRangeOnly(true); editor.setHighlightRange(region.getOffset(), region.getLength(), true); } }
Example 7
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Jumps to the matching bracket. */ public void gotoMatchingBracket() { ISourceViewer sourceViewer= getSourceViewer(); IDocument document= sourceViewer.getDocument(); if (document == null) return; IRegion selection= getSignedSelection(sourceViewer); if (fPreviousSelections == null) initializePreviousSelectionList(); IRegion region= fBracketMatcher.match(document, selection.getOffset(), selection.getLength()); if (region == null) { region= fBracketMatcher.findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength()); initializePreviousSelectionList(); fPreviousSelections.add(selection); } else { if (fPreviousSelections.size() == 2) { if (!selection.equals(fPreviousSelections.get(1))) { initializePreviousSelectionList(); } } else if (fPreviousSelections.size() == 3) { if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) { IRegion originalSelection= fPreviousSelections.get(0); sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength()); sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength()); initializePreviousSelectionList(); return; } initializePreviousSelectionList(); } } if (region == null) { setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_noMatchingBracket); sourceViewer.getTextWidget().getDisplay().beep(); return; } int offset= region.getOffset(); int length= region.getLength(); if (length < 1) return; int anchor= fBracketMatcher.getAnchor(); // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1; boolean visible= false; if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) sourceViewer; visible= (extension.modelOffset2WidgetOffset(targetOffset) > -1); } else { IRegion visibleRegion= sourceViewer.getVisibleRegion(); // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 visible= (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength()); } if (!visible) { setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement); sourceViewer.getTextWidget().getDisplay().beep(); return; } int adjustment= getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength()); targetOffset+= adjustment; int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1); if (fPreviousSelections.size() == 1 && direction < 0) { targetOffset++; } if (fPreviousSelections.size() > 0) { fPreviousSelections.add(new Region(targetOffset, direction)); } sourceViewer.setSelectedRange(targetOffset, direction); sourceViewer.revealRange(targetOffset, direction); }
Example 8
Source File: JavaElementHyperlinkDetector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class); if (region == null || !(textEditor instanceof JavaEditor)) return null; IAction openAction= textEditor.getAction("OpenEditor"); //$NON-NLS-1$ if (!(openAction instanceof SelectionDispatchAction)) return null; int offset= region.getOffset(); ITypeRoot input= EditorUtility.getEditorInputJavaElement(textEditor, false); if (input == null) return null; try { IDocumentProvider documentProvider= textEditor.getDocumentProvider(); IEditorInput editorInput= textEditor.getEditorInput(); IDocument document= documentProvider.getDocument(editorInput); IRegion wordRegion= JavaWordFinder.findWord(document, offset); if (wordRegion == null || wordRegion.getLength() == 0) return null; if (isInheritDoc(document, wordRegion) && getClass() != JavaElementHyperlinkDetector.class) return null; if (JavaElementHyperlinkDetector.class == getClass() && findBreakOrContinueTarget(input, region) != null) return new IHyperlink[] { new JavaElementHyperlink(wordRegion, (SelectionDispatchAction)openAction, null, false) }; IJavaElement[] elements; long modStamp= documentProvider.getModificationStamp(editorInput); if (input.equals(fLastInput) && modStamp == fLastModStamp && wordRegion.equals(fLastWordRegion)) { elements= fLastElements; } else { elements= ((ICodeAssist) input).codeSelect(wordRegion.getOffset(), wordRegion.getLength()); elements= selectOpenableElements(elements); fLastInput= input; fLastModStamp= modStamp; fLastWordRegion= wordRegion; fLastElements= elements; } if (elements.length == 0) return null; ArrayList<IHyperlink> links= new ArrayList<IHyperlink>(elements.length); for (int i= 0; i < elements.length; i++) { addHyperlinks(links, wordRegion, (SelectionDispatchAction)openAction, elements[i], elements.length > 1, (JavaEditor)textEditor); } if (links.size() == 0) return null; return CollectionsUtil.toArray(links, IHyperlink.class); } catch (JavaModelException e) { return null; } }
Example 9
Source File: GotoMatchingBracketManager.java From goclipse with Eclipse Public License 1.0 | 4 votes |
public void gotoMatchingBracket() { ITextViewer sourceViewer = langEditor.getSourceViewer_(); IDocument document= sourceViewer.getDocument(); if (document == null) return; IRegion selection= EditorUtils.getSignedSelection(sourceViewer); if (fPreviousSelections == null) initializePreviousSelectionList(); IRegion region= getBracketMatcher().match(document, selection.getOffset(), selection.getLength()); if (region == null) { region= getBracketMatcher().findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength()); initializePreviousSelectionList(); fPreviousSelections.add(selection); } else { if (fPreviousSelections.size() == 2) { if (!selection.equals(fPreviousSelections.get(1))) { initializePreviousSelectionList(); } } else if (fPreviousSelections.size() == 3) { if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) { IRegion originalSelection= fPreviousSelections.get(0); sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength()); sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength()); initializePreviousSelectionList(); return; } initializePreviousSelectionList(); } } if (region == null) { langEditor.setStatusLineErrorMessage(LangEditorMessages.GotoMatchingBracket_error_noMatchingBracket); sourceViewer.getTextWidget().getDisplay().beep(); return; } int offset= region.getOffset(); int length= region.getLength(); if (length < 1) return; int anchor= getBracketMatcher().getAnchor(); // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1; boolean visible= false; if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) sourceViewer; visible= (extension.modelOffset2WidgetOffset(targetOffset) > -1); } else { IRegion visibleRegion= sourceViewer.getVisibleRegion(); // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 visible= (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength()); } if (!visible) { langEditor.setStatusLineErrorMessage(LangEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement); sourceViewer.getTextWidget().getDisplay().beep(); return; } int adjustment= getBracketMatcher().getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength()); targetOffset+= adjustment; int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1); if (fPreviousSelections.size() == 1 && direction < 0) { targetOffset++; } if (fPreviousSelections.size() > 0) { fPreviousSelections.add(new Region(targetOffset, direction)); } sourceViewer.setSelectedRange(targetOffset, direction); sourceViewer.revealRange(targetOffset, direction); }