/** * Adds the given position to the default position category of the * given document. * * @param document the document to which to add the position * @param position the position to add * @throws BadLocationException if the position is not a valid document position */ protected void addPosition(IDocument document, Position position) throws BadLocationException { if (document != null) document.addPosition(position); }
/** * Called before document changes occur. It must be followed by a call to postReplace(). * * @param document the document on which to track the reference position. * @param offset the offset * @throws BadLocationException if the offset describes an invalid range in this document * */ public void preReplace(IDocument document, int offset) throws BadLocationException { fPosition.setOffset(offset); try { document.addPositionCategory(CATEGORY); document.addPositionUpdater(fPositionUpdater); document.addPosition(CATEGORY, fPosition); } catch (BadPositionCategoryException e) { // should not happen JavaPlugin.log(e); } }
private void registerPositionUpdater(int start, int length) { fBaseDocument.addPositionCategory(RANGE_CATEGORY); fRange= new Position(start, length); try { fBaseDocument.addPosition(RANGE_CATEGORY, fRange); } catch (BadPositionCategoryException ex) { CompareUIPlugin.log(ex); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } }
/** * Adds the given position to the default position category of the * given document. * * @param document the document to which to add the position * @param position the position to add * @throws BadLocationException if the position is not a valid document position */ protected void addPosition(IDocument document, Position position) throws BadLocationException { if (document != null) document.addPosition(position); }
/** * Creates a new edition on the document of this factory. * * @param offset the offset of the edition at the point when is created. * @param length the length of the edition (not updated via the position update mechanism) * @param text the text to be replaced on the document * @return an <code>Edit</code> reflecting the edition on the document */ public Edit createEdit(int offset, int length, String text) throws BadLocationException { if (!fDocument.containsPositionCategory(fCategory)) { fDocument.addPositionCategory(fCategory); fUpdater= new DefaultPositionUpdater(fCategory); fDocument.addPositionUpdater(fUpdater); } Position position= new Position(offset); try { fDocument.addPosition(fCategory, position); } catch (BadPositionCategoryException e) { Assert.isTrue(false); } return new Edit(fDocument, length, text, position); }
private void registerPositionUpdater(int start, int length) { fBaseDocument.addPositionCategory(RANGE_CATEGORY); fRange= new Position(start, length); try { fBaseDocument.addPosition(RANGE_CATEGORY, fRange); } catch (BadPositionCategoryException ex) { CompareUIPlugin.log(ex); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } }
@Override public void managePosition(Position position) { try { fDocument.addPosition(fCategory, position); } catch (BadPositionCategoryException x) { // should not happen } catch (BadLocationException x) { // should not happen } }
@Override public void managePosition(Position position) { if (fDocument == null) { return; } try { fDocument.addPosition(fCategory, position); } catch (BadPositionCategoryException x) { // should not happen } catch (BadLocationException x) { // should not happen } }
private static void savePosition(IDocument document, ExtraPosition extraPosition) { try { document.addPosition(MarkerUtils.SONARLINT_EXTRA_POSITIONS_CATEGORY, extraPosition); } catch (BadLocationException | BadPositionCategoryException e) { throw new IllegalStateException("Unable to register extra position", e); } }
/** * Add a position with the given range and highlighting unconditionally, only from UI thread. * The position will also be registered on the document. The text presentation is not * invalidated. * * @param event The document event * @param category The category * @param offset The range offset * @param length The range length * @param highlighting the highlighting */ protected void addPositionForEvent(DocumentEvent event, String category, int offset, int length, Object highlighting) { HighlightedPositionCore highlightedPosition = new HighlightedPositionCore(offset, length, highlighting, new Object()); try { event.fDocument.addPosition(category, highlightedPosition); } catch (BadLocationException | BadPositionCategoryException e) { JavaManipulationPlugin.logException("Error when adding new highlighting position to the document", e); //$NON-NLS-1$ } } /**
@Override public void documentAboutToBeChanged(DocumentEvent event) { if (fActiveRegion != null) { fRememberedPosition= new Position(fActiveRegion.getOffset(), fActiveRegion.getLength()); try { event.getDocument().addPosition(fRememberedPosition); } catch (BadLocationException x) { fRememberedPosition= null; } } }
@Override public void documentAboutToBeChanged(DocumentEvent event) { if (fActiveRegion != null) { fRememberedPosition= new Position(fActiveRegion.getOffset(), fActiveRegion.getLength()); try { event.getDocument().addPosition(fRememberedPosition); } catch (BadLocationException x) { fRememberedPosition= null; } } }
/** * Adds a hyperlink to this console. * * @param hyperlink the hyperlink to add * @param offset the offset in the console document at which the hyperlink should be added * @param length the length of the text which should be hyperlinked * @throws BadLocationException if the specified location is not valid. */ public void addHyperlink(IHyperlink hyperlink, int offset, int length) throws BadLocationException { IDocument document = getDocument(); ConsoleHyperlinkPosition hyperlinkPosition = new ConsoleHyperlinkPosition(hyperlink, offset, length); try { document.addPosition(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY, hyperlinkPosition); fConsoleManager.refresh(this); } catch (BadPositionCategoryException e) { ConsolePlugin.log(e); } }
/** * Adds a hyperlink to this console. * * @param hyperlink the hyperlink to add * @param offset the offset in the console document at which the hyperlink should be added * @param length the length of the text which should be hyperlinked * @throws BadLocationException if the specified location is not valid. */ public void addHyperlink(IHyperlink hyperlink, int offset, int length) throws BadLocationException { IDocument document = getDocument(); ConsoleHyperlinkPosition hyperlinkPosition = new ConsoleHyperlinkPosition(hyperlink, offset, length); try { document.addPosition(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY, hyperlinkPosition); fConsoleManager.refresh(this); } catch (BadPositionCategoryException e) { ConsolePlugin.log(e); } }
private void trackPosition(AbstractTextSearchResult result, ITextFileBuffer fb, Match match) { int offset = match.getOffset(); int length = match.getLength(); if (offset < 0 || length < 0) return; try { IDocument doc= fb.getDocument(); Position position= new Position(offset, length); if (match.getBaseUnit() == Match.UNIT_LINE) { position= convertToCharacterPosition(position, doc); } doc.addPosition(position); fMatchesToSearchResults.put(match, result); fMatchesToPositions.put(match, position); addFileBufferMapping(fb, match); } catch (BadLocationException e) { // the match is outside the document result.removeMatch(match); } }
public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
private void trackPosition(AbstractTextSearchResult result, ITextFileBuffer fb, Match match) { int offset = match.getOffset(); int length = match.getLength(); if (offset < 0 || length < 0) return; try { IDocument doc= fb.getDocument(); Position position= new Position(offset, length); if (match.getBaseUnit() == Match.UNIT_LINE) { position= convertToCharacterPosition(position, doc); } doc.addPosition(position); fMatchesToSearchResults.put(match, result); fMatchesToPositions.put(match, position); addFileBufferMapping(fb, match); } catch (BadLocationException e) { // the match is outside the document result.removeMatch(match); } }
@Override public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
@Override public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
public void addFileLink(FileLink link, int offset, int length) { IDocument document = getDocument(); MarkerPosition linkPosition = new MarkerPosition(link, offset, length); try { document.addPosition(ERROR_MARKER_CATEGORY, linkPosition); IConsoleManager fConsoleManager = ConsolePlugin.getDefault().getConsoleManager(); fConsoleManager.refresh(this); } catch (BadPositionCategoryException e) { CppStyle.log(e); } catch (BadLocationException e) { CppStyle.log(e); } }