IDocument[] getDocuments() { IDocument[] docs= new IDocument[fPositions.size()]; int i= 0; for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); i++) { LinkedPosition pos= it.next(); docs[i]= pos.getDocument(); } return docs; }
IDocument[] getDocuments() { IDocument[] docs= new IDocument[fPositions.size()]; int i= 0; for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); i++) { LinkedPosition pos= it.next(); docs[i]= pos.getDocument(); } return docs; }
/** * Prune <code>list</code> of all <code>LinkedPosition</code>s that * do not belong to this model's <code>IDocument</code>. * * @param list the list of positions to prune */ private void prune(List<Position> list) { for (Iterator<Position> iter= list.iterator(); iter.hasNext();) { LinkedPosition pos= (LinkedPosition) iter.next(); if (!pos.getDocument().equals(fDocument)) iter.remove(); } }
/** * Prune <code>list</code> of all <code>LinkedPosition</code>s that * do not belong to this model's <code>IDocument</code>. * * @param list the list of positions to prune */ private void prune(List<Position> list) { for (Iterator<Position> iter= list.iterator(); iter.hasNext();) { LinkedPosition pos= (LinkedPosition) iter.next(); if (!pos.getDocument().equals(fDocument)) iter.remove(); } }
/** * Returns whether this position includes <code>position</code>. * * @param position the position to check. * @return <code>true</code> if this position includes * <code>position</code>,<code>false</code> otherwise */ public boolean includes(LinkedPosition position) { return includes(position.getDocument(), position.getOffset(), position.getLength()); }
/** * Returns whether this position overlaps with <code>position</code>. * * @param position the position to check. * @return <code>true</code> if this position overlaps with * <code>position</code>,<code>false</code> otherwise */ public boolean overlapsWith(LinkedPosition position) { return position.getDocument() == fDocument && overlapsWith(position.getOffset(), position.getLength()); }
/** * Returns whether this position includes <code>position</code>. * * @param position the position to check. * @return <code>true</code> if this position includes * <code>position</code>,<code>false</code> otherwise */ public boolean includes(LinkedPosition position) { return includes(position.getDocument(), position.getOffset(), position.getLength()); }
/** * Returns whether this position overlaps with <code>position</code>. * * @param position the position to check. * @return <code>true</code> if this position overlaps with * <code>position</code>,<code>false</code> otherwise */ public boolean overlapsWith(LinkedPosition position) { return position.getDocument() == fDocument && overlapsWith(position.getOffset(), position.getLength()); }
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { IDocument doc= viewer.getDocument(); LinkedPosition position= fLinkedPositionModel.findPosition(new LinkedPosition(doc, offset, 0)); if (position != null) { try { try { TextEdit edit= fProposal.computeEdits(offset, position, trigger, stateMask, fLinkedPositionModel); if (edit != null) { edit.apply(position.getDocument(), 0); } } catch (MalformedTreeException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } } catch (CoreException e) { JavaPlugin.log(e); } } }
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { IDocument doc= viewer.getDocument(); LinkedPosition position= fLinkedPositionModel.findPosition(new LinkedPosition(doc, offset, 0)); if (position != null) { try { try { TextEdit edit= fProposal.computeEdits(offset, position, trigger, stateMask, fLinkedPositionModel); if (edit != null) { edit.apply(position.getDocument(), 0); } } catch (MalformedTreeException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } } catch (CoreException e) { JavaPlugin.log(e); } } }
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { IDocument doc= viewer.getDocument(); LinkedPosition position= fLinkedPositionModel.findPosition(new LinkedPosition(doc, offset, 0)); if (position != null) { try { try { TextEdit edit= fProposal.computeEdits(offset, position, trigger, stateMask, fLinkedPositionModel); if (edit != null) { edit.apply(position.getDocument(), 0); } } catch (MalformedTreeException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Unexpected exception applying edit", e)); //$NON-NLS-1$ } } catch (CoreException e) { JavaPlugin.log(e); } } }
@Override public void run() { if (fExitPosition != null) fExitPosition.getDocument().removePosition(fExitPosition); for (Iterator<IDocument> iter = docs.iterator(); iter.hasNext(); ) { IDocument doc= iter.next(); doc.removePositionUpdater(fPositionUpdater); boolean uninstallCat= false; String[] cats= doc.getPositionCategories(); for (int j= 0; j < cats.length; j++) { if (getCategory().equals(cats[j])) { uninstallCat= true; break; } } if (uninstallCat) try { doc.removePositionCategory(getCategory()); } catch (BadPositionCategoryException e) { // ignore } } fModel.exit(flags); } };
/** * Registers a <code>LinkedPosition</code> with this model. Called * by <code>PositionGroup</code>. * * @param position the position to register * @throws BadLocationException if the position cannot be added to its * document */ void register(LinkedPosition position) throws BadLocationException { Assert.isNotNull(position); IDocument document= position.getDocument(); manageDocument(document); try { document.addPosition(getCategory(), position); } catch (BadPositionCategoryException e) { // won't happen as the category has been added by manageDocument() Assert.isTrue(false); } int seqNr= position.getSequenceNumber(); if (seqNr != LinkedPositionGroup.NO_STOP) { fPositionSequence.add(position); } }
/** * Registers a <code>LinkedPosition</code> with this model. Called * by <code>PositionGroup</code>. * * @param position the position to register * @throws BadLocationException if the position cannot be added to its * document */ void register(LinkedPosition position) throws BadLocationException { Assert.isNotNull(position); IDocument document= position.getDocument(); manageDocument(document); try { document.addPosition(getCategory(), position); } catch (BadPositionCategoryException e) { // won't happen as the category has been added by manageDocument() Assert.isTrue(false); } int seqNr= position.getSequenceNumber(); if (seqNr != LinkedPositionGroup.NO_STOP) { fPositionSequence.add(position); } }
@Override public TextEdit computeEdits(int offset, LinkedPosition currentPosition, char trigger, int stateMask, LinkedModeModel model) throws CoreException { try { IDocument document = currentPosition.getDocument(); MultiTextEdit edit = new MultiTextEdit(); int documentLen = document.getLength(); if (fModifier == 0) { int end = currentPosition.offset + currentPosition.length; // current end position int k = end; while (k < documentLen && IndentManipulation.isIndentChar(document.getChar(k))) { k++; } // first remove space then replace range (remove space can destroy empty position) edit.addChild(new ReplaceEdit(end, k - end, new String())); // remove extra spaces edit.addChild(new ReplaceEdit(currentPosition.offset, currentPosition.length, new String())); } else { // first then replace range the insert space (insert space can destroy empty position) edit.addChild(new ReplaceEdit(currentPosition.offset, currentPosition.length, ModifierKeyword.fromFlagValue(fModifier).toString())); int end = currentPosition.offset + currentPosition.length; // current end position if (end < documentLen && !Character.isWhitespace(document.getChar(end))) { edit.addChild(new ReplaceEdit(end, 0, String.valueOf(' '))); // insert extra space } } return edit; } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); } } }
/** * Checks whether the given event touches the given position. To touch means * to overlap or come up to the borders of the position. * * @param position the position * @param event the event * @return <code>true</code> if <code>position</code> and * <code>event</code> are not absolutely disjoint * @since 3.1 */ private boolean overlapsOrTouches(LinkedPosition position, DocumentEvent event) { return position.getDocument().equals(event.getDocument()) && position.getOffset() <= event.getOffset() + event.getLength() && position.getOffset() + position.getLength() >= event.getOffset(); }
/** * Checks whether the given event touches the given position. To touch means * to overlap or come up to the borders of the position. * * @param position the position * @param event the event * @return <code>true</code> if <code>position</code> and * <code>event</code> are not absolutely disjoint * @since 3.1 */ private boolean overlapsOrTouches(LinkedPosition position, DocumentEvent event) { return position.getDocument().equals(event.getDocument()) && position.getOffset() <= event.getOffset() + event.getLength() && position.getOffset() + position.getLength() >= event.getOffset(); }
public TextEdit computeEdits(int offset, LinkedPosition currentPosition, char trigger, int stateMask, LinkedModeModel model) throws CoreException { try { IDocument document= currentPosition.getDocument(); MultiTextEdit edit= new MultiTextEdit(); int documentLen= document.getLength(); if (fModifier == 0) { int end= currentPosition.offset + currentPosition.length; // current end position int k= end; while (k < documentLen && IndentManipulation.isIndentChar(document.getChar(k))) { k++; } // first remove space then replace range (remove space can destroy empty position) edit.addChild(new ReplaceEdit(end, k - end, new String())); // remove extra spaces edit.addChild(new ReplaceEdit(currentPosition.offset, currentPosition.length, new String())); } else { // first then replace range the insert space (insert space can destroy empty position) edit.addChild(new ReplaceEdit(currentPosition.offset, currentPosition.length, ModifierKeyword.fromFlagValue(fModifier).toString())); int end= currentPosition.offset + currentPosition.length; // current end position if (end < documentLen && !Character.isWhitespace(document.getChar(end))) { edit.addChild(new ReplaceEdit(end, 0, String.valueOf(' '))); // insert extra space } } return edit; } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, e.getMessage(), e)); } } }
private void switchPosition(LinkedPosition pos, boolean select, boolean showProposals) { Assert.isNotNull(pos); if (pos.equals(fFramePosition)) return; if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusLost(fFramePosition, fCurrentTarget); // undo endCompoundChangeIfNeeded(); redraw(); // redraw current position being left - usually not needed IDocument oldDoc= fFramePosition == null ? null : fFramePosition.getDocument(); IDocument newDoc= pos.getDocument(); switchViewer(oldDoc, newDoc, pos); fFramePosition= pos; if (select) select(); if (fFramePosition == fExitPosition && !fIterator.isCycling()) leave(ILinkedModeListener.NONE); else { redraw(); // redraw new position ensureAnnotationModelInstalled(); } if (showProposals) triggerContentAssist(); if (fFramePosition != fExitPosition && fDoContextInfo) triggerContextInfo(); if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusGained(fFramePosition, fCurrentTarget); }
private void switchPosition(LinkedPosition pos, boolean select, boolean showProposals) { Assert.isNotNull(pos); if (pos.equals(fFramePosition)) return; if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusLost(fFramePosition, fCurrentTarget); // undo endCompoundChangeIfNeeded(); redraw(); // redraw current position being left - usually not needed IDocument oldDoc= fFramePosition == null ? null : fFramePosition.getDocument(); IDocument newDoc= pos.getDocument(); switchViewer(oldDoc, newDoc, pos); fFramePosition= pos; if (select) select(); if (fFramePosition == fExitPosition && !fIterator.isCycling()) leave(ILinkedModeListener.NONE); else { redraw(); // redraw new position ensureAnnotationModelInstalled(); } if (showProposals) triggerContentAssist(); if (fFramePosition != fExitPosition && fDoContextInfo) triggerContextInfo(); if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusGained(fFramePosition, fCurrentTarget); }