diff options
Diffstat (limited to 'org.eclipse.text/src/org')
99 files changed, 0 insertions, 16153 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java deleted file mode 100644 index 9e3bf7863bd..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java +++ /dev/null @@ -1,1309 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.regex.PatternSyntaxException; - - -/** - * Abstract default implementation of <code>IDocument</code> and its extension - * interfaces {@link org.eclipse.jface.text.IDocumentExtension}, - * {@link org.eclipse.jface.text.IDocumentExtension2}, - * {@link org.eclipse.jface.text.IDocumentExtension3}, as well as - * {@link org.eclipse.jface.text.IRepairableDocument}. - * <p> - * - * An <code>AbstractDocument</code> supports the following implementation - * plug-ins: - * <ul> - * <li>a text store implementing {@link org.eclipse.jface.text.ITextStore} for - * storing and managing the document's content,</li> - * <li>a line tracker implementing {@link org.eclipse.jface.text.ILineTracker} - * to map character positions to line numbers and vice versa</li> - * </ul> - * The document can dynamically change the text store when switching between - * sequential rewrite mode and normal mode. - * <p> - * - * This class must be subclassed. Subclasses must configure which implementation - * plug-ins the document instance should use. Subclasses are not intended to - * overwrite existing methods. - * - * @see org.eclipse.jface.text.ITextStore - * @see org.eclipse.jface.text.ILineTracker - */ -public abstract class AbstractDocument implements IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IRepairableDocument { - - /** - * Inner class to bundle a registered post notification replace operation together with its - * owner. - * - * @since 2.0 - */ - static private class RegisteredReplace { - /** The owner of this replace operation. */ - IDocumentListener fOwner; - /** The replace operation */ - IDocumentExtension.IReplace fReplace; - - /** - * Creates a new bundle object. - * @param owner the document listener owning the replace operation - * @param replace the replace operation - */ - RegisteredReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { - fOwner= owner; - fReplace= replace; - } - } - - - /** The document's text store */ - private ITextStore fStore; - /** The document's line tracker */ - private ILineTracker fTracker; - /** The registered document listeners */ - private List fDocumentListeners; - /** The registered pre-notified document listeners */ - private List fPrenotifiedDocumentListeners; - /** The registered document partitioning listeners */ - private List fDocumentPartitioningListeners; - /** All positions managed by the document */ - private Map fPositions; - /** All registered document position updaters */ - private List fPositionUpdaters; - /** - * The list of post notification changes - * @since 2.0 - */ - private List fPostNotificationChanges; - /** - * The reentrance count for post notification changes. - * @since 2.0 - */ - private int fReentranceCount= 0; - /** - * Indicates whether post notification change processing has been stopped. - * @since 2.0 - */ - private int fStoppedCount= 0; - /** - * Indicates whether the registration of post notification changes should be ignored. - * @since 2.1 - */ - private boolean fAcceptPostNotificationReplaces= true; - /** - * Indicates whether the notification of listeners has been stopped. - * @since 2.1 - */ - private int fStoppedListenerNotification= 0; - /** - * The document event to be sent after listener notification has been resumed. - * @since 2.1 - */ - private DocumentEvent fDeferredDocumentEvent; - /** - * The registered document partitioners. - * @since 3.0 - */ - private Map fDocumentPartitioners; - /** - * The partitioning changed event. - * @since 3.0 - */ - private DocumentPartitioningChangedEvent fDocumentPartitioningChangedEvent; - /** - * The find/replace document adapter. - * @since 3.0 - */ - private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter; - - - /** - * The default constructor does not perform any configuration - * but leaves it to the clients who must first initialize the - * implementation plug-ins and then call <code>completeInitialization</code>. - * Results in the construction of an empty document. - */ - protected AbstractDocument() { - } - - - /** - * Returns the document's text store. Assumes that the - * document has been initialized with a text store. - * - * @return the document's text store - */ - protected ITextStore getStore() { - Assert.isNotNull(fStore); - return fStore; - } - - /** - * Returns the document's line tracker. Assumes that the - * document has been initialized with a line tracker. - * - * @return the document's line tracker - */ - protected ILineTracker getTracker() { - Assert.isNotNull(fTracker); - return fTracker; - } - - /** - * Returns the document's document listeners. - * - * @return the document's document listeners - */ - protected List getDocumentListeners() { - return fDocumentListeners; - } - - /** - * Returns the document's partitioning listeners . - * - * @return the document's partitioning listeners - */ - protected List getDocumentPartitioningListeners() { - return fDocumentPartitioningListeners; - } - - /** - * Returns all positions managed by the document grouped by category. - * - * @return the document's positions - */ - protected Map getDocumentManagedPositions() { - return fPositions; - } - - /* - * @see org.eclipse.jface.text.IDocument#getDocumentPartitioner() - */ - public IDocumentPartitioner getDocumentPartitioner() { - return getDocumentPartitioner(DEFAULT_PARTITIONING); - } - - - - //--- implementation configuration interface ------------ - - /** - * Sets the document's text store. - * Must be called at the beginning of the constructor. - * - * @param store the document's text store - */ - protected void setTextStore(ITextStore store) { - fStore= store; - } - - /** - * Sets the document's line tracker. - * Must be called at the beginning of the constructor. - * - * @param tracker the document's line tracker - */ - protected void setLineTracker(ILineTracker tracker) { - fTracker= tracker; - } - - /* - * @see org.eclipse.jface.text.IDocument#setDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) - */ - public void setDocumentPartitioner(IDocumentPartitioner partitioner) { - setDocumentPartitioner(DEFAULT_PARTITIONING, partitioner); - } - - /** - * Initializes document listeners, positions, and position updaters. - * Must be called inside the constructor after the implementation plug-ins - * have been set. - */ - protected void completeInitialization() { - - fPositions= new HashMap(); - fPositionUpdaters= new ArrayList(); - fDocumentListeners= new ArrayList(); - fPrenotifiedDocumentListeners= new ArrayList(); - fDocumentPartitioningListeners= new ArrayList(); - - addPositionCategory(DEFAULT_CATEGORY); - addPositionUpdater(new DefaultPositionUpdater(DEFAULT_CATEGORY)); - } - - - //------------------------------------------------------- - - /* - * @see org.eclipse.jface.text.IDocument#addDocumentListener(org.eclipse.jface.text.IDocumentListener) - */ - public void addDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - if (! fDocumentListeners.contains(listener)) - fDocumentListeners.add(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#removeDocumentListener(org.eclipse.jface.text.IDocumentListener) - */ - public void removeDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - fDocumentListeners.remove(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#addPrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener) - */ - public void addPrenotifiedDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - if (! fPrenotifiedDocumentListeners.contains(listener)) - fPrenotifiedDocumentListeners.add(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#removePrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener) - */ - public void removePrenotifiedDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - fPrenotifiedDocumentListeners.remove(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#addDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener) - */ - public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) { - Assert.isNotNull(listener); - if (! fDocumentPartitioningListeners.contains(listener)) - fDocumentPartitioningListeners.add(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#removeDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener) - */ - public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) { - Assert.isNotNull(listener); - fDocumentPartitioningListeners.remove(listener); - } - - /* - * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position) - */ - public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { - - if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) - throw new BadLocationException(); - - if (category == null) - throw new BadPositionCategoryException(); - - List list= (List) fPositions.get(category); - if (list == null) - throw new BadPositionCategoryException(); - - list.add(computeIndexInPositionList(list, position.offset), position); - } - - /* - * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position) - */ - public void addPosition(Position position) throws BadLocationException { - try { - addPosition(DEFAULT_CATEGORY, position); - } catch (BadPositionCategoryException e) { - } - } - - /* - * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String) - */ - public void addPositionCategory(String category) { - - if (category == null) - return; - - if (!containsPositionCategory(category)) - fPositions.put(category, new ArrayList()); - } - - /* - * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater) - */ - public void addPositionUpdater(IPositionUpdater updater) { - insertPositionUpdater(updater, fPositionUpdaters.size()); - } - - /* - * @see org.eclipse.jface.text.IDocument#containsPosition(java.lang.String, int, int) - */ - public boolean containsPosition(String category, int offset, int length) { - - if (category == null) - return false; - - List list= (List) fPositions.get(category); - if (list == null) - return false; - - int size= list.size(); - if (size == 0) - return false; - - int index= computeIndexInPositionList(list, offset); - if (index < size) { - Position p= (Position) list.get(index); - while (p != null && p.offset == offset) { - if (p.length == length) - return true; - ++ index; - p= (index < size) ? (Position) list.get(index) : null; - } - } - - return false; - } - - /* - * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String) - */ - public boolean containsPositionCategory(String category) { - if (category != null) - return fPositions.containsKey(category); - return false; - } - - - /** - * Computes the index in the list of positions at which a position with the given - * offset would be inserted. The position is supposed to become the first in this list - * of all positions with the same offset. - * - * @param positions the list in which the index is computed - * @param offset the offset for which the index is computed - * @return the computed index - * - * @see IDocument#computeIndexInCategory(String, int) - */ - protected int computeIndexInPositionList(List positions, int offset) { - - if (positions.size() == 0) - return 0; - - int left= 0; - int right= positions.size() -1; - int mid= 0; - Position p= null; - - while (left < right) { - - mid= (left + right) / 2; - - p= (Position) positions.get(mid); - if (offset < p.getOffset()) { - if (left == mid) - right= left; - else - right= mid -1; - } else if (offset > p.getOffset()) { - if (right == mid) - left= right; - else - left= mid +1; - } else if (offset == p.getOffset()) { - left= right= mid; - } - - } - - int pos= left; - p= (Position) positions.get(pos); - if (offset > p.getOffset()) { - // append to the end - pos++; - } else { - // entry will became the first of all entries with the same offset - do { - --pos; - if (pos < 0) - break; - p= (Position) positions.get(pos); - } while (offset == p.getOffset()); - ++pos; - } - - Assert.isTrue(0 <= pos && pos <= positions.size()); - - return pos; - } - - /* - * @see org.eclipse.jface.text.IDocument#computeIndexInCategory(java.lang.String, int) - */ - public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException { - - if (0 > offset || offset > getLength()) - throw new BadLocationException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - return computeIndexInPositionList(c, offset); - } - - /** - * Fires the document partitioning changed notification to all registered - * document partitioning listeners. Uses a robust iterator. - * - * @deprecated as of 2.0. Use <code>fireDocumentPartitioningChanged(IRegion)</code> instead. - */ - protected void fireDocumentPartitioningChanged() { - - if (fDocumentPartitioningListeners != null && fDocumentPartitioningListeners.size() > 0) { - - List list= new ArrayList(fDocumentPartitioningListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentPartitioningListener l= (IDocumentPartitioningListener) e.next(); - l.documentPartitioningChanged(this); - } - } - } - - /** - * Fires the document partitioning changed notification to all registered - * document partitioning listeners. Uses a robust iterator. - * - * @param region the region in which partitioning has changed - * - * @see IDocumentPartitioningListenerExtension - * @since 2.0 - * @deprecated as of 3.0. Use - * <code>fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent)</code> - * instead. - */ - protected void fireDocumentPartitioningChanged(IRegion region) { - - if (fDocumentPartitioningListeners != null && fDocumentPartitioningListeners.size() > 0) { - - List list= new ArrayList(fDocumentPartitioningListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentPartitioningListener l= (IDocumentPartitioningListener) e.next(); - if (l instanceof IDocumentPartitioningListenerExtension) - ((IDocumentPartitioningListenerExtension) l).documentPartitioningChanged(this, region); - else - l.documentPartitioningChanged(this); - } - } - } - - /** - * Fires the document partitioning changed notification to all registered - * document partitioning listeners. Uses a robust iterator. - * - * @param event the document partitioning changed event - * - * @see IDocumentPartitioningListenerExtension2 - * @since 3.0 - */ - protected void fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent event) { - if (fDocumentPartitioningListeners == null || fDocumentPartitioningListeners.size() == 0) - return; - - List list= new ArrayList(fDocumentPartitioningListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentPartitioningListener l= (IDocumentPartitioningListener) e.next(); - if (l instanceof IDocumentPartitioningListenerExtension2) { - IDocumentPartitioningListenerExtension2 extension2= (IDocumentPartitioningListenerExtension2) l; - extension2.documentPartitioningChanged(event); - } else if (l instanceof IDocumentPartitioningListenerExtension) { - IDocumentPartitioningListenerExtension extension= (IDocumentPartitioningListenerExtension) l; - extension.documentPartitioningChanged(this, event.getCoverage()); - } else { - l.documentPartitioningChanged(this); - } - } - - } - - /** - * Fires the given document event to all registers document listeners informing them - * about the forthcoming document manipulation. Uses a robust iterator. - * - * @param event the event to be sent out - */ - protected void fireDocumentAboutToBeChanged(DocumentEvent event) { - - // IDocumentExtension - if (fReentranceCount == 0) - flushPostNotificationChanges(); - - if (fDocumentPartitioners != null) { - Iterator e= fDocumentPartitioners.values().iterator(); - while (e.hasNext()) { - IDocumentPartitioner p= (IDocumentPartitioner) e.next(); - p.documentAboutToBeChanged(event); - } - } - - if (fPrenotifiedDocumentListeners.size() > 0) { - - List list= new ArrayList(fPrenotifiedDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentAboutToBeChanged(event); - } - } - - if (fDocumentListeners.size() > 0) { - - List list= new ArrayList(fDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentAboutToBeChanged(event); - } - } - } - - - /** - * Updates document partitioning and document positions according to the - * specification given by the document event. - * - * @param event the document event describing the change to which structures must be adapted - */ - protected void updateDocumentStructures(DocumentEvent event) { - - if (fDocumentPartitioners != null) { - fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this); - Iterator e= fDocumentPartitioners.keySet().iterator(); - while (e.hasNext()) { - String partitioning= (String) e.next(); - IDocumentPartitioner partitioner= (IDocumentPartitioner) fDocumentPartitioners.get(partitioning); - if (partitioner instanceof IDocumentPartitionerExtension) { - IDocumentPartitionerExtension extension= (IDocumentPartitionerExtension) partitioner; - IRegion r= extension.documentChanged2(event); - if (r != null) - fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, r.getOffset(), r.getLength()); - } else { - if (partitioner.documentChanged(event)) - fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, 0, event.getDocument().getLength()); - } - } - } - - if (fPositions.size() > 0) - updatePositions(event); - } - - /** - * Notifies all listeners about the given document change. Uses a robust - * iterator. - * <p> - * Executes all registered post notification replace operation. - * - * @param event the event to be sent out. - */ - protected void doFireDocumentChanged(DocumentEvent event) { - boolean changed= fDocumentPartitioningChangedEvent != null && !fDocumentPartitioningChangedEvent.isEmpty(); - IRegion change= changed ? fDocumentPartitioningChangedEvent.getCoverage() : null; - doFireDocumentChanged(event, changed, change); - } - - /** - * Notifies all listeners about the given document change. - * Uses a robust iterator. <p> - * Executes all registered post notification replace operation. - * - * @param event the event to be sent out - * @param firePartitionChange <code>true</code> if a partition change notification should be sent - * @param partitionChange the region whose partitioning changed - * @since 2.0 - * @deprecated as of 3.0. Use <code>doFireDocumentChanged2(DocumentEvent)</code> instead; this method will be removed. - */ - protected void doFireDocumentChanged(DocumentEvent event, boolean firePartitionChange, IRegion partitionChange) { - doFireDocumentChanged2(event); - } - - /** - * Notifies all listeners about the given document change. Uses a robust - * iterator. - * <p> - * Executes all registered post notification replace operation. - * <p> - * This method will be renamed to <code>doFireDocumentChanged</code>. - * - * @param event the event to be sent out - * @since 3.0 - */ - protected void doFireDocumentChanged2(DocumentEvent event) { - - DocumentPartitioningChangedEvent p= fDocumentPartitioningChangedEvent; - fDocumentPartitioningChangedEvent= null; - if (p != null && !p.isEmpty()) - fireDocumentPartitioningChanged(p); - - if (fPrenotifiedDocumentListeners.size() > 0) { - - List list= new ArrayList(fPrenotifiedDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentChanged(event); - } - } - - if (fDocumentListeners.size() > 0) { - - List list= new ArrayList(fDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentChanged(event); - } - } - - // IDocumentExtension - ++ fReentranceCount; - try { - if (fReentranceCount == 1) - executePostNotificationChanges(); - } finally { - -- fReentranceCount; - } - } - - /** - * Updates the internal document structures and informs all document listeners - * if listener notification has been enabled. Otherwise it remembers the event - * to be sent to the listeners on resume. - * - * @param event the document event to be sent out - */ - protected void fireDocumentChanged(DocumentEvent event) { - updateDocumentStructures(event); - - if (fStoppedListenerNotification == 0) - doFireDocumentChanged(event); - else - fDeferredDocumentEvent= event; - } - - /* - * @see org.eclipse.jface.text.IDocument#getChar(int) - */ - public char getChar(int pos) throws BadLocationException { - if ((0 > pos) || (pos >= getLength())) - throw new BadLocationException(); - return getStore().get(pos); - } - - /* - * @see org.eclipse.jface.text.IDocument#getContentType(int) - */ - public String getContentType(int offset) throws BadLocationException { - String contentType= null; - try { - contentType= getContentType(DEFAULT_PARTITIONING, offset, false); - Assert.isNotNull(contentType); - } catch (BadPartitioningException e) { - Assert.isTrue(false); - } - return contentType; - } - - /* - * @see org.eclipse.jface.text.IDocument#getLegalContentTypes() - */ - public String[] getLegalContentTypes() { - String[] contentTypes= null; - try { - contentTypes= getLegalContentTypes(DEFAULT_PARTITIONING); - Assert.isNotNull(contentTypes); - } catch (BadPartitioningException e) { - Assert.isTrue(false); - } - return contentTypes; - } - - /* - * @see org.eclipse.jface.text.IDocument#getLength() - */ - public int getLength() { - return getStore().getLength(); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int) - */ - public String getLineDelimiter(int line) throws BadLocationException { - return getTracker().getLineDelimiter(line); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters() - */ - public String[] getLegalLineDelimiters() { - return getTracker().getLegalLineDelimiters(); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineLength(int) - */ - public int getLineLength(int line) throws BadLocationException { - return getTracker().getLineLength(line); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineOfOffset(int) - */ - public int getLineOfOffset(int pos) throws BadLocationException { - return getTracker().getLineNumberOfOffset(pos); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineOffset(int) - */ - public int getLineOffset(int line) throws BadLocationException { - return getTracker().getLineOffset(line); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineInformation(int) - */ - public IRegion getLineInformation(int line) throws BadLocationException { - return getTracker().getLineInformation(line); - } - - /* - * @see org.eclipse.jface.text.IDocument#getLineInformationOfOffset(int) - */ - public IRegion getLineInformationOfOffset(int offset) throws BadLocationException { - return getTracker().getLineInformationOfOffset(offset); - } - - /* - * @see org.eclipse.jface.text.IDocument#getNumberOfLines() - */ - public int getNumberOfLines() { - return getTracker().getNumberOfLines(); - } - - /* - * @see org.eclipse.jface.text.IDocument#getNumberOfLines(int, int) - */ - public int getNumberOfLines(int offset, int length) throws BadLocationException { - return getTracker().getNumberOfLines(offset, length); - } - - /* - * @see org.eclipse.jface.text.IDocument#computeNumberOfLines(java.lang.String) - */ - public int computeNumberOfLines(String text) { - return getTracker().computeNumberOfLines(text); - } - - /* - * @see org.eclipse.jface.text.IDocument#getPartition(int) - */ - public ITypedRegion getPartition(int offset) throws BadLocationException { - ITypedRegion partition= null; - try { - partition= getPartition(DEFAULT_PARTITIONING, offset, false); - Assert.isNotNull(partition); - } catch (BadPartitioningException e) { - Assert.isTrue(false); - } - return partition; - } - - /* - * @see org.eclipse.jface.text.IDocument#computePartitioning(int, int) - */ - public ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException { - ITypedRegion[] partitioning= null; - try { - partitioning= computePartitioning(DEFAULT_PARTITIONING, offset, length, false); - Assert.isNotNull(partitioning); - } catch (BadPartitioningException e) { - Assert.isTrue(false); - } - return partitioning; - } - - /* - * @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String) - */ - public Position[] getPositions(String category) throws BadPositionCategoryException { - - if (category == null) - throw new BadPositionCategoryException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - Position[] positions= new Position[c.size()]; - c.toArray(positions); - return positions; - } - - /* - * @see org.eclipse.jface.text.IDocument#getPositionCategories() - */ - public String[] getPositionCategories() { - String[] categories= new String[fPositions.size()]; - Iterator keys= fPositions.keySet().iterator(); - for (int i= 0; i < categories.length; i++) - categories[i]= (String) keys.next(); - return categories; - } - - /* - * @see org.eclipse.jface.text.IDocument#getPositionUpdaters() - */ - public IPositionUpdater[] getPositionUpdaters() { - IPositionUpdater[] updaters= new IPositionUpdater[fPositionUpdaters.size()]; - fPositionUpdaters.toArray(updaters); - return updaters; - } - - /* - * @see org.eclipse.jface.text.IDocument#get() - */ - public String get() { - return getStore().get(0, getLength()); - } - - /* - * @see org.eclipse.jface.text.IDocument#get(int, int) - */ - public String get(int pos, int length) throws BadLocationException { - int myLength= getLength(); - if ((0 > pos) || (0 > length) || (pos + length > myLength)) - throw new BadLocationException(); - return getStore().get(pos, length); - } - - /* - * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater, int) - */ - public void insertPositionUpdater(IPositionUpdater updater, int index) { - - for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { - if (fPositionUpdaters.get(i) == updater) - return; - } - - if (index == fPositionUpdaters.size()) - fPositionUpdaters.add(updater); - else - fPositionUpdaters.add(index, updater); - } - - /* - * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position) - */ - public void removePosition(String category, Position position) throws BadPositionCategoryException { - - if (position == null) - return; - - if (category == null) - throw new BadPositionCategoryException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - // remove based on identity not equality - int size= c.size(); - for (int i= 0; i < size; i++) { - if (position == c.get(i)) { - c.remove(i); - return; - } - } - } - - /* - * @see org.eclipse.jface.text.IDocument#removePosition(org.eclipse.jface.text.Position) - */ - public void removePosition(Position position) { - try { - removePosition(DEFAULT_CATEGORY, position); - } catch (BadPositionCategoryException e) { - } - } - - /* - * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String) - */ - public void removePositionCategory(String category) throws BadPositionCategoryException { - - if (category == null) - return; - - if ( !containsPositionCategory(category)) - throw new BadPositionCategoryException(); - - fPositions.remove(category); - } - - /* - * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater) - */ - public void removePositionUpdater(IPositionUpdater updater) { - for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { - if (fPositionUpdaters.get(i) == updater) { - fPositionUpdaters.remove(i); - return; - } - } - } - - /* - * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String) - */ - public void replace(int pos, int length, String text) throws BadLocationException { - if ((0 > pos) || (0 > length) || (pos + length > getLength())) - throw new BadLocationException(); - - DocumentEvent e= new DocumentEvent(this, pos, length, text); - fireDocumentAboutToBeChanged(e); - - getStore().replace(pos, length, text); - getTracker().replace(pos, length, text); - - fireDocumentChanged(e); - } - - /* - * @see org.eclipse.jface.text.IDocument#set(java.lang.String) - */ - public void set(String text) { - int length= getStore().getLength(); - DocumentEvent e= new DocumentEvent(this, 0, length, text); - fireDocumentAboutToBeChanged(e); - - getStore().set(text); - getTracker().set(text); - - fireDocumentChanged(e); - } - - /** - * Updates all positions of all categories to the change described by the - * document event. All registered document updaters are called in the - * sequence they have been arranged. Uses a robust iterator. - * - * @param event the document event describing the change to which to adapt - * the positions - */ - protected void updatePositions(DocumentEvent event) { - List list= new ArrayList(fPositionUpdaters); - Iterator e= list.iterator(); - while (e.hasNext()) { - IPositionUpdater u= (IPositionUpdater) e.next(); - u.update(event); - } - } - - /* - * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String, boolean, boolean, boolean) - */ - public int search(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException { - try { - IRegion region= getFindReplaceDocumentAdapter().find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false); - if (region == null) - return -1; - else - return region.getOffset(); - } catch (IllegalStateException ex) { - return -1; - } catch (PatternSyntaxException ex) { - return -1; - } - } - - /** - * Returns the find/replace adapter for this document. - * - * @return this document's find/replace document adapter - * @since 3.0 - */ - private FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() { - if (fFindReplaceDocumentAdapter == null) - fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(this); - - return fFindReplaceDocumentAdapter; - } - - /** - * Flushes all registered post notification changes. - * - * @since 2.0 - */ - private void flushPostNotificationChanges() { - if (fPostNotificationChanges != null) - fPostNotificationChanges.clear(); - } - - /** - * Executes all registered post notification changes. The process is - * repeated until no new post notification changes are added. - * - * @since 2.0 - */ - private void executePostNotificationChanges() { - - if (fStoppedCount > 0) - return; - - while (fPostNotificationChanges != null) { - List changes= fPostNotificationChanges; - fPostNotificationChanges= null; - - Iterator e= changes.iterator(); - while (e.hasNext()) { - RegisteredReplace replace = (RegisteredReplace) e.next(); - replace.fReplace.perform(this, replace.fOwner); - } - } - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension2#acceptPostNotificationReplaces() - * @since 2.1 - */ - public void acceptPostNotificationReplaces() { - fAcceptPostNotificationReplaces= true; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension2#ignorePostNotificationReplaces() - * @since 2.1 - */ - public void ignorePostNotificationReplaces() { - fAcceptPostNotificationReplaces= false; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#registerPostNotificationReplace(org.eclipse.jface.text.IDocumentListener, org.eclipse.jface.text.IDocumentExtension.IReplace) - * @since 2.0 - */ - public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { - if (fAcceptPostNotificationReplaces) { - if (fPostNotificationChanges == null) - fPostNotificationChanges= new ArrayList(1); - fPostNotificationChanges.add(new RegisteredReplace(owner, replace)); - } - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#stopPostNotificationProcessing() - * @since 2.0 - */ - public void stopPostNotificationProcessing() { - ++ fStoppedCount; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#resumePostNotificationProcessing() - * @since 2.0 - */ - public void resumePostNotificationProcessing() { - -- fStoppedCount; - if (fStoppedCount == 0 && fReentranceCount == 0) - executePostNotificationChanges(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#startSequentialRewrite(boolean) - * @since 2.0 - */ - public void startSequentialRewrite(boolean normalized) { - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#stopSequentialRewrite() - * @since 2.0 - */ - public void stopSequentialRewrite() { - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension2#resumeListenerNotification() - * @since 2.1 - */ - public void resumeListenerNotification() { - -- fStoppedListenerNotification; - if (fStoppedListenerNotification == 0) { - resumeDocumentListenerNotification(); - } - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension2#stopListenerNotification() - * @since 2.1 - */ - public void stopListenerNotification() { - ++ fStoppedListenerNotification; - } - - /** - * Resumes the document listener notification by sending out the remembered - * partition changed and document event. - * - * @since 2.1 - */ - private void resumeDocumentListenerNotification() { - if (fDeferredDocumentEvent != null) { - DocumentEvent event= fDeferredDocumentEvent; - fDeferredDocumentEvent= null; - doFireDocumentChanged(event); - } - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#computeZeroLengthPartitioning(java.lang.String, int, int) - * @since 3.0 - */ - public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException { - if ((0 > offset) || (0 > length) || (offset + length > getLength())) - throw new BadLocationException(); - - IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); - - if (partitioner instanceof IDocumentPartitionerExtension2) - return ((IDocumentPartitionerExtension2) partitioner).computePartitioning(offset, length, includeZeroLengthPartitions); - else if (partitioner != null) - return partitioner.computePartitioning(offset, length); - else if (DEFAULT_PARTITIONING.equals(partitioning)) - return new TypedRegion[] { new TypedRegion(offset, length, DEFAULT_CONTENT_TYPE) }; - else - throw new BadPartitioningException(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#getZeroLengthContentType(java.lang.String, int) - * @since 3.0 - */ - public String getContentType(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException { - if ((0 > offset) || (offset > getLength())) - throw new BadLocationException(); - - IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); - - if (partitioner instanceof IDocumentPartitionerExtension2) - return ((IDocumentPartitionerExtension2) partitioner).getContentType(offset, preferOpenPartitions); - else if (partitioner != null) - return partitioner.getContentType(offset); - else if (DEFAULT_PARTITIONING.equals(partitioning)) - return DEFAULT_CONTENT_TYPE; - else - throw new BadPartitioningException(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner(java.lang.String) - * @since 3.0 - */ - public IDocumentPartitioner getDocumentPartitioner(String partitioning) { - return fDocumentPartitioners != null ? (IDocumentPartitioner) fDocumentPartitioners.get(partitioning) : null; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#getLegalContentTypes(java.lang.String) - * @since 3.0 - */ - public String[] getLegalContentTypes(String partitioning) throws BadPartitioningException { - IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); - if (partitioner != null) - return partitioner.getLegalContentTypes(); - if (DEFAULT_PARTITIONING.equals(partitioning)) - return new String[] { DEFAULT_CONTENT_TYPE }; - throw new BadPartitioningException(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#getZeroLengthPartition(java.lang.String, int) - * @since 3.0 - */ - public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException { - if ((0 > offset) || (offset > getLength())) - throw new BadLocationException(); - - IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); - - if (partitioner instanceof IDocumentPartitionerExtension2) - return ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions); - else if (partitioner != null) - return partitioner.getPartition(offset); - else if (DEFAULT_PARTITIONING.equals(partitioning)) - return new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE); - else - throw new BadPartitioningException(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#getPartitionings() - * @since 3.0 - */ - public String[] getPartitionings() { - if (fDocumentPartitioners == null) - return new String[0]; - String[] partitionings= new String[fDocumentPartitioners.size()]; - fDocumentPartitioners.keySet().toArray(partitionings); - return partitionings; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension3#setDocumentPartitioner(java.lang.String, org.eclipse.jface.text.IDocumentPartitioner) - * @since 3.0 - */ - public void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner) { - if (partitioner == null) { - if (fDocumentPartitioners != null) { - fDocumentPartitioners.remove(partitioning); - if (fDocumentPartitioners.size() == 0) - fDocumentPartitioners= null; - } - } else { - if (fDocumentPartitioners == null) - fDocumentPartitioners= new HashMap(); - fDocumentPartitioners.put(partitioning, partitioner); - } - DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); - event.setPartitionChange(partitioning, 0, getLength()); - fireDocumentPartitioningChanged(event); - } - - /* - * @see org.eclipse.jface.text.IRepairableDocument#repairLineInformation() - * @since 3.0 - */ - public void repairLineInformation() { - getTracker().set(get()); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java deleted file mode 100644 index 89e993671eb..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java +++ /dev/null @@ -1,554 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import java.util.ArrayList; -import java.util.List; - - -/** - * Abstract implementation of <code>ILineTracker</code>. It lets the - * definition of line delimiters to subclasses. Assuming that '\n' is - * the only line delimiter, this abstract implementation defines the - * following line scheme: - * <ul> - * <li> "" -> [0,0] - * <li> "a" -> [0,1] - * <li> "\n" -> [0,1], [1,0] - * <li> "a\n" -> [0,2], [2,0] - * <li> "a\nb" -> [0,2], [2,1] - * <li> "a\nbc\n" -> [0,2], [2,3], [5,0] - * </ul> - * This class must be subclassed. - */ -public abstract class AbstractLineTracker implements ILineTracker { - - - /** - * Combines the information of the occurrence of a line delimiter. - * <code>delimiterIndex</code> is the index where a line delimiter - * starts, whereas <code>delimiterLength</code>, indicates the length - * of the delimiter. - */ - protected static class DelimiterInfo { - public int delimiterIndex; - public int delimiterLength; - public String delimiter; - } - - - /** The line information */ - private List fLines= new ArrayList(); - /** The length of the tracked text */ - private int fTextLength; - - - /** - * Creates a new line tracker. - */ - protected AbstractLineTracker() { - } - - /** - * Binary search for the line at a given offset. - * - * @param offset the offset whose line should be found - * @return the line of the offset - */ - private int findLine(int offset) { - - if (fLines.size() == 0) - return -1; - - int left= 0; - int right= fLines.size() -1; - int mid= 0; - Line line= null; - - while (left < right) { - - mid= (left + right) / 2; - - line= (Line) fLines.get(mid); - if (offset < line.offset) { - if (left == mid) - right= left; - else - right= mid -1; - } else if (offset > line.offset) { - if (right == mid) - left= right; - else - left= mid +1; - } else if (offset == line.offset) { - left= right= mid; - } - } - - line= (Line) fLines.get(left); - if (line.offset > offset) - -- left; - return left; - } - - /** - * Returns the number of lines covered by the specified text range. - * - * @param startLine the line where the text range starts - * @param offset the start offset of the text range - * @param length the length of the text range - * @return the number of lines covered by this text range - * @exception BadLocationException if range is undefined in this tracker - */ - private int getNumberOfLines(int startLine, int offset, int length) throws BadLocationException { - - if (length == 0) - return 1; - - int target= offset + length; - - Line l= (Line) fLines.get(startLine); - - if (l.delimiter == null) - return 1; - - if (l.offset + l.length > target) - return 1; - - if (l.offset + l.length == target) - return 2; - - return getLineNumberOfOffset(target) - startLine + 1; - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineLength(int) - */ - public int getLineLength(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0 || lines == line) - return 0; - - Line l= (Line) fLines.get(line); - return l.length; - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineNumberOfOffset(int) - */ - public int getLineNumberOfOffset(int position) throws BadLocationException { - - if (position > fTextLength) - throw new BadLocationException(); - - if (position == fTextLength) { - - int lastLine= fLines.size() - 1; - if (lastLine < 0) - return 0; - - Line l= (Line) fLines.get(lastLine); - return (l.delimiter != null ? lastLine + 1 : lastLine); - } - - return findLine(position); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineInformationOfOffset(int) - */ - public IRegion getLineInformationOfOffset(int position) throws BadLocationException { - if (position > fTextLength) - throw new BadLocationException(); - - if (position == fTextLength) { - int size= fLines.size(); - if (size == 0) - return new Region(0, 0); - Line l= (Line) fLines.get(size - 1); - return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length)); - } - - return getLineInformation(findLine(position)); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineInformation(int) - */ - public IRegion getLineInformation(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return new Line(0, 0); - - if (line == lines) { - Line l= (Line) fLines.get(line - 1); - return new Line(l.offset + l.length, 0); - } - - Line l= (Line) fLines.get(line); - return (l.delimiter != null ? new Line(l.offset, l.length - l.delimiter.length()) : l); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineOffset(int) - */ - public int getLineOffset(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return 0; - - if (line == lines) { - Line l= (Line) fLines.get(line - 1); - return l.offset + l.length; - } - - Line l= (Line) fLines.get(line); - return l.offset; - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getNumberOfLines() - */ - public int getNumberOfLines() { - - int lines= fLines.size(); - - if (lines == 0) - return 1; - - Line l= (Line) fLines.get(lines - 1); - return (l.delimiter != null ? lines + 1 : lines); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getNumberOfLines(int, int) - */ - public int getNumberOfLines(int position, int length) throws BadLocationException { - - if (position < 0 || position + length > fTextLength) - throw new BadLocationException(); - - if (length == 0) // optimization - return 1; - - return getNumberOfLines(getLineNumberOfOffset(position), position, length); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#computeNumberOfLines(java.lang.String) - */ - public int computeNumberOfLines(String text) { - int count= 0; - int start= 0; - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); - while (delimiterInfo != null && delimiterInfo.delimiterIndex > -1) { - ++count; - start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; - delimiterInfo= nextDelimiterInfo(text, start); - } - return count; - } - - - /* ----------------- manipulation ------------------------------ */ - - - /** - * Returns the information about the first delimiter found in the given - * text starting at the given offset. - * - * @param text the text to be searched - * @param offset the offset in the given text - * @return the information of the first found delimiter or <code>null</code> - */ - protected abstract DelimiterInfo nextDelimiterInfo(String text, int offset); - - - /** - * Creates the line structure for the given text. Newly created lines - * are inserted into the line structure starting at the given - * position. Returns the number of newly created lines. - * - * @param text the text for which to create a line structure - * @param insertPosition the position at which the newly created lines are inserted - * into the tracker's line structure - * @param offset the offset of all newly created lines - * @return the number of newly created lines - */ - private int createLines(String text, int insertPosition, int offset) { - - int count= 0; - int start= 0; - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); - - - while (delimiterInfo != null && delimiterInfo.delimiterIndex > -1) { - - int index= delimiterInfo.delimiterIndex + (delimiterInfo.delimiterLength - 1); - - if (insertPosition + count >= fLines.size()) - fLines.add(new Line(offset + start, offset + index, delimiterInfo.delimiter)); - else - fLines.add(insertPosition + count, new Line(offset + start, offset + index, delimiterInfo.delimiter)); - - ++count; - start= index + 1; - delimiterInfo= nextDelimiterInfo(text, start); - } - - if (start < text.length()) { - if (insertPosition + count < fLines.size()) { - // there is a line below the current - Line l= (Line) fLines.get(insertPosition + count); - int delta= text.length() - start; - l.offset -= delta; - l.length += delta; - } else { - fLines.add(new Line(offset + start, offset + text.length() - 1, null)); - ++count; - } - } - - return count; - } - - /** - * Keeps track of the line information when text is inserted. - * Returns the number of inserted lines. - * - * @param lineNumber the line at which the insert happens - * @param offset at which the insert happens - * @param text the inserted text - * @return the number of inserted lines - * @exception BadLocationException if offset is invalid in this tracker - */ - private int insert(int lineNumber, int offset, String text) throws BadLocationException { - - if (text == null || text.length() == 0) - return 0; - - fTextLength += text.length(); - - int size= fLines.size(); - - if (size == 0 || lineNumber >= size) - return createLines(text, size, offset); - - Line line= (Line) fLines.get(lineNumber); - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); - if (delimiterInfo == null || delimiterInfo.delimiterIndex == -1) { - line.length += text.length(); - return 0; - } - - - // as there is a line break, split line but do so only if rest of line is not of length 0 - int restLength= line.offset + line.length - offset; - if (restLength > 0) { - // determine start and end of the second half of the splitted line - Line lineRest= new Line(offset, restLength); - lineRest.delimiter= line.delimiter; - // shift it by the inserted text - lineRest.offset += text.length(); - // and insert in line structure - fLines.add(lineNumber + 1, lineRest); - } - - // adapt the beginning of the splitted line - line.delimiter= delimiterInfo.delimiter; - int nextStart= offset + delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; - line.length= nextStart - line.offset; - - // insert lines for the remaining text - text= text.substring(delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength); - return createLines(text, lineNumber + 1, nextStart) + 1; - } - - /** - * Keeps track of the line information when text is removed. Returns - * whether the line at which the deletion start will thereby be deleted. - * - * @param lineNumber the lineNumber at which the deletion starts - * @param offset the offset of the first deleted character - * @param length the number of deleted characters - * @return <code>true</code> if the start line has been deleted, <code>false</code> otherwise - * @exception BadLocationException if position is unknown to the tracker - */ - private boolean remove(int lineNumber, int offset, int length) throws BadLocationException { - - if (length == 0) - return false; - - int removedLineEnds= getNumberOfLines(lineNumber, offset, length) - 1; - Line line= (Line) fLines.get(lineNumber); - - if ((lineNumber == fLines.size() - 1) && removedLineEnds > 0) { - line.length -= length; - line.delimiter= null; - } else { - - ++ lineNumber; - for (int i= 1; i <= removedLineEnds; i++) { - - if (lineNumber == fLines.size()) { - line.delimiter= null; - break; - } - - Line line2= (Line) fLines.get(lineNumber); - line.length += line2.length; - line.delimiter= line2.delimiter; - fLines.remove(lineNumber); - } - line.length -= length; - } - - fTextLength -= length; - - if (line.length == 0) { - fLines.remove(line); - return true; - } - - return false; - } - - /** - * Adapts the offset of all lines with line numbers greater than the specified - * one to the given delta. - * - * @param lineNumber the line number after which to start - * @param delta the offset delta to be applied - */ - private void adaptLineOffsets(int lineNumber, int delta) { - int size= fLines.size(); - for (int i= lineNumber + 1; i < size; i++) { - Line l= (Line) fLines.get(i); - l.offset += delta; - } - } - - /* - * @see org.eclipse.jface.text.ILineTracker#replace(int, int, java.lang.String) - */ - public void replace(int position, int length, String text) throws BadLocationException { - - int firstLine= getLineNumberOfOffset(position); - int insertLineNumber= firstLine; - - if (remove(firstLine, position, length)) - -- firstLine; - - int lastLine= firstLine + insert(insertLineNumber, position, text); - -// int lines= fLines.size(); -// if (lines > 0) { -// -// // try to collapse the first and the second line if second line is empty -// if (0 <= firstLine && firstLine + 1 < lines) { -// Line l2= (Line) fLines.get(firstLine + 1); -// if (l2.delimiter != null && l2.length == l2.delimiter.length()) { -// // line is empty -// -// // append empty line to precessor -// Line l1= (Line) fLines.get(firstLine); -// StringBuffer buffer= new StringBuffer(); -// buffer.append(l1.delimiter); -// buffer.append(l2.delimiter); -// -// // test whether this yields just one line rather then two -// DelimiterInfo info= nextDelimiterInfo(buffer.toString(), 0); -// if (info != null && info.delimiterIndex == 0 && info.delimiterLength == buffer.length()) { -// l1.length += l2.length; -// l1.delimiter += l2.delimiter; -// fLines.remove(firstLine + 1); -// -- lastLine; -// } -// } -// } -// -// // try to collapse the last inserted line with the following line -// if (lastLine < lines) { -// Line l2= (Line) fLines.get(lastLine); -// if (l2.delimiter != null && l2.length == l2.delimiter.length()) { -// // line is empty -// -// // append empty line to precessor -// Line l1= (Line) fLines.get(lastLine -1); -// StringBuffer buffer= new StringBuffer(); -// buffer.append(l1.delimiter); -// buffer.append(l2.delimiter); -// -// // test whether this yields just one line rather then two -// DelimiterInfo info= nextDelimiterInfo(buffer.toString(), 0); -// if (info != null && info.delimiterIndex == 0 && info.delimiterLength == buffer.length()) { -// l1.length += l2.length; -// l1.delimiter += l2.delimiter; -// fLines.remove(lastLine); -// } -// } -// } -// } - - int delta= -length; - if (text != null) - delta= text.length() + delta; - - if (delta != 0) - adaptLineOffsets(lastLine, delta); - } - - /* - * @see org.eclipse.jface.text.ILineTracker#set(java.lang.String) - */ - public void set(String text) { - fLines.clear(); - if (text != null) { - fTextLength= text.length(); - createLines(text, 0, 0); - } - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLineDelimiter(int) - */ - public String getLineDelimiter(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return null; - - if (line == lines) - return null; - - Line l= (Line) fLines.get(line); - return l.delimiter; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Assert.java b/org.eclipse.text/src/org/eclipse/jface/text/Assert.java deleted file mode 100644 index 611d36853e9..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Assert.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * <code>Assert</code> is useful for for embedding runtime sanity checks - * in code. The static predicate methods all test a condition and throw some - * type of unchecked exception if the condition does not hold. - * <p> - * Assertion failure exceptions, like most runtime exceptions, are - * thrown when something is misbehaving. Assertion failures are invariably - * unspecified behavior; consequently, clients should never rely on - * these being thrown (or not thrown). <b>If you find yourself in the - * position where you need to catch an assertion failure, you have most - * certainly written your program incorrectly.</b> - * </p> - * <p> - * Note that an <code>assert</code> statement is slated to be added to the - * Java language in JDK 1.4, rending this class obsolete. - * </p> - */ -public final class Assert { - - /** - * <code>AssertionFailedException</code> is a runtime exception thrown - * by some of the methods in <code>Assert</code>. - * <p> - * This class is not declared public to prevent some misuses; programs that catch - * or otherwise depend on assertion failures are susceptible to unexpected - * breakage when assertions in the code are added or removed. - * </p> - */ - private static class AssertionFailedException extends RuntimeException { - - /** - * Constructs a new exception. - */ - public AssertionFailedException() { - } - - /** - * Constructs a new exception with the given message. - * - * @param detail the detailed message - */ - public AssertionFailedException(String detail) { - super(detail); - } - } - - /* This class is not intended to be instantiated. */ - private Assert() { - } - - /** - * Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * - * @param expression the outcome of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression) { - // succeed as quickly as possible - if (expression) { - return true; - } - return isLegal(expression, "");//$NON-NLS-1$ - } - - /** - * Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcome of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException("assertion failed; " + message); //$NON-NLS-1$ - return expression; - } - - /** - * Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * <p> - * As a general rule, parameters passed to API methods must not be - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Similarly, results returned from API methods are never - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Implementations are encouraged to make regular use of - * <code>Assert.isNotNull</code> to ensure that <code>null</code> - * parameters are detected as early as possible. - * </p> - * - * @param object the value to test - * @exception Throwable an unspecified unchecked exception if the object - * is <code>null</code> - */ - public static void isNotNull(Object object) { - // succeed as quickly as possible - if (object != null) { - return; - } - isNotNull(object, "");//$NON-NLS-1$ - } - - /** - * Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * <p> - * As a general rule, parameters passed to API methods must not be - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Similarly, results returned from API methods are never - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Implementations are encouraged to make regular use of - * <code>Assert.isNotNull</code> to ensure that <code>null</code> - * parameters are detected as early as possible. - * </p> - * - * @param object the value to test - * @param message the message to include in the exception - * @exception Throwable an unspecified unchecked exception if the object - * is <code>null</code> - */ - public static void isNotNull(Object object, String message) { - if (object == null) - throw new AssertionFailedException("null argument;" + message);//$NON-NLS-1$ - } - - /** - * Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param expression the outcome of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression) { - // succeed as quickly as possible - if (expression) { - return true; - } - return isTrue(expression, "");//$NON-NLS-1$ - } - - /** - * Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcome of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression, String message) { - if (!expression) - throw new AssertionFailedException("Assertion failed: "+message);//$NON-NLS-1$ - return expression; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java b/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java deleted file mode 100644 index 2ad4478451d..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Indicates the attempt to access a non-existing position. The attempt has been - * performed on a text store such as a document or string. - */ -public class BadLocationException extends Exception { - - /** - * Creates a new bad location exception. - */ - public BadLocationException() { - super(); - } - - /** - * Creates a new bad location exception. - * - * @param message the exception message - */ - public BadLocationException(String message) { - super(message); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/BadPartitioningException.java b/org.eclipse.text/src/org/eclipse/jface/text/BadPartitioningException.java deleted file mode 100644 index 95a87ded38b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/BadPartitioningException.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Represents the attempt to refer to a non-existing document partitioning. - * - * @see org.eclipse.jface.text.IDocument - * @see org.eclipse.jface.text.IDocumentExtension3 - * @since 3.0 - */ -public class BadPartitioningException extends Exception { - - /** - * Creates a new bad partitioning exception. - */ - public BadPartitioningException() { - } - - /** - * Creates a new bad partitioning exception. - * - * @param message message describing the exception - */ - public BadPartitioningException(String message) { - super(message); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java b/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java deleted file mode 100644 index 379f2fc356c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Indicates the attempt to access a non-existing position - * category in a document. - * - * @see org.eclipse.jface.text.IDocument - */ -public class BadPositionCategoryException extends Exception { - - /** - * Creates a new bad position category exception. - */ - public BadPositionCategoryException() { - super(); - } - - /** - * Creates a new bad position category exception. - * - * @param message the exception's message - */ - public BadPositionCategoryException(String message) { - super(message); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java deleted file mode 100644 index 5db6b66b950..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Standard implementation of a generic - * {@link org.eclipse.jface.text.ILineTracker}. - * <p> - * The line tracker can be configured with the set of legal line delimiters. - * Line delimiters are unconstrained. The line delimiters are used to compute - * the tracker's line structure. In the case of overlapping line delimiters, the - * longest line delimiter is given precedence of the shorter ones. - * <p> - * This class is not intended to be subclassed. - */ -public class ConfigurableLineTracker extends AbstractLineTracker { - - - /** The strings which are considered being the line delimiter */ - private String[] fDelimiters; - /** A predefined delimiter information which is always reused as return value */ - private DelimiterInfo fDelimiterInfo= new DelimiterInfo(); - - - /** - * Creates a standard line tracker for the given line delimiters. - * - * @param legalLineDelimiters the tracker's legal line delimiters, - * may not be <code>null</code> and must be longer than 0 - */ - public ConfigurableLineTracker(String[] legalLineDelimiters) { - Assert.isTrue(legalLineDelimiters != null && legalLineDelimiters.length > 0); - fDelimiters= legalLineDelimiters; - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLegalLineDelimiters() - */ - public String[] getLegalLineDelimiters() { - return fDelimiters; - } - - /* - * @see org.eclipse.jface.text.AbstractLineTracker#nextDelimiterInfo(java.lang.String, int) - */ - protected DelimiterInfo nextDelimiterInfo(String text, int offset) { - int[] info= TextUtilities.indexOf(fDelimiters, text, offset); - if (info[0] == -1) - return null; - - fDelimiterInfo.delimiterIndex= info[0]; - fDelimiterInfo.delimiter= fDelimiters[info[1]]; - fDelimiterInfo.delimiterLength= fDelimiterInfo.delimiter.length(); - return fDelimiterInfo; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java deleted file mode 100644 index 291003e9826..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Standard implementation of {@link org.eclipse.jface.text.ILineTracker}. - * <p> - * The line tracker considers the three common line delimiters which are '\n', - * '\r', '\r\n'. - * <p> - * This class is not intended to be subclassed. - */ -public class DefaultLineTracker extends AbstractLineTracker { - - /** The predefined delimiters of this tracker */ - public final static String[] DELIMITERS= { "\r", "\n", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ - /** A predefined delimiter information which is always reused as return value */ - private DelimiterInfo fDelimiterInfo= new DelimiterInfo(); - - - /** - * Creates a standard line tracker. - */ - public DefaultLineTracker() { - } - - /* - * @see org.eclipse.jface.text.ILineTracker#getLegalLineDelimiters() - */ - public String[] getLegalLineDelimiters() { - return DELIMITERS; - } - - /* - * @see org.eclipse.jface.text.AbstractLineTracker#nextDelimiterInfo(java.lang.String, int) - */ - protected DelimiterInfo nextDelimiterInfo(String text, int offset) { - - char ch; - int length= text.length(); - for (int i= offset; i < length; i++) { - - ch= text.charAt(i); - if (ch == '\r') { - - if (i + 1 < length) { - if (text.charAt(i + 1) == '\n') { - fDelimiterInfo.delimiter= DELIMITERS[2]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 2; - return fDelimiterInfo; - } - } - - fDelimiterInfo.delimiter= DELIMITERS[0]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 1; - return fDelimiterInfo; - - } else if (ch == '\n') { - - fDelimiterInfo.delimiter= DELIMITERS[1]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 1; - return fDelimiterInfo; - } - } - - return null; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java deleted file mode 100644 index b8c72476f3b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Default implementation of {@link org.eclipse.jface.text.IPositionUpdater}.<p> - * A default position updater must be configured with the position category - * whose positions it will update. Other position categories are not affected - * by this updater.<p> - * This implementation follows the following specification: - * <ul> - * <li> Inserting or deleting text before the position shifts the position accordingly. - * <li> Inserting text at the position offset shifts the position accordingly. - * <li> Inserting or deleting text completely surrounded by the position shrinks or stretches the position. - * <li> Inserting or deleting text after a position does not affect the position. - * <li> Deleting text which completely contains the position deletes the position. - * <li> Replacing text overlapping with the position considered as a sequence of first - * deleting the replaced text and afterwards inserting the new text. Thus, a - * position might first be shifted and shrink and then be stretched. - * </ul> - * This class can be used as is or be adapted by subclasses. Fields are protected to - * allow subclasses direct access. Because of the frequency with which position updaters - * are used this is a performance decision. - */ -public class DefaultPositionUpdater implements IPositionUpdater { - - /** The position category the updater draws responsible for */ - private String fCategory; - - /** Caches the currently investigated position */ - protected Position fPosition; - /** - * Remembers the original state of the investigated position - * @since 2.1 - */ - protected Position fOriginalPosition= new Position(0, 0); - /** Caches the offset of the replaced text */ - protected int fOffset; - /** Caches the length of the replaced text */ - protected int fLength; - /** Caches the length of the newly inserted text */ - protected int fReplaceLength; - /** Catches the document */ - protected IDocument fDocument; - - - /** - * Creates a new default position updater for the given category. - * - * @param category the category the updater is responsible for - */ - public DefaultPositionUpdater(String category) { - fCategory= category; - } - - /** - * Returns the category this updater is responsible for. - * - * @return the category this updater is responsible for - */ - protected String getCategory() { - return fCategory; - } - - /** - * Returns whether the current event describes a well formed replace - * by which the current position is directly affected. - * - * @return <code>true</code> the current position is directly affected - * @since 3.0 - */ - protected boolean isAffectingReplace() { - return fLength > 0 && fReplaceLength > 0 && fPosition.length < fOriginalPosition.length; - } - - /** - * Adapts the currently investigated position to an insertion. - */ - protected void adaptToInsert() { - - int myStart= fPosition.offset; - int myEnd= fPosition.offset + fPosition.length - (isAffectingReplace() ? 0 : 1); - myEnd= Math.max(myStart, myEnd); - - int yoursStart= fOffset; - int yoursEnd= fOffset + fReplaceLength -1; - yoursEnd= Math.max(yoursStart, yoursEnd); - - if (myEnd < yoursStart) - return; - - if (fLength <= 0) { - - if (myStart < yoursStart) - fPosition.length += fReplaceLength; - else - fPosition.offset += fReplaceLength; - - } else { - - if (myStart <= yoursStart && fOriginalPosition.offset <= yoursStart) - fPosition.length += fReplaceLength; - else - fPosition.offset += fReplaceLength; - } - } - - /** - * Adapts the currently investigated position to a deletion. - */ - protected void adaptToRemove() { - - int myStart= fPosition.offset; - int myEnd= fPosition.offset + fPosition.length -1; - myEnd= Math.max(myStart, myEnd); - - int yoursStart= fOffset; - int yoursEnd= fOffset + fLength -1; - yoursEnd= Math.max(yoursStart, yoursEnd); - - if (myEnd < yoursStart) - return; - - if (myStart <= yoursStart) { - - if (yoursEnd <= myEnd) - fPosition.length -= fLength; - else - fPosition.length -= (myEnd - yoursStart +1); - - } else if (yoursStart < myStart) { - - if (yoursEnd < myStart) - fPosition.offset -= fLength; - else { - fPosition.offset -= (myStart - yoursStart); - fPosition.length -= (yoursEnd - myStart +1); - } - - } - - // validate position to allowed values - if (fPosition.offset < 0) - fPosition.offset= 0; - - if (fPosition.length < 0) - fPosition.length= 0; - } - - /** - * Adapts the currently investigated position to the replace operation. - * First it checks whether the change replaces the whole range of the position. - * If not, it performs first the deletion of the previous text and afterwards - * the insertion of the new text. - */ - protected void adaptToReplace() { - - if (fPosition.offset == fOffset && fPosition.length == fLength && fPosition.length > 0) { - - // replace the whole range of the position - fPosition.length += (fReplaceLength - fLength); - if (fPosition.length < 0) { - fPosition.offset += fPosition.length; - fPosition.length= 0; - } - - } else { - - if (fLength > 0) - adaptToRemove(); - - if (fReplaceLength > 0) - adaptToInsert(); - } - } - - /** - * Determines whether the currently investigated position has been deleted by - * the replace operation specified in the current event. If so, it deletes - * the position and removes it from the document's position category. - * - * @return <code>true</code> if position has been deleted - */ - protected boolean notDeleted() { - - if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) { - - fPosition.delete(); - - try { - fDocument.removePosition(fCategory, fPosition); - } catch (BadPositionCategoryException x) { - } - - return false; - } - - return true; - } - - /* - * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) - */ - public void update(DocumentEvent event) { - - try { - - - fOffset= event.getOffset(); - fLength= event.getLength(); - fReplaceLength= (event.getText() == null ? 0 : event.getText().length()); - fDocument= event.getDocument(); - - Position[] category= fDocument.getPositions(fCategory); - for (int i= 0; i < category.length; i++) { - - fPosition= category[i]; - fOriginalPosition.offset= fPosition.offset; - fOriginalPosition.length= fPosition.length; - - if (notDeleted()) - adaptToReplace(); - } - - } catch (BadPositionCategoryException x) { - // do nothing - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Document.java b/org.eclipse.text/src/org/eclipse/jface/text/Document.java deleted file mode 100644 index 5d8254b310b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Document.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Default document implementation. Uses a - * {@link org.eclipse.jface.text.GapTextStore}as default text store and a - * {@link org.eclipse.jface.text.SequentialRewriteTextStore}when in sequential - * rewrite mode. - * <p> - * The used line tracker considers the following strings as line delimiters - * "\n", "\r", "\r\n". - * <p> - * The document is ready to use. It has a default position category for which a - * default position updater is installed. - * - * @see org.eclipse.jface.text.GapTextStore - * @see org.eclipse.jface.text.SequentialRewriteTextStore - */ -public class Document extends AbstractDocument { - - - /** - * Creates a new empty document. - */ - public Document() { - super(); - setTextStore(new GapTextStore(50, 300)); - setLineTracker(new DefaultLineTracker()); - completeInitialization(); - } - - /** - * Creates a new document with the given initial content. - * - * @param initialContent the document's initial content - */ - public Document(String initialContent) { - super(); - setTextStore(new GapTextStore(50, 300)); - setLineTracker(new DefaultLineTracker()); - getStore().set(initialContent); - getTracker().set(initialContent); - completeInitialization(); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#startSequentialRewrite(boolean) - * @since 2.0 - */ - public void startSequentialRewrite(boolean normalized) { - ITextStore store= new SequentialRewriteTextStore(getStore()); - setTextStore(store); - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension#stopSequentialRewrite() - * @since 2.0 - */ - public void stopSequentialRewrite() { - if (getStore() instanceof SequentialRewriteTextStore) { - SequentialRewriteTextStore srws= (SequentialRewriteTextStore) getStore(); - ITextStore source= srws.getSourceStore(); - setTextStore(source); - srws.dispose(); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java deleted file mode 100644 index d47b29e1265..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Specification of changes applied to documents. All changes are represented as - * replace commands, i.e. specifying a document range whose text gets replaced - * with different text. In addition to this information, the event also contains - * the changed document. - * - * @see org.eclipse.jface.text.IDocument - */ -public class DocumentEvent { - - /** The changed document */ - public IDocument fDocument; - /** The document offset */ - public int fOffset; - /** Length of the replaced document text */ - public int fLength; - /** Text inserted into the document */ - public String fText; - - /** - * Creates a new document event. - * - * @param doc the changed document - * @param offset the offset of the replaced text - * @param length the length of the replaced text - * @param text the substitution text - */ - public DocumentEvent(IDocument doc, int offset, int length, String text) { - - Assert.isNotNull(doc); - Assert.isTrue(offset >= 0); - Assert.isTrue(length >= 0); - - fDocument= doc; - fOffset= offset; - fLength= length; - fText= text; - } - - /** - * Creates a new, not initialized document event. - */ - public DocumentEvent() { - } - - /** - * Returns the changed document. - * - * @return the changed document - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * Returns the offset of the change. - * - * @return the offset of the change - */ - public int getOffset() { - return fOffset; - } - - /** - * Returns the length of the replaced text. - * - * @return the length of the replaced text - */ - public int getLength() { - return fLength; - } - - /** - * Returns the text that has been inserted. - * - * @return the text that has been inserted - */ - public String getText() { - return fText; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java deleted file mode 100644 index 986da9d9c29..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * Event describing the change of document partitionings. - * - * @see org.eclipse.jface.text.IDocumentExtension3 - * @since 3.0 - */ -public class DocumentPartitioningChangedEvent { - - /** The document whose partitionings changed */ - private final IDocument fDocument; - /** The map of partitionings to changed regions. */ - private final Map fMap= new HashMap(); - - - /** - * Creates a new document partitioning changed event for the given document. - * Initially this event is empty, i.e. does not describe any change. - * - * @param document the changed document - */ - public DocumentPartitioningChangedEvent(IDocument document) { - fDocument= document; - } - - /** - * Returns the changed document. - * - * @return the changed document - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * Returns the changed region of the given partitioning or <code>null</code> - * if the given partitioning did not change. - * - * @param partitioning the partitioning - * @return the changed region of the given partitioning or <code>null</code> - */ - public IRegion getChangedRegion(String partitioning) { - return (IRegion) fMap.get(partitioning); - } - - /** - * Returns the set of changed partitionings. - * - * @return the set of changed partitionings - */ - public String[] getChangedPartitionings() { - String[] partitionings= new String[fMap.size()]; - fMap.keySet().toArray(partitionings); - return partitionings; - } - - /** - * Sets the specified range as changed region for the given partitioning. - * - * @param partitioning the partitioning - * @param offset the region offset - * @param length the region length - */ - public void setPartitionChange(String partitioning, int offset, int length) { - Assert.isNotNull(partitioning); - fMap.put(partitioning, new Region(offset, length)); - } - - /** - * Returns <code>true</code> if the set of changed partitionings is empty, - * <code>false</code> otherwise. - * - * @return <code>true</code> if the set of changed partitionings is empty - */ - public boolean isEmpty() { - return fMap.isEmpty(); - } - - /** - * Returns the coverage of this event. This is the minimal region that - * contains all changed regions of all changed partitionings. - * - * @return the coverage of this event - */ - public IRegion getCoverage() { - if (fMap.isEmpty()) - return new Region(0, 0); - - int offset= -1; - int endOffset= -1; - Iterator e= fMap.values().iterator(); - while (e.hasNext()) { - IRegion r= (IRegion) e.next(); - - if (offset < 0 || r.getOffset() < offset) - offset= r.getOffset(); - - int end= r.getOffset() + r.getLength(); - if (end > endOffset) - endOffset= end; - } - - return new Region(offset, endOffset - offset); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java b/org.eclipse.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java deleted file mode 100644 index 8b82bfba8f3..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java +++ /dev/null @@ -1,317 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - - -/** - * Provides search and replace operations on - * {@link org.eclipse.jface.text.IDocument}. - * <p> - * Replaces - * {@link org.eclipse.jface.text.IDocument#search(int, String, boolean, boolean, boolean)}. - * - * @since 3.0 - */ -public class FindReplaceDocumentAdapter implements CharSequence { - - /** - * Internal type for operation codes. - */ - private static class FindReplaceOperationCode { - } - - // Find/replace operation codes. - private static final FindReplaceOperationCode FIND_FIRST= new FindReplaceOperationCode(); - private static final FindReplaceOperationCode FIND_NEXT= new FindReplaceOperationCode(); - private static final FindReplaceOperationCode REPLACE= new FindReplaceOperationCode(); - private static final FindReplaceOperationCode REPLACE_FIND_NEXT= new FindReplaceOperationCode(); - - /** - * The adapted document. - */ - private IDocument fDocument; - - /** - * State for findReplace. - */ - private FindReplaceOperationCode fFindReplaceState= null; - - /** - * The matcher used in findReplace. - */ - private Matcher fFindReplaceMatcher; - - /** - * The match offset from the last findReplace call. - */ - private int fFindReplaceMatchOffset; - - /** - * Constructs a new find replace document adapter. - * - * @param document the adapted document - */ - public FindReplaceDocumentAdapter(IDocument document) { - Assert.isNotNull(document); - fDocument= document; - } - - /** - * Returns the location of a given string in this adapter's document based on a set of search criteria. - * - * @param startOffset document offset at which search starts - * @param findString the string to find - * @param forwardSearch the search direction - * @param caseSensitive indicates whether lower and upper case should be distinguished - * @param wholeWord indicates whether the findString should be limited by white spaces as - * defined by Character.isWhiteSpace. Must not be used in combination with <code>regExSearch</code>. - * @param regExSearch if <code>true</code> findString represents a regular expression - * Must not be used in combination with <code>wholeWord</code>. - * @return the find or replace region or <code>null</code> if there was no match - * @throws BadLocationException if startOffset is an invalid document offset - * @throws PatternSyntaxException if a regular expression has invalid syntax - */ - public IRegion find(int startOffset, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) throws BadLocationException { - Assert.isTrue(!(regExSearch && wholeWord)); - - // Adjust offset to special meaning of -1 - if (startOffset == -1 && forwardSearch) - startOffset= 0; - if (startOffset == -1 && !forwardSearch) - startOffset= length() - 1; - - return findReplace(FIND_FIRST, startOffset, findString, null, forwardSearch, caseSensitive, wholeWord, regExSearch); - } - - /** - * Stateful findReplace executes a FIND, REPLACE, REPLACE_FIND or FIND_FIRST operation. - * In case of REPLACE and REPLACE_FIND it sends a <code>DocumentEvent</code> to all - * registered <code>IDocumentListener</code>. - * - * @param startOffset document offset at which search starts - * this value is only used in the FIND_FIRST operation and otherwise ignored - * @param findString the string to find - * this value is only used in the FIND_FIRST operation and otherwise ignored - * @param replaceText the string to replace the current match - * this value is only used in the REPLACE and REPLACE_FIND operations and otherwise ignored - * @param forwardSearch the search direction - * @param caseSensitive indicates whether lower and upper case should be distinguished - * @param wholeWord indicates whether the findString should be limited by white spaces as - * defined by Character.isWhiteSpace. Must not be used in combination with <code>regExSearch</code>. - * @param regExSearch if <code>true</code> this operation represents a regular expression - * Must not be used in combination with <code>wholeWord</code>. - * @param operationCode specifies what kind of operation is executed - * @return the find or replace region or <code>null</code> if there was no match - * @throws BadLocationException if startOffset is an invalid document offset - * @throws IllegalStateException if a REPLACE or REPLACE_FIND operation is not preceded by a successful FIND operation - * @throws PatternSyntaxException if a regular expression has invalid syntax - */ - private IRegion findReplace(final FindReplaceOperationCode operationCode, int startOffset, String findString, String replaceText, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) throws BadLocationException { - - // Validate option combinations - Assert.isTrue(!(regExSearch && wholeWord)); - - // Validate state - if ((operationCode == REPLACE || operationCode == REPLACE_FIND_NEXT) && (fFindReplaceState != FIND_FIRST && fFindReplaceState != FIND_NEXT)) - throw new IllegalStateException("illegal findReplace state: cannot replace without preceding find"); //$NON-NLS-1$ - - if (operationCode == FIND_FIRST) { - // Reset - - if (findString == null || findString.length() == 0) - return null; - - // Validate start offset - if (startOffset < 0 || startOffset >= length()) - throw new BadLocationException(); - - int patternFlags= 0; - - if (regExSearch) - patternFlags |= Pattern.MULTILINE; - - if (!caseSensitive) - patternFlags |= Pattern.CASE_INSENSITIVE; - - if (wholeWord) - findString= "\\b" + findString + "\\b"; //$NON-NLS-1$ //$NON-NLS-2$ - - if (!regExSearch && !wholeWord) - findString= asRegPattern(findString); - - fFindReplaceMatchOffset= startOffset; - if (fFindReplaceMatcher != null && fFindReplaceMatcher.pattern().pattern().equals(findString) && fFindReplaceMatcher.pattern().flags() == patternFlags) { - /* - * Commented out for optimization: - * The call is not needed since FIND_FIRST uses find(int) which resets the matcher - */ - // fFindReplaceMatcher.reset(); - } else { - Pattern pattern= Pattern.compile(findString, patternFlags); - fFindReplaceMatcher= pattern.matcher(this); - } - } - - // Set state - fFindReplaceState= operationCode; - - if (operationCode == REPLACE || operationCode == REPLACE_FIND_NEXT) { - if (regExSearch) { - Pattern pattern= fFindReplaceMatcher.pattern(); - Matcher replaceTextMatcher= pattern.matcher(fFindReplaceMatcher.group()); - try { - replaceText= replaceTextMatcher.replaceFirst(replaceText); - } catch (IndexOutOfBoundsException ex) { - throw new PatternSyntaxException(ex.getLocalizedMessage(), replaceText, -1); - } - } - - int offset= fFindReplaceMatcher.start(); - fDocument.replace(offset, fFindReplaceMatcher.group().length(), replaceText); - - if (operationCode == REPLACE) { - return new Region(offset, replaceText.length()); - } - } - - if (operationCode != REPLACE) { - if (forwardSearch) { - - boolean found= false; - if (operationCode == FIND_FIRST) - found= fFindReplaceMatcher.find(startOffset); - else - found= fFindReplaceMatcher.find(); - - if (operationCode == REPLACE_FIND_NEXT) - fFindReplaceState= FIND_NEXT; - - if (found && fFindReplaceMatcher.group().length() > 0) { - return new Region(fFindReplaceMatcher.start(), fFindReplaceMatcher.group().length()); - } else { - return null; - } - } else { // backward search - - boolean found= fFindReplaceMatcher.find(0); - int index= -1; - int length= -1; - while (found && fFindReplaceMatcher.start() <= fFindReplaceMatchOffset) { - index= fFindReplaceMatcher.start(); - length= fFindReplaceMatcher.group().length(); - found= fFindReplaceMatcher.find(index + 1); - } - fFindReplaceMatchOffset= index; - if (index > -1) { - // must set matcher to correct position - fFindReplaceMatcher.find(index); - return new Region(index, length); - } else - return null; - } - } - return null; - } - - /** - * Converts a non-regex string to a pattern - * that can be used with the regex search engine. - * - * @param string the non-regex pattern - * @return the string converted to a regex pattern - */ - private String asRegPattern(String string) { - StringBuffer out= new StringBuffer(string.length()); - boolean quoting= false; - - for (int i= 0, length= string.length(); i < length; i++) { - char ch= string.charAt(i); - if (ch == '\\') { - if (quoting) { - out.append("\\E"); //$NON-NLS-1$ - quoting= false; - } - out.append("\\\\"); //$NON-NLS-1$ - continue; - } - if (!quoting) { - out.append("\\Q"); //$NON-NLS-1$ - quoting= true; - } - out.append(ch); - } - if (quoting) - out.append("\\E"); //$NON-NLS-1$ - - return out.toString(); - } - - /** - * Substitutes the previous match with the given text. - * Sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>. - * - * @param text the substitution text - * @param regExReplace if <code>true</code> <code>text</code> represents a regular expression - * @return the replace region or <code>null</code> if there was no match - * @throws BadLocationException if startOffset is an invalid document offset - * @throws IllegalStateException if a REPLACE or REPLACE_FIND operation is not preceded by a successful FIND operation - * @throws PatternSyntaxException if a regular expression has invalid syntax - * - * @see DocumentEvent - * @see IDocumentListener - */ - public IRegion replace(String text, boolean regExReplace) throws BadLocationException { - return findReplace(REPLACE, -1, null, text, false, false, false, regExReplace); - } - - // ---------- CharSequence implementation ---------- - - /* - * @see java.lang.CharSequence#length() - */ - public int length() { - return fDocument.getLength(); - } - - /* - * @see java.lang.CharSequence#charAt(int) - */ - public char charAt(int index) { - try { - return fDocument.getChar(index); - } catch (BadLocationException e) { - throw new IndexOutOfBoundsException(); - } - } - - /* - * @see java.lang.CharSequence#subSequence(int, int) - */ - public CharSequence subSequence(int start, int end) { - try { - return fDocument.get(start, end - start); - } catch (BadLocationException e) { - throw new IndexOutOfBoundsException(); - } - } - - /* - * @see java.lang.Object#toString() - */ - public String toString() { - return fDocument.get(); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java deleted file mode 100644 index d6a8c4e3612..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Implements a gap managing text store. The gap text store - * relies on the assumption that subsequent changes of a document are co-located. - * The start of the gap is always moved to the location of the last change. The - * size of the gap varies between the low water mark and the high water mark. <p> - * This class is not intended to be subclassed. - */ -public class GapTextStore implements ITextStore { - - /** The store's content */ - private char[] fContent= new char[0]; - /** Starting index of the gap */ - private int fGapStart= -1; - /** End index of the gap */ - private int fGapEnd= -1; - - /** The high water mark. If the gap is larger than this, it will be shrunken */ - private int fHighWatermark; - /** The low water mark, If this gap is smaller than this, it will be extended */ - private int fLowWatermark; - - /** - * Creates a new empty text store using the specified low and high watermarks. - * - * @param lowWatermark if this gap is ever smaller than this, it will automatically be extended - * @param highWatermark if the gap is ever larger than this, it will automatically be shrunken - */ - public GapTextStore(int lowWatermark, int highWatermark) { - Assert.isTrue(lowWatermark < highWatermark); - fLowWatermark= lowWatermark; - fHighWatermark= highWatermark; - } - - /** - * Adjusts the gap so that is at the right offset and capable of handling - * the addition of a specified number of characters without having to be shifted. - * The <code>sizeHint</code> represents the range that will be filled afterwards. - * If the gap is already at the right offset, it must only be - * resized if it will be no longer between the low and high watermark. However, - * on delete (sizeHint < 0) at the edges of the gap, the gap is only enlarged. - * - * @param offset the offset at which the change happens - * @param sizeHint the number of character which will be inserted - */ - private void adjustGap(int offset, int sizeHint) { - - if (offset == fGapStart) { - int size= (fGapEnd - fGapStart) - sizeHint; - if (fLowWatermark <= size && size <= fHighWatermark) - return; - } - - moveAndResizeGap(offset, sizeHint); - } - - /** - * Moves the gap to the specified offset and adjust its size to the - * anticipated change size. The given size represents the expected - * range of the gap that will be filled after the gap has been moved. - * Thus the gap is resized to actual size + the specified size and - * moved to the given offset. - * - * @param offset the offset where the gap is moved to - * @param size the anticipated size of the change - */ - private void moveAndResizeGap(int offset, int size) { - - char[] content= null; - int oldSize= fGapEnd - fGapStart; - int newSize= fHighWatermark + size; - - - if (newSize < 0) { - - if (oldSize > 0) { - content= new char[fContent.length - oldSize]; - System.arraycopy(fContent, 0, content, 0, fGapStart); - System.arraycopy(fContent, fGapEnd, content, fGapStart, content.length - fGapStart); - fContent= content; - } - fGapStart= fGapEnd= offset; - return; - } - - - content= new char[fContent.length + (newSize - oldSize)]; - - int newGapStart= offset; - int newGapEnd= newGapStart + newSize; - - if (oldSize == 0) { - - System.arraycopy(fContent, 0, content, 0, newGapStart); - System.arraycopy(fContent, newGapStart, content, newGapEnd, content.length - newGapEnd); - - } else if (newGapStart < fGapStart) { - - int delta= fGapStart - newGapStart; - System.arraycopy(fContent, 0, content, 0, newGapStart); - System.arraycopy(fContent, newGapStart, content, newGapEnd, delta); - System.arraycopy(fContent, fGapEnd, content, newGapEnd + delta, fContent.length - fGapEnd); - - } else { - - int delta= newGapStart - fGapStart; - System.arraycopy(fContent, 0, content, 0, fGapStart); - System.arraycopy(fContent, fGapEnd, content, fGapStart, delta); - System.arraycopy(fContent, fGapEnd + delta, content, newGapEnd, content.length - newGapEnd); - } - - - fContent= content; - fGapStart= newGapStart; - fGapEnd= newGapEnd; - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int) - */ - public char get(int offset) { - - if (offset < fGapStart) - return fContent[offset]; - - int gapLength= fGapEnd - fGapStart; - return fContent[offset + gapLength]; - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int, int) - */ - public String get(int offset, int length) { - - int end= offset + length; - - if (fContent == null) - return ""; //$NON-NLS-1$ - - if (end <= fGapStart) - return new String(fContent, offset, length); - - if (fGapStart < offset) { - int gapLength= fGapEnd - fGapStart; - return new String(fContent, offset + gapLength , length); - } - - StringBuffer buf= new StringBuffer(); - buf.append(fContent, offset, fGapStart - offset); - buf.append(fContent, fGapEnd, end - fGapStart); - return buf.toString(); - } - - /* - * @see org.eclipse.jface.text.ITextStore#getLength() - */ - public int getLength() { - int length= fGapEnd - fGapStart; - return (fContent.length - length); - } - - /* - * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String) - */ - public void replace(int offset, int length, String text) { - - int textLength= (text == null ? 0 : text.length()); - - // handle delete at the edges of the gap - if (textLength == 0) { - if (offset <= fGapStart && offset + length >= fGapStart && fGapStart > -1 && fGapEnd > -1) { - length -= fGapStart - offset; - fGapStart= offset; - fGapEnd += length; - return; - } - } - - // move gap - adjustGap(offset + length, textLength - length); - - // overwrite - int min= Math.min(textLength, length); - for (int i= offset, j= 0; i < offset + min; i++, j++) - fContent[i]= text.charAt(j); - - if (length > textLength) { - // enlarge the gap - fGapStart -= (length - textLength); - } else if (textLength > length) { - // shrink gap - fGapStart += (textLength - length); - for (int i= length; i < textLength; i++) - fContent[offset + i]= text.charAt(i); - } - } - - /** - * Sets the content to <code>text</code> and removes the gap - * since there are no sensible predictions about - * where the next change will occur. - * - * @see ITextStore#set(String) - */ - public void set(String text) { - - if (text == null) - text= ""; //$NON-NLS-1$ - - fContent= text.toCharArray(); - - fGapStart= -1; - fGapEnd= -1; - } - - /** - * Returns a copy of the content of this text store. - * For internal use only. - * - * @return a copy of the content of this text store - */ - protected String getContentAsString() { - return new String(fContent); - } - - /** - * Returns the start index of the gap managed by this text store. - * For internal use only. - * - * @return the start index of the gap managed by this text store - */ - protected int getGapStartIndex() { - return fGapStart; - } - - /** - * Returns the end index of the gap managed by this text store. - * For internal use only. - * - * @return the end index of the gap managed by this text store - */ - protected int getGapEndIndex() { - return fGapEnd; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java deleted file mode 100644 index eff3df75031..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java +++ /dev/null @@ -1,637 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * An <code>IDocument</code> represents text providing support for - * <ul> - * <li> text manipulation - * <li> positions - * <li> partitions - * <li> line information - * <li> document change listeners - * <li> document partition change listeners - * </ul> - * - * A document allows to set its content and to manipulate it. For manipulation - * a document provides the <code>replace</code> method which substitutes a given - * string for a specified text range in the document. On each document change, all - * registered document listeners are informed exactly once. - * - * Positions are stickers to the document's text that are updated when the - * document is changed. Positions are updated by {@link org.eclipse.jface.text.IPositionUpdater}s. Position - * updaters are managed as a list. The list defines the sequence in which position - * updaters are invoked. This way, position updaters may rely on each other. - * Positions are grouped into categories. A category is a ordered list of positions. - * the document defines the order of position in a category based on the position's offset - * based on the implementation of the method <code>computeIndexInCategory</code>. - * Each document must support a default position category whose name is specified by this - * interface.<p> - * - * A document can be considered consisting of a sequence of not overlapping partitions. - * A partition is defined by its offset, its length, and its type. Partitions are - * updated on every document manipulation and ensured to be up-to-date when the document - * listeners are informed. A document uses an <code>IDocumentPartitioner</code> to - * manage its partitions. A document may be unpartitioned which happens when there is no - * partitioner. In this case, the document is considered as one single partition of a - * default type. The default type is specified by this interface. If a document change - * changes the document's partitioning all registered partitioning listeners are - * informed exactly once. The extension interface {@link org.eclipse.jface.text.IDocumentExtension3} - * introduced in version 3.0 extends the concept of partitions and allows a document to - * not only manage one but multiple partitioning. Each partitioning has an id which must - * be used to refer to a particular partitioning.<p> - * - * An <code>IDocument</code> provides methods to map line numbers and character - * positions onto each other based on the document's line delimiters. When moving text - * between documents using different line delimiters, the text must be converted to - * use the target document's line delimiters.<p> - * - * <code>IDocument</code> throws <code>BadLocationException</code> if the parameters of - * queries or manipulation requests are not inside the bounds of the document. The purpose - * of this style of exception handling is - * <ul> - * <li> prepare document for multi-thread access - * <li> allow clients to implement backtracking recovery methods - * <li> prevent clients from up-front contract checking when dealing with documents. - * </ul> - * - * A document support for searching has deprecated since version 3.0. The recommended way - * for searching is to use a {@link org.eclipse.jface.text.FindReplaceDocumentAdapter}.<p> - * - * In order to provide backward compatibility for clients of <code>IDocument</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.IDocumentExtension} since version 2.0 introducing the concept - * of post notification replaces in order to allow document listeners to manipulate the document - * while receiving a document change notification </li> - * <li> {@link org.eclipse.jface.text.IDocumentExtension2} since version 2.1 introducing configuration - * methods for post notification replaces and document change notification. </li> - * <li> {@link org.eclipse.jface.text.IDocumentExtension3} since version 3.0 replacing the original - * partitioning concept by allowing multiple partitionings at the same time and introducing zero- - * length partitions in conjunction with the distinction between open and closed partitions. </li> - * </ul> - * - * Clients may implement this interface and its extension interfaces or use the default - * implementation provided by <code>AbstractDocument</code> and <code>Document</code>. - * - * @see org.eclipse.jface.text.IDocumentExtension - * @see org.eclipse.jface.text.IDocumentExtension2 - * @see org.eclipse.jface.text.IDocumentExtension3 - * @see org.eclipse.jface.text.Position - * @see org.eclipse.jface.text.IPositionUpdater - * @see org.eclipse.jface.text.IDocumentPartitioner - * @see org.eclipse.jface.text.ILineTracker - * @see org.eclipse.jface.text.IDocumentListener - * @see org.eclipse.jface.text.IDocumentPartitioningListener - */ -public interface IDocument { - - - /** - * The identifier of the default position category. - */ - final static String DEFAULT_CATEGORY= "__dflt_position_category"; //$NON-NLS-1$ - - /** - * The identifier of the default partition content type. - */ - final static String DEFAULT_CONTENT_TYPE= "__dftl_partition_content_type"; //$NON-NLS-1$ - - - - - /* --------------- text access and manipulation --------------------------- */ - - /** - * Returns the character at the given document offset in this document. - * - * @param offset a document offset - * @return the character at the offset - * @exception BadLocationException if the offset is invalid in this document - */ - char getChar(int offset) throws BadLocationException; - - /** - * Returns the number of characters in this document. - * - * @return the number of characters in this document - */ - int getLength(); - - /** - * Returns this document's complete text. - * - * @return the document's complete text - */ - String get(); - - /** - * Returns this document's text for the specified range. - * - * @param offset the document offset - * @param length the length of the specified range - * @return the document's text for the specified range - * @exception BadLocationException if the range is invalid in this document - */ - String get(int offset, int length) throws BadLocationException; - - /** - * Replaces the content of the document with the given text. - * Sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>. - * This method is a convenience method for <code>replace(0, getLength(), text)</code>. - * - * @param text the new content of the document - * - * @see DocumentEvent - * @see IDocumentListener - */ - void set(String text); - - /** - * Substitutes the given text for the specified document range. - * Sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>. - * - * @param offset the document offset - * @param length the length of the specified range - * @param text the substitution text - * @exception BadLocationException if the offset is invalid in this document - * - * @see DocumentEvent - * @see IDocumentListener - */ - void replace(int offset, int length, String text) throws BadLocationException; - - /** - * Registers the document listener with the document. After registration - * the IDocumentListener is informed about each change of this document. - * If the listener is already registered nothing happens.<p> - * An <code>IDocumentListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be registered - */ - void addDocumentListener(IDocumentListener listener); - - /** - * Removes the listener from the document's list of document listeners. - * If the listener is not registered with the document nothing happens.<p> - * An <code>IDocumentListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be removed - */ - void removeDocumentListener(IDocumentListener listener); - - /** - * Adds the given document listener as one which is notified before - * those document listeners added with <code>addDocumentListener</code> - * are notified. If the given listener is also registered using - * <code>addDocumentListener</code> it will be notified twice. - * If the listener is already registered nothing happens.<p> - * - * This method is not for public use. - * - * @param documentAdapter the listener to be added as pre-notified document listener - * - * @see #removePrenotifiedDocumentListener(IDocumentListener) - */ - void addPrenotifiedDocumentListener(IDocumentListener documentAdapter); - - /** - * Removes the given document listener from the document's list of - * pre-notified document listeners. If the listener is not registered - * with the document nothing happens. <p> - * - * This method is not for public use. - * - * @param documentAdapter the listener to be removed - * - * @see #addPrenotifiedDocumentListener(IDocumentListener) - */ - void removePrenotifiedDocumentListener(IDocumentListener documentAdapter); - - - - /* -------------------------- positions ----------------------------------- */ - - /** - * Adds a new position category to the document. If the position category - * already exists nothing happens. - * - * @param category the category to be added - */ - void addPositionCategory(String category); - - /** - * Deletes the position category from the document. All positions - * in this category are thus deleted as well. - * - * @param category the category to be removed - * @exception BadPositionCategoryException if category is undefined in this document - */ - void removePositionCategory(String category) throws BadPositionCategoryException; - - /** - * Returns all position categories of this document. This - * includes the default position category. - * - * @return the document's position categories - */ - String[] getPositionCategories(); - - /** - * Checks the presence of the specified position category. - * - * @param category the category to check - * @return <code>true</code> if category is defined - */ - boolean containsPositionCategory(String category); - - /** - * Adds the position to the document's default position category. - * This is a convenience method for <code>addPosition(DEFAULT_CATEGORY, position)</code>. - * - * @param position the position to be added - * @exception BadLocationException if position describes an invalid range in this document - */ - void addPosition(Position position) throws BadLocationException; - - /** - * Removes the given position from the document's default position category. - * This is a convenience method for <code>removePosition(DEFAULT_CATEGORY, position)</code>. - * - * @param position the position to be removed - */ - void removePosition(Position position); - - /** - * Adds the position to the specified position category of the document. - * A position that has been added to a position category is updated on each - * change applied to the document. Positions may be added multiple times. - * The order of the category is maintained. - * - * @param category the category to which to add - * @param position the position to be added - * @exception BadLocationException if position describes an invalid range in this document - * @exception BadPositionCategoryException if the category is undefined in this document - */ - void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException; - - /** - * Removes the given position from the specified position category. - * If the position is not part of the specified category nothing happens. - * If the position has been added multiple times, only the first occurrence is deleted. - * - * @param category the category from which to delete - * @param position the position to be deleted - * @exception BadPositionCategoryException if category is undefined in this document - */ - void removePosition(String category, Position position) throws BadPositionCategoryException; - - /** - * Returns all positions of the given position category. - * The positions are ordered according to the category's order. - * Manipulating this list does not affect the document, but manipulating the - * position does affect the document. - * - * @param category the category - * @return the list of all positions - * @exception BadPositionCategoryException if category is undefined in this document - */ - Position[] getPositions(String category) throws BadPositionCategoryException; - - /** - * Determines whether a position described by the parameters is managed by this document. - * - * @param category the category to check - * @param offset the offset of the position to find - * @param length the length of the position to find - * @return <code>true</code> if position is found - */ - boolean containsPosition(String category, int offset, int length); - - /** - * Computes the index at which a <code>Position</code> with the - * specified offset would be inserted into the given category. As the - * ordering inside a category only depends on the offset, the index must be - * chosen to be the first of all positions with the same offset. - * - * @param category the category in which would be added - * @param offset the position offset to be considered - * @return the index into the category - * @exception BadLocationException if offset is invalid in this document - * @exception BadPositionCategoryException if category is undefined in this document - */ - int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException; - - /** - * Appends a new position updater to the document's list of position updaters. - * Position updaters may be added multiple times.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be added - */ - void addPositionUpdater(IPositionUpdater updater); - - /** - * Removes the position updater from the document's list of position updaters. - * If the position updater has multiple occurrences only the first occurrence is - * removed. If the position updater is not registered with this document, nothing - * happens.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be removed - */ - void removePositionUpdater(IPositionUpdater updater); - - /** - * Inserts the position updater at the specified index in the document's - * list of position updaters. Positions updaters may be inserted multiple times.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be inserted - * @param index the index in the document's updater list - */ - void insertPositionUpdater(IPositionUpdater updater, int index); - - /** - * Returns the list of position updaters attached to the document. - * - * @return the list of position updaters - */ - IPositionUpdater[] getPositionUpdaters(); - - - - - /* -------------------------- partitions ---------------------------------- */ - - /** - * Returns the set of legal content types of document partitions. - * This set can be empty. The set can contain more content types than - * contained by the result of <code>getPartitioning(0, getLength())</code>. - * <p> - * Use {@link IDocumentExtension3#getLegalContentTypes(String)} when the document - * supports multiple partitionings. In that case this method is equivalent to: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.getLegalContentTypes(IDocumentExtension3.DEFAULT_PARTITIONING); - * </pre> - * - * @return the set of legal content types - */ - String[] getLegalContentTypes(); - - /** - * Returns the type of the document partition containing the given offset. - * This is a convenience method for <code>getPartition(offset).getType()</code>. - * <p> - * Use {@link IDocumentExtension3#getContentType(String, int, boolean)} when - * the document supports multiple partitionings. In that case this method is - * equivalent to: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.getContentTypes(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false); - * </pre> - * - * @param offset the document offset - * @return the partition type - * @exception BadLocationException if offset is invalid in this document - */ - String getContentType(int offset) throws BadLocationException; - - /** - * Returns the document partition in which the position is located. - * <p> - * Use {@link IDocumentExtension3#getPartition(String, int, boolean)} when - * the document supports multiple partitionings. In that case this method is - * equivalent: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false); - * </pre> - * - * @param offset the document offset - * @return a specification of the partition - * @exception BadLocationException if offset is invalid in this document - */ - ITypedRegion getPartition(int offset) throws BadLocationException; - - /** - * Computes the partitioning of the given document range using the - * document's partitioner. - * <p> - * Use {@link IDocumentExtension3#computePartitioning(String, int, int, boolean)} when - * the document supports multiple partitionings. In that case this method is - * equivalent: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING, offset, length, false); - * </pre> - * - * @param offset the document offset at which the range starts - * @param length the length of the document range - * @return a specification of the range's partitioning - * @exception BadLocationException if the range is invalid in this document - */ - ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException; - - /** - * Registers the document partitioning listener with the document. After registration - * the document partitioning listener is informed about each partition change - * cause by a document manipulation or by changing the document's partitioner. - * If a document partitioning listener is also - * a document listener, the following notification sequence is guaranteed if a - * document manipulation changes the document partitioning: - * <ul> - * <li>listener.documentAboutToBeChanged(DocumentEvent); - * <li>listener.documentPartitioningChanged(); - * <li>listener.documentChanged(DocumentEvent); - * </ul> - * If the listener is already registered nothing happens.<p> - * An <code>IDocumentPartitioningListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be added - */ - void addDocumentPartitioningListener(IDocumentPartitioningListener listener); - - /** - * Removes the listener from this document's list of document partitioning - * listeners. If the listener is not registered with the document nothing - * happens.<p> - * An <code>IDocumentPartitioningListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be removed - */ - void removeDocumentPartitioningListener(IDocumentPartitioningListener listener); - - /** - * Sets this document's partitioner. The caller of this method is responsible for - * disconnecting the document's old partitioner from the document and to - * connect the new partitioner to the document. Informs all document partitioning - * listeners about this change. - * <p> - * Use {@link IDocumentExtension3#setDocumentPartitioner(String, IDocumentPartitioner)} when - * the document supports multiple partitionings. In that case this method is equivalent to: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.setDocumentPartitioner(IDocumentExtension3.DEFAULT_PARTITIONING, partitioner); - * </pre> - * - * @param partitioner the document's new partitioner - * - * @see IDocumentPartitioningListener - */ - void setDocumentPartitioner(IDocumentPartitioner partitioner); - - /** - * Returns this document's partitioner. - * <p> - * Use {@link IDocumentExtension3#getDocumentPartitioner(String)} when - * the document supports multiple partitionings. In that case this method is - * equivalent to: - * <pre> - * IDocumentExtension3 extension= (IDocumentExtension3) document; - * return extension.getDocumentPartitioner(IDocumentExtension3.DEFAULT_PARTITIONING); - * </pre> - * - * @return this document's partitioner - */ - IDocumentPartitioner getDocumentPartitioner(); - - - - /* ---------------------- line information -------------------------------- */ - - /** - * Returns the length of the given line including the line's delimiter. - * - * @param line the line of interest - * @return the length of the line - * @exception BadLocationException if the line number is invalid in this document - */ - int getLineLength(int line) throws BadLocationException; - - /** - * Returns the number of the line at which the character of the specified position is located. - * The first line has the line number 0. A new line starts directly after a line - * delimiter. <code>(offset == document length)</code> is a valid argument although there is no - * corresponding character. - * - * @param offset the document offset - * @return the number of the line - * @exception BadLocationException if the offset is invalid in this document - */ - int getLineOfOffset(int offset) throws BadLocationException; - - /** - * Determines the offset of the first character of the given line. - * - * @param line the line of interest - * @return the document offset - * @exception BadLocationException if the line number is invalid in this document - */ - int getLineOffset(int line) throws BadLocationException; - - /** - * Returns a description of the specified line. The line is described by its - * offset and its length excluding the line's delimiter. - * - * @param line the line of interest - * @return a line description - * @exception BadLocationException if the line number is invalid in this document - */ - IRegion getLineInformation(int line) throws BadLocationException; - - /** - * Returns a description of the line at the given offset. - * The description contains the offset and the length of the line - * excluding the line's delimiter. - * - * @param offset the offset whose line should be described - * @return a region describing the line - * @exception BadLocationException if offset is invalid in this document - */ - IRegion getLineInformationOfOffset(int offset) throws BadLocationException; - - /** - * Returns the number of lines in this document - * - * @return the number of lines in this document - */ - int getNumberOfLines(); - - /** - * Returns the number of lines which are occupied by a given text range. - * - * @param offset the offset of the specified text range - * @param length the length of the specified text range - * @return the number of lines occupied by the specified range - * @exception BadLocationException if specified range is invalid in this tracker - */ - int getNumberOfLines(int offset, int length) throws BadLocationException; - - /** - * Computes the number of lines in the given text. For a given - * implementer of this interface this method returns the same - * result as <code>set(text); getNumberOfLines()</code>. - * - * @param text the text whose number of lines should be computed - * @return the number of lines in the given text - */ - int computeNumberOfLines(String text); - - - /* ------------------ line delimiter conversion --------------------------- */ - - /** - * Returns the document's legal line delimiters. - * - * @return the document's legal line delimiters - */ - String[] getLegalLineDelimiters(); - - /** - * Returns the line delimiter of that line or <code>null</code> if the - * line is not closed with a line delimiter. - * - * @param line the line of interest - * @return the line's delimiter or <code>null</code> if line does not have a delimiter - * @exception BadLocationException if the line number is invalid in this document - */ - String getLineDelimiter(int line) throws BadLocationException; - - - /* ---------------------------- search ------------------------------------ */ - - /** - * Returns the offset of a given search string in the document based on a set of search criteria. - * - * @param startOffset document offset at which search starts - * @param findString the string to find - * @param forwardSearch the search direction - * @param caseSensitive indicates whether lower and upper case should be distinguished - * @param wholeWord indicates whether the findString should be limited by white spaces as - * defined by Character.isWhiteSpace - * @return the offset of the first occurrence of findString based on the parameters or -1 if no match is found - * @exception BadLocationException if startOffset is an invalid document offset - * @deprecated as of 3.0 search is provided by {@link FindReplaceDocumentAdapter} - */ - int search(int startOffset, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException; -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java deleted file mode 100644 index 09be52ccabe..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocument}.<p> - * - * It introduces the notion of sequentially rewriting a document. This is to tell a - * document that a sequence of non-overlapping replace operation is about to be - * performed. Implementers can use this knowledge for internal optimization.<p> - * - * Is also introduces the concept of post notification replaces. This is, a document - * listener who is informed about a document change can cause a derived document - * change. As the listener is not allowed to directly modify the document, it can - * register a replace operation that is performed directly after all document listeners - * have been notified. - * - * @since 2.0 - */ -public interface IDocumentExtension { - - /** - * Interface for a post notification replace operation. - */ - public interface IReplace { - - /** - * Executes the replace operation on the given document. - * - * @param document the document to be changed - * @param owner the owner of this replace operation - */ - void perform(IDocument document, IDocumentListener owner); - }; - - /** - * Callback for document listeners to be used inside <code>documentChanged</code> - * to register a post notification replace operation on the document notifying them. - * - * @param owner the owner of the replace operation - * @param replace the replace operation to be executed - * @exception UnsupportedOperationException if <code>registerPostNotificationReplace</code> - * is not supported by this document - */ - void registerPostNotificationReplace(IDocumentListener owner, IReplace replace) throws UnsupportedOperationException; - - /** - * Stops the processing of registered post notification replace operations until - * <code>resumePostNotificationProcessing</code> is called. - */ - void stopPostNotificationProcessing(); - - /** - * Resumes the processing of post notification replace operations. If the queue of registered - * <code>IDocumentExtension.IReplace</code> objects is not empty, they are immediately processed if the - * document is not inside a replace operation. If the document is inside a replace operation, - * they are processed directly after the replace operation has finished. - */ - void resumePostNotificationProcessing(); - - /** - * Tells the document that it is about to be sequentially rewritten. That is a - * sequence of non-overlapping replace operations will be performed on it. The - * <code>normalize</code> flag indicates whether the rewrite is performed from - * the start of the document to its end or from an arbitrary start offset. <p> - * - * The document is considered being in sequential rewrite mode as long as - * <code>stopSequentialRewrite</code> has not been called. - * - * @param normalize <code>true</code> if performed from the start to the end of the document - */ - void startSequentialRewrite(boolean normalize); - - /** - * Tells the document that the sequential rewrite has been finished. This method - * has only any effect if <code>startSequentialRewrite</code> has been called before. - */ - void stopSequentialRewrite(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension2.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension2.java deleted file mode 100644 index 1b83dcd854c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension2.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocument}.<p> - * - * It adds configuration methods to post notification replaces and document - * listener notification. - * - * @since 2.1 - */ -public interface IDocumentExtension2 { - - /** - * Tells the receiver to ignore calls to - * <code>registerPostNotificationReplace</code> until - * <code>acceptPostNotificationReplaces</code> is called. - */ - void ignorePostNotificationReplaces(); - - /** - * Tells the receiver to accept calls to - * <code>registerPostNotificationReplace</code> until - * <code>ignorePostNotificationReplaces</code> is called. - */ - void acceptPostNotificationReplaces(); - - /** - * Can be called prior to a <code>replace</code> operation. After the - * <code>replace</code> <code>resumeListenerNotification</code> must be - * called. The affect of these calls is that no document listener is notified - * until <code>resumeListenerNotification</code> is called. This allows clients - * to update structure before any listener is informed about the change.<p> - * Listener notification can only be stopped for a single <code>replace</code> operation. - * Otherwise, document change notifications will be lost. - */ - void stopListenerNotification(); - - /** - * Resumes the notification of document listeners which must previously - * have been stopped by a call to <code>stopListenerNotification</code>. - */ - void resumeListenerNotification(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java deleted file mode 100644 index 518ecea6eac..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocument}. - * <p> - * Adds the concept of multiple partitionings and the concept of zero-length - * partitions in conjunction with open and delimited partitions. A delimited - * partition has a well defined start delimiter and a well defined end - * delimiter. Between two delimited partitions there may be an open partition of - * length zero. - * <p> - * - * In order to fulfill the contract of this interface, the document must be - * configured with a document partitioner implementing - * {@link org.eclipse.jface.text.IDocumentPartitionerExtension2}. - * - * @see org.eclipse.jface.text.IDocumentPartitionerExtension2 - * @since 3.0 - */ -public interface IDocumentExtension3 { - - /** - * The identifier of the default partitioning. - */ - final static String DEFAULT_PARTITIONING= "__dftl_partitioning"; //$NON-NLS-1$ - - - /** - * Returns the existing partitionings for this document. This includes - * the default partitioning. - * - * @return the existing partitionings for this document - */ - String[] getPartitionings(); - - /** - * Returns the set of legal content types of document partitions for the given partitioning - * This set can be empty. The set can contain more content types than contained by the - * result of <code>getPartitioning(partitioning, 0, getLength())</code>. - * - * @param partitioning the partitioning for which to return the legal content types - * @return the set of legal content types - * @exception BadPartitioningException if partitioning is invalid for this document - */ - String[] getLegalContentTypes(String partitioning) throws BadPartitioningException; - - - /** - * Returns the type of the document partition containing the given offset - * for the given partitioning. This is a convenience method for - * <code>getPartition(partitioning, offset, boolean).getType()</code>. - * <p> - * If <code>preferOpenPartitions</code> is <code>true</code>, - * precedence is given to an open partition ending at <code>offset</code> - * over a delimited partition starting at <code>offset</code>. If it is - * <code>false</code>, precedence is given to the partition that does not - * end at <code>offset</code>. - * </p> - * This is only supported if the connected <code>IDocumentPartitioner</code> - * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>. - * Otherwise, <code>preferOpenPartitions</code> is ignored. - * </p> - * - * @param partitioning the partitioning - * @param offset the document offset - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over a - * closed partition starting at <code>offset</code> - * @return the partition type - * @exception BadLocationException if offset is invalid in this document - * @exception BadPartitioningException if partitioning is invalid for this document - */ - String getContentType(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException; - - /** - * Returns the document partition of the given partitioning in which the - * given offset is located. - * <p> - * If <code>preferOpenPartitions</code> is <code>true</code>, - * precedence is given to an open partition ending at <code>offset</code> - * over a delimited partition starting at <code>offset</code>. If it is - * <code>false</code>, precedence is given to the partition that does not - * end at <code>offset</code>. - * </p> - * This is only supported if the connected <code>IDocumentPartitioner</code> - * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>. - * Otherwise, <code>preferOpenPartitions</code> is ignored. - * </p> - * - * @param partitioning the partitioning - * @param offset the document offset - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over a - * closed partition starting at <code>offset</code> - * @return a specification of the partition - * @exception BadLocationException if offset is invalid in this document - * @exception BadPartitioningException if partitioning is invalid for this document - */ - ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException; - - /** - * Computes the partitioning of the given document range based on the given - * partitioning type. - * <p> - * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a - * zero-length partition of an open partition type (usually the default - * partition) is included between two closed partitions. If it is - * <code>false</code>, no zero-length partitions are included. - * </p> - * This is only supported if the connected <code>IDocumentPartitioner</code> - * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>. - * Otherwise, <code>includeZeroLengthPartitions</code> is ignored. - * </p> - * - * @param partitioning the document's partitioning type - * @param offset the document offset at which the range starts - * @param length the length of the document range - * @param includeZeroLengthPartitions <code>true</code> if zero-length - * partitions should be returned as part of the computed partitioning - * @return a specification of the range's partitioning - * @exception BadLocationException if the range is invalid in this document$ - * @exception BadPartitioningException if partitioning is invalid for this document - */ - ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException; - - /** - * Sets this document's partitioner. The caller of this method is responsible for - * disconnecting the document's old partitioner from the document and to - * connect the new partitioner to the document. Informs all document partitioning - * listeners about this change. - * - * @param partitioning the partitioning for which to set the partitioner - * @param partitioner the document's new partitioner - * @see IDocumentPartitioningListener - */ - void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner); - - /** - * Returns the partitioner for the given partitioning or <code>null</code> if - * no partitioner is registered. - * - * @param partitioning the partitioning for which to set the partitioner - * @return the partitioner for the given partitioning - */ - IDocumentPartitioner getDocumentPartitioner(String partitioning); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMapping.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMapping.java deleted file mode 100644 index e70ac12fe0b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMapping.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * A <code>IDocumentInformationMapping</code> represents a mapping between the coordinates of two - * <code>IDocument</code> objects: the original and the image. The document information mapping - * can translate document information such as line numbers or character ranges given for the original into - * the corresponding information of the image and vice versa. - * - * In order to provided backward compatibility for clients of <code>IDocumentInformationMapping</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.IDocumentInformationMappingExtension} since version 3.0 extending the - * degree of detail of the mapping information.</li> - * </ul> - * - * @since 2.1 - */ -public interface IDocumentInformationMapping { - - /** - * Returns the minimal region of the original document that completely comprises all of the image document - * or <code>null</code> if there is no such region. - * - * @return the minimal region of the original document comprising the image document or <code>null</code> - */ - IRegion getCoverage(); - - /** - * Returns the offset in the original document that corresponds to the given offset in the image document - * or <code>-1</code> if there is no such offset - * - * @param imageOffset the offset in the image document - * @return the corresponding offset in the original document or <code>-1</code> - * @throws BadLocationException if <code>imageOffset</code> is not a valid offset in the image document - */ - int toOriginOffset(int imageOffset) throws BadLocationException; - - /** - * Returns the minimal region of the original document that completely comprises the given region of the - * image document or <code>null</code> if there is no such region. - * - * @param imageRegion the region of the image document - * @return the minimal region of the original document comprising the given region of the image document or <code>null</code> - * @throws BadLocationException if <code>imageRegion</code> is not a valid region of the image document - */ - IRegion toOriginRegion(IRegion imageRegion) throws BadLocationException; - - /** - * Returns the range of lines of the original document that corresponds to the given line of the image document or - * <code>null</code> if there are no such lines. - * - * @param imageLine the line of the image document - * @return the corresponding lines of the original document or <code>null</code> - * @throws BadLocationException if <code>imageLine</code> is not a valid line number in the image document - */ - IRegion toOriginLines(int imageLine) throws BadLocationException; - - /** - * Returns the line of the original document that corresponds to the given line of the image document or - * <code>-1</code> if there is no such line. - * - * @param imageLine the line of the image document - * @return the corresponding line of the original document or <code>-1</code> - * @throws BadLocationException if <code>imageLine</code> is not a valid line number in the image document - */ - int toOriginLine(int imageLine) throws BadLocationException; - - - - /** - * Returns the offset in the image document that corresponds to the given offset in the original document - * or <code>-1</code> if there is no such offset - * - * @param originOffset the offset in the original document - * @return the corresponding offset in the image document or <code>-1</code> - * @throws BadLocationException if <code>originOffset</code> is not a valid offset in the original document - */ - int toImageOffset(int originOffset) throws BadLocationException; - - /** - * Returns the minimal region of the image document that completely comprises the given region of the - * original document or <code>null</code> if there is no such region. - * - * @param originRegion the region of the original document - * @return the minimal region of the image document comprising the given region of the original document or <code>null</code> - * @throws BadLocationException if <code>originRegion</code> is not a valid region of the original document - */ - IRegion toImageRegion(IRegion originRegion) throws BadLocationException; - - /** - * Returns the line of the image document that corresponds to the given line of the original document or - * <code>-1</code> if there is no such line. - * - * @param originLine the line of the original document - * @return the corresponding line of the image document or <code>-1</code> - * @throws BadLocationException if <code>originLine</code> is not a valid line number in the original document - */ - int toImageLine(int originLine) throws BadLocationException; - - /** - * Returns the line of the image document whose corresponding line in the original document - * is closest to the given line in the original document. - * - * @param originLine the line in the original document - * @return the line in the image document that corresponds best to the given line in the original document - * @throws BadLocationException if <code>originLine</code>is not a valid line in the original document - */ - int toClosestImageLine(int originLine) throws BadLocationException; -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMappingExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMappingExtension.java deleted file mode 100644 index 6981b3267f9..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentInformationMappingExtension.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Extension to {@link org.eclipse.jface.text.IDocumentInformationMapping}. - * <p> - * Extends the information available in the mapping by providing explicit access - * to the isomorphic portion of the basically homomorphic information mapping. - * - * @see org.eclipse.jface.text.IDocumentInformationMapping - * @since 3.0 - */ -public interface IDocumentInformationMappingExtension { - - /** - * Adheres to - * <code>originRegion=toOriginRegion(toExactImageRegion(originRegion))</code>, - * if <code>toExactImageRegion(originRegion) != null</code>. Returns - * <code>null</code> if there is no image for the given origin region. - * - * @param originRegion the origin region - * @return the exact image region or <code>null</code> - * @throws BadLocationException if origin region is not a valid region in - * the origin document - */ - IRegion toExactImageRegion(IRegion originRegion) throws BadLocationException; - - /** - * Returns the segments of the image document that exactly correspond to the - * given region of the original document. Returns <code>null</code> if - * there are no such image regions. - * - * @param originRegion the region in the origin document - * @return the segments in the image document or <code>null</code> - * @throws BadLocationException in case the given origin region is not valid - * in the original document - */ - IRegion[] toExactImageRegions(IRegion originRegion) throws BadLocationException; - - /** - * Returns the fragments of the original document that exactly correspond to - * the given region of the image document. - * - * @param imageRegion the region in the image document - * @return the fragments in the origin document - * @throws BadLocationException in case the given image region is not valid - * in the image document - */ - IRegion[] toExactOriginRegions(IRegion imageRegion) throws BadLocationException; - - /** - * Returns the length of the image document. - * - * @return the length of the image document - */ - int getImageLength(); - - /** - * Returns the maximal sub-regions of the given origin region which are - * completely covered. I.e. each offset in a sub-region has a corresponding - * image offset. Returns <code>null</code> if there are no such - * sub-regions. - * - * @param originRegion the region in the origin document - * @return the sub-regions with complete coverage or <code>null</code> - * @throws BadLocationException in case the given origin region is not valid - * in the original document - */ - IRegion[] getExactCoverage(IRegion originRegion) throws BadLocationException; -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java deleted file mode 100644 index 28e7f60272c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Interface for objects which are interested in getting informed about - * document changes. A listener is informed about document changes before - * they are applied and after they have been applied. It is ensured that - * the document event passed into the listener is the same for the two - * notifications, i.e. the two document events can be checked using object identity. - * Clients may implement this interface. - * - * @see org.eclipse.jface.text.IDocument - */ -public interface IDocumentListener { - - - /** - * The manipulation described by the document event will be performed. - * - * @param event the document event describing the document change - */ - void documentAboutToBeChanged(DocumentEvent event); - - /** - * The manipulation described by the document event has been performed. - * - * @param event the document event describing the document change - */ - void documentChanged(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java deleted file mode 100644 index c6a713dde55..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * A document partitioner divides a document into a set - * of disjoint text partitions. Each partition has a content type, an - * offset, and a length. The document partitioner is connected to one document - * and informed about all changes of this document before any of the - * document's document listeners. A document partitioner can thus - * incrementally update on the receipt of a document change event.<p> - * - * In order to provided backward compatibility for clients of <code>IDocumentPartitioner</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.IDocumentPartitionerExtension} since version 2.0 replacing - * the <code>documentChanged</code> method with a new one returning the minimal document region - * comprising all partition changes. </li> - * <li> {@link org.eclipse.jface.text.IDocumentPartitionerExtension2} since version 3.0 - * introducing zero-length partitions in conjunction with the distinction between - * open and closed partitions. Also provides inside in the implementation of the partitioner - * by exposing the position category used for managing the partitioning information.</li> - * </ul> - * - * Clients may implement this interface and its extension interfaces or use the standard - * implementation <code>DefaultPartitioner</code>. - * - * @see org.eclipse.jface.text.IDocumentPartitionerExtension - * @see org.eclipse.jface.text.IDocumentPartitionerExtension2 - * @see org.eclipse.jface.text.IDocument - */ -public interface IDocumentPartitioner { - - /** - * Connects the partitioner to a document. - * Connect indicates the begin of the usage of the receiver - * as partitioner of the given document. Thus, resources the partitioner - * needs to be operational for this document should be allocated.<p> - * The caller of this method must ensure that this partitioner is - * also set as the document's document partitioner. - * - * @param document the document to be connected to - */ - void connect(IDocument document); - - /** - * Disconnects the partitioner from the document it is connected to. - * Disconnect indicates the end of the usage of the receiver as - * partitioner of the connected document. Thus, resources the partitioner - * needed to be operation for its connected document should be deallocated.<p> - * The caller of this method should also must ensure that this partitioner is - * no longer the document's partitioner. - */ - void disconnect(); - - /** - * Informs about a forthcoming document change. Will be called by the - * connected document and is not intended to be used by clients - * other than the connected document. - * - * @param event the event describing the forthcoming change - */ - void documentAboutToBeChanged(DocumentEvent event); - - /** - * The document has been changed. The partitioner updates - * the document's partitioning and returns whether the structure of the - * document partitioning has been changed, i.e. whether partitions - * have been added or removed. Will be called by the connected document and - * is not intended to be used by clients other than the connected document.<p> - * - * This method has been replaced by {@link IDocumentPartitionerExtension#documentChanged2(DocumentEvent)}. - * - * @param event the event describing the document change - * @return <code>true</code> if partitioning changed - */ - boolean documentChanged(DocumentEvent event); - - /** - * Returns the set of all legal content types of this partitioner. - * I.e. any result delivered by this partitioner may not contain a content type - * which would not be included in this method's result. - * - * @return the set of legal content types - */ - String[] getLegalContentTypes(); - - /** - * Returns the content type of the partition containing the - * given offset in the connected document. There must be a - * document connected to this partitioner.<p> - * - * Use {@link IDocumentPartitionerExtension2#getContentType(int, boolean)} when - * zero-length partitions are supported. In that case this method is - * equivalent: - * <pre> - * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; - * return extension.getContentType(offset, false); - * </pre> - * - * @param offset the offset in the connected document - * @return the content type of the offset's partition - */ - String getContentType(int offset); - - /** - * Returns the partitioning of the given range of the connected - * document. There must be a document connected to this partitioner.<p> - * - * Use {@link IDocumentPartitionerExtension2#computePartitioning(int, int, boolean)} when - * zero-length partitions are supported. In that case this method is - * equivalent: - * <pre> - * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; - * return extension.computePartitioning(offset, length, false); - * </pre> - * - * @param offset the offset of the range of interest - * @param length the length of the range of interest - * @return the partitioning of the range - */ - ITypedRegion[] computePartitioning(int offset, int length); - - /** - * Returns the partition containing the given offset of - * the connected document. There must be a document connected to this - * partitioner.<p> - * - * Use {@link IDocumentPartitionerExtension2#getPartition(int, boolean)} when - * zero-length partitions are supported. In that case this method is - * equivalent: - * <pre> - * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner; - * return extension.getPartition(offset, false); - * </pre> - * - * @param offset the offset for which to determine the partition - * @return the partition containing the offset - */ - ITypedRegion getPartition(int offset); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java deleted file mode 100644 index 2c37fcb54a3..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocumentPartitioner}. - * <p> - * Replaces the original concept of the document partitioner by returning the - * minimal region that includes all partition changes caused by the invocation - * of the document partitioner. - * The method <code>documentChanged2</code> is considered the replacement of - * {@link org.eclipse.jface.text.IDocumentPartitioner#documentChanged(DocumentEvent)}. - * - * @since 2.0 - */ -public interface IDocumentPartitionerExtension { - - /** - * The document has been changed. The partitioner updates the document's - * partitioning and returns the minimal region that comprises all partition - * changes caused in response to the given document event. This method - * returns <code>null</code> if the partitioning did not change. - * <p> - * - * Will be called by the connected document and is not intended to be used - * by clients other than the connected document. - * <p> - * Replaces {@link IDocumentPartitioner#documentChanged(DocumentEvent)}. - * - * @param event the event describing the document change - * @return the region of the document in which the partition type changed - */ - IRegion documentChanged2(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java deleted file mode 100644 index c9e3298a01f..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Extension interface for {@link org.eclipse.jface.text.IDocumentPartitioner}. - * <p> - * Extends the original concept of a document partitioner to answer the position - * categories that are used to manage the partitioning information. - * <p> - * This extension also introduces the concept of open and delimited partitions. - * A delimited partition has a predefined textual token delimiting its start and - * end, while an open partition can fill any space between two delimited - * partitions. - * </p> - * <p> - * An open partition of length zero can occur between two delimited partitions, - * thus having the same offset as the following delimited partition. The - * document start and end are considered to be delimiters of open partitions, - * i.e. there may be a zero-length partition between the document start and a - * delimited partition starting at offset 0. - * </p> - * - * @since 3.0 - */ -public interface IDocumentPartitionerExtension2 { - - /** - * Returns the position categories that this partitioners uses in order to manage - * the partitioning information of the documents. Returns <code>null</code> if - * no position category is used. - * - * @return the position categories used to manage partitioning information or <code>null</code> - */ - String[] getManagingPositionCategories(); - - - /* zero-length partition support */ - - /** - * Returns the content type of the partition containing the given offset in - * the connected document. There must be a document connected to this - * partitioner. - * <p> - * If <code>preferOpenPartitions</code> is <code>true</code>, - * precedence is given to an open partition ending at <code>offset</code> - * over a delimited partition starting at <code>offset</code>. - * <p> - * This method replaces {@link IDocumentPartitioner#getContentType(int)}and - * behaves like it when <code>prepreferOpenPartitions</code> is - * <code>false</code>, i.e. precedence is always given to the partition - * that does not end at <code>offset</code>. - * </p> - * - * @param offset the offset in the connected document - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over - * a delimited partition starting at <code>offset</code> - * @return the content type of the offset's partition - */ - String getContentType(int offset, boolean preferOpenPartitions); - - /** - * Returns the partition containing the given offset of the connected - * document. There must be a document connected to this partitioner. - * <p> - * If <code>preferOpenPartitions</code> is <code>true</code>, - * precedence is given to an open partition ending at <code>offset</code> - * over a delimited partition starting at <code>offset</code>. - * <p> - * This method replaces {@link IDocumentPartitioner#getPartition(int)}and - * behaves like it when <preferOpenPartitions</code> is <code>false - * </code>, i.e. precedence is always given to the partition that does not - * end at <code>offset</code>. - * </p> - * - * @param offset the offset for which to determine the partition - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over - * a delimited partition starting at <code>offset</code> - * @return the partition containing the offset - */ - ITypedRegion getPartition(int offset, boolean preferOpenPartitions); - - /** - * Returns the partitioning of the given range of the connected document. - * There must be a document connected to this partitioner. - * <p> - * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a - * zero-length partition of an open partition type (usually the default - * partition) is included between two delimited partitions. If it is - * <code>false</code>, no zero-length partitions are included. - * </p> - * <p> - * This method replaces - * {@link IDocumentPartitioner#computePartitioning(int, int)}and behaves - * like it when <code>includeZeroLengthPartitions</code> is - * <code>false</code>. - * </p> - * - * @param offset the offset of the range of interest - * @param length the length of the range of interest - * @param includeZeroLengthPartitions <code>true</code> if zero-length - * partitions should be returned as part of the computed - * partitioning - * @return the partitioning of the range - */ - ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java deleted file mode 100644 index e7b202db87c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Interface of objects which are interested in getting informed - * about changes of a document's partitioning. Clients may - * implement this interface.<p> - * - * In order to provided backward compatibility for clients of <code>IDocumentPartitioningListener</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.IDocumentPartitioningListenerExtension} since version 2.0 replacing the original - * notification mechanism.</li> - * <li> {@link org.eclipse.jface.text.IDocumentPartitioningListenerExtension2} since version 3.0 replacing all previous - * notification mechanisms. Thus, implementers up-to-date with version 3.0 do not have to implement - * {@link org.eclipse.jface.text.IDocumentPartitioningListenerExtension}.</li> - * </ul> - * - * @see org.eclipse.jface.text.IDocumentPartitioningListenerExtension - * @see org.eclipse.jface.text.IDocumentPartitioningListenerExtension2 - * @see org.eclipse.jface.text.IDocument - * @see org.eclipse.jface.text.IDocumentPartitioner - */ -public interface IDocumentPartitioningListener { - - /** - * The partitioning of the given document changed. - * <p> - * In version 2.0 this method has been replaces by - * {@link IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion)}. - * <p> - * In version 3.0 this method has been replaces by - * {@link IDocumentPartitioningListenerExtension2#documentPartitioningChanged(DocumentPartitioningChangedEvent)}<p> - * - * @param document the document whose partitioning changed - * - * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion) - * @see IDocumentPartitioningListenerExtension2#documentPartitioningChanged(DocumentPartitioningChangedEvent) - * @see IDocument#addDocumentPartitioningListener(IDocumentPartitioningListener) - */ - void documentPartitioningChanged(IDocument document); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java deleted file mode 100644 index a0b68e9b4df..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Extension interface for - * {@link org.eclipse.jface.text.IDocumentPartitioningListener}. - * <p> - * Replaces the original notification mechanism by telling the listener the - * minimal region that comprises all partitioning changes. - * - * @see org.eclipse.jface.text.IDocumentPartitionerExtension - * @since 2.0 - */ -public interface IDocumentPartitioningListenerExtension { - - /** - * The partitioning of the given document changed in the given region. - * <p> - * In version 3.0, this method has been replaced with - * {@link IDocumentPartitioningListenerExtension2#documentPartitioningChanged(DocumentPartitioningChangedEvent)}. - * - * @param document the document whose partitioning changed - * @param region the region in which the partitioning changed - * @see IDocumentPartitioningListenerExtension2#documentPartitioningChanged(DocumentPartitioningChangedEvent) - * @see IDocument#addDocumentPartitioningListener(IDocumentPartitioningListener) - */ - void documentPartitioningChanged(IDocument document, IRegion region); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension2.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension2.java deleted file mode 100644 index 9aa30b30f0f..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension2.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Extension interface to - * {@link org.eclipse.jface.text.IDocumentPartitioningListener}. - * <p> - * - * Replaces the previous notification mechanisms by introducing an explicit - * document partitioning changed event. - * - * @see org.eclipse.jface.text.DocumentPartitioningChangedEvent - * @since 3.0 - */ -public interface IDocumentPartitioningListenerExtension2 { - - /** - * Signals the change of document partitionings. - * <p> - * This method replaces - * {@link IDocumentPartitioningListener#documentPartitioningChanged(IDocument)} - * and - * {@link IDocumentPartitioningListenerExtension2#documentPartitioningChanged(DocumentPartitioningChangedEvent)}. - * - * @param event the event describing the change - * @see IDocument#addDocumentPartitioningListener(IDocumentPartitioningListener) - */ - void documentPartitioningChanged(DocumentPartitioningChangedEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java deleted file mode 100644 index edfb66cb5d0..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * A line tracker maps character positions to line numbers and vice versa. - * Initially the line tracker is informed about its underlying text in order to - * initialize the mapping information. After that, the line tracker is informed - * about all changes of the underlying text allowing for incremental updates of - * the mapping information. It is the client's responsibility to actively inform - * the line tacker about text changes. For example, when using a line tracker in - * combination with a document the document controls the line tracker. - * <p> - * Clients may implement this interface or use the standard implementation - * {@link org.eclipse.jface.text.DefaultLineTracker}or - * {@link org.eclipse.jface.text.ConfigurableLineTracker}. - */ -public interface ILineTracker { - - /** - * Returns the strings this tracker considers as legal line delimiters. - * - * @return the legal line delimiters - */ - String[] getLegalLineDelimiters(); - - /** - * Returns the line delimiter of the specified line. Returns <code>null</code> if the - * line is not closed with a line delimiter. - * - * @param line the line whose line delimiter is queried - * @return the line's delimiter or <code>null</code> if line does not have a delimiter - * @exception BadLocationException if the line number is invalid in this tracker's line structure - */ - String getLineDelimiter(int line) throws BadLocationException; - - /** - * Computes the number of lines in the given text. - * - * @param text the text whose number of lines should be computed - * @return the number of lines in the given text - */ - int computeNumberOfLines(String text); - - /** - * Returns the number of lines. - * - * @return the number of lines in this tracker's line structure - */ - int getNumberOfLines(); - - /** - * Returns the number of lines which are occupied by a given text range. - * - * @param offset the offset of the specified text range - * @param length the length of the specified text range - * @return the number of lines occupied by the specified range - * @exception BadLocationException if specified range is unknown to this tracker - */ - int getNumberOfLines(int offset, int length) throws BadLocationException; - - /** - * Returns the position of the first character of the specified line. - * - * @param line the line of interest - * @return offset of the first character of the line - * @exception BadLocationException if the line is unknown to this tracker - */ - int getLineOffset(int line) throws BadLocationException; - - /** - * Returns length of the specified line including the line's delimiter. - * - * @param line the line of interest - * @return the length of the line - * @exception BadLocationException if line is unknown to this tracker - */ - int getLineLength(int line) throws BadLocationException; - - /** - * Returns the line number the character at the given offset belongs to. - * - * @param offset the offset whose line number to be determined - * @return the number of the line the offset is on - * @exception BadLocationException if the offset is invalid in this tracker - */ - int getLineNumberOfOffset(int offset) throws BadLocationException; - - /** - * Returns a line description of the line at the given offset. - * The description contains the start offset and the length of the line - * excluding the line's delimiter. - * - * @param offset the offset whose line should be described - * @return a region describing the line - * @exception BadLocationException if offset is invalid in this tracker - */ - IRegion getLineInformationOfOffset(int offset) throws BadLocationException; - - /** - * Returns a line description of the given line. The description - * contains the start offset and the length of the line excluding the line's - * delimiter. - * - * @param line the line that should be described - * @return a region describing the line - * @exception BadLocationException if line is unknown to this tracker - */ - IRegion getLineInformation(int line) throws BadLocationException; - - /** - * Informs the line tracker about the specified change in the tracked text. - * - * @param offset the offset of the replaced text - * @param length the length of the replaced text - * @param text the substitution text - * @exception BadLocationException if specified range is unknown to this tracker - */ - void replace(int offset, int length, String text) throws BadLocationException; - - /** - * Sets the tracked text to the specified text. - * - * @param text the new tracked text - */ - void set(String text); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java deleted file mode 100644 index 63361f6b5d8..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * A position updater is responsible for adapting document positions. When - * installed on a document, the position updater updates the document's - * positions to changes applied to this document. Document updaters can be - * selective, i.e. they might only update positions of a certain category. - * <p> - * Position updaters are of primary importance for the definition of the - * semantics of positions. - * <p> - * Clients may implement this interface or use the standard implementation - * {@link org.eclipse.jface.text.DefaultPositionUpdater}. - * - * @see org.eclipse.jface.text.IDocument - * @see org.eclipse.jface.text.Position - */ -public interface IPositionUpdater { - - /** - * Adapts positions to the change specified by the document event. - * It is ensured that the document's partitioning has been adapted to - * this document change and that all the position updaters which have - * a smaller index in the document's position updater list have been called. - * - * @param event the document event describing the document change - */ - void update(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java deleted file mode 100644 index 2c63ddd153f..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * A region describes a certain range in an indexed text store. Text stores are - * for example documents or strings. A region is defined by its offset into the - * text store and its length. - * <p> - * A region is considered a value object. Its offset and length do not change - * over time. - * <p> - * Clients may implement this interface or use the standard implementation - * {@link org.eclipse.jface.text.Region}. - */ -public interface IRegion { - - /** - * Returns the length of the region. - * - * @return the length of the region - */ - int getLength(); - - /** - * Returns the offset of the region. - * - * @return the offset of the region - */ - int getOffset(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IRepairableDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/IRepairableDocument.java deleted file mode 100644 index 1d6c7a00c57..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IRepairableDocument.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Tagging interface to be implemented by - * {@link org.eclipse.jface.text.IDocument}implementers that offer a line - * repair method on the documents. - * - * @see org.eclipse.jface.text.IDocument - * @since 3.0 - */ -public interface IRepairableDocument { - - /** - * Repairs the line information of the document implementing this interface. - */ - void repairLineInformation(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManager.java b/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManager.java deleted file mode 100644 index 6349aaa1b38..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManager.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text; - -/** - * Slave documents are documents whose contents is defined in terms of a master - * document. Thus, slave documents usually reflect a projection of the master document. - * Slave documents are causally connected to the master document. This means, changes - * of the master document have immediate effect on the slave document and vice versa.<p> - * - * A slave document manager creates slave documents for given master documents, manages the - * life cycle of the slave documents, and keeps track of the information flow between - * master and slave documents. The slave document manager defines the construction rules of the - * slave documents in terms of the master document.<p> - * -* In order to provided backward compatibility for clients of <code>ISlaveDocumentManager</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.ISlaveDocumentManagerExtension} since version 3.0 extending the protocol - * with an access to all managed slave document for a given master document. </li> - * </ul> - * - * - * @see org.eclipse.jface.text.IDocument - * @since 2.1 - */ -public interface ISlaveDocumentManager { - - /** - * Creates a new slave document for the given master document. The slave document - * is causally connected to its master document until <code>freeSlaveDocument</code> - * is called. The connection between the newly created slave document and the master - * document is managed by this slave document manager. - * - * @param master the master document - * @return the newly created slave document - * @see #freeSlaveDocument(IDocument) - */ - IDocument createSlaveDocument(IDocument master); - - /** - * Frees the given slave document. If the given document is not a slave document known - * to this slave document manager, this call does not have any effect. A slave - * document is known to this slave document manager if it has been created by - * this manager using <code>createSlaveDocument</code>. - * - * @param slave the slave document to be freed - * @see #createSlaveDocument(IDocument) - */ - void freeSlaveDocument(IDocument slave); - - /** - * Creates a new document information mapping between the given slave document and - * its master document. Returns <code>null</code> if the given document is unknown - * to this slave document manager. - * - * @param slave the slave document - * @return a document information mapping between the slave document and its master document or - * <code>null</code> - */ - IDocumentInformationMapping createMasterSlaveMapping(IDocument slave); - - /** - * Returns the master document of the given slave document or <code>null</code> if the - * given document is unknown to this slave document manager. - * - * @param slave the slave document - * @return the master document of the given slave document or <code>null</code> - */ - IDocument getMasterDocument(IDocument slave); - - /** - * Returns whether the given document is a slave document known to this slave document manager. A slave document - * is known to this slave document manager, if the document has been created by this manager. - * - * @param document the document to be checked whether it is a slave document known to this manager - * @return <code>true</code> if the document is a slave document, <code>false</code> otherwise - */ - boolean isSlaveDocument(IDocument document); - - /** - * Sets the given slave document's auto expand mode. In auto expand mode, a - * slave document is automatically adapted to reflect all changes applied to it's master document. - * Assume a master document contains 30 lines and the slave is defined to contain the lines 11-20. - * In auto expand mode, when the master document is changed at line 8, the slave document is expanded - * to contain the lines 8-20.<p> - * This call is without effect if the given document is unknown to this slave document manager. - * - * @param slave the slave whose auto expand mode should be set - * @param autoExpand <code>true</code> for auto expand, <code>false</code> otherwise - */ - void setAutoExpandMode(IDocument slave, boolean autoExpand); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManagerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManagerExtension.java deleted file mode 100644 index af1485af359..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ISlaveDocumentManagerExtension.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Extension interface for {@link org.eclipse.jface.text.ISlaveDocumentManager}. - * <p> - * Adds access to the list of all slave documents for a given master document. - * - * @see org.eclipse.jface.text.ISlaveDocumentManager - * @since 3.0 - */ -public interface ISlaveDocumentManagerExtension { - - /** - * Returns the list of slave documents for the given master document or - * <code>null</code> if there are no such slave document. - * - * @param master the master document - * @return the list of slave documents or <code>null</code> - */ - IDocument[] getSlaveDocuments(IDocument master); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ISynchronizable.java b/org.eclipse.text/src/org/eclipse/jface/text/ISynchronizable.java deleted file mode 100644 index d82c1047535..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ISynchronizable.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - -/** - * Interface for text related objects which may be used in the multi-threaded - * context and thus must provide a way to prevent concurrent access and - * manipulation. - * <p> - * In order to reduce the probability of dead locks clients should synchronize - * their access to these objects by using the provided lock object rather than - * the object itself. - * <p> - * Managing objects can use the <code>setLockObject</code> method in order to - * synchronize whole sets of objects. - * - * @since 3.0 - */ -public interface ISynchronizable { - - /** - * Sets the lock object for this object. If the lock object is not - * <code>null</code> subsequent calls to specified methods of this object - * are synchronized on this lock object. Which methods are synchronized is - * specified by the implementer. - * - * @param lockObject the lock object. May be <code>null</code>. - */ - void setLockObject(Object lockObject); - - /** - * Returns the lock object or <code>null</code> if there is none. Clients - * should use the lock object in order to synchronize concurrent access to - * the implementer. - * - * @return the lock object or <code>null</code> - */ - Object getLockObject(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java deleted file mode 100644 index 87a4a7795d9..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Interface for storing and managing text. - * <p> - * Provides access to the stored text and allows to manipulate it. Clients may - * implement this interface or use {@link org.eclipse.jface.text.GapTextStore} and - * {@link org.eclipse.jface.text.SequentialRewriteTextStore}. - */ -public interface ITextStore { - - /** - * Returns the character at the specified offset. - * - * @param offset the offset in this text store - * @return the character at this offset - */ - char get(int offset); - - /** - * Returns the text of the specified character range. - * - * @param offset the offset of the range - * @param length the length of the range - * @return the text of the range - */ - String get(int offset, int length); - - /** - * Returns number of characters stored in this text store. - * - * @return the number of characters stored in this text store - */ - int getLength(); - - /** - * Replaces the specified character range with the given text. - * <code>replace(getLength(), 0, "some text")</code> is a valid - * call and appends text to the end of the text store. - * - * @param offset the offset of the range to be replaced - * @param length the number of characters to be replaced - * @param text the substitution text - */ - void replace(int offset, int length, String text); - - /** - * Replace the content of the text store with the given text. - * Convenience method for <code>replace(0, getLength(), text</code>. - * - * @param text the new content of the text store - */ - void set(String text); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java deleted file mode 100644 index 66c335afde7..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Describes a region of an indexed text store such as a document or a string. - * The region consists of offset, length, and type. The region type is defined - * as a string. - * <p> - * A typed region can, e.g., be used to described document partitions. Clients - * may implement this interface or use the standard implementation - * {@link org.eclipse.jface.text.TypedRegion}. - */ -public interface ITypedRegion extends IRegion { - - /** - * Returns the content type of the region. - * - * @return the content type of the region - */ - String getType(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Line.java b/org.eclipse.text/src/org/eclipse/jface/text/Line.java deleted file mode 100644 index c843cab00fe..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Line.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Describes a line as a particular number of characters beginning at - * a particular offset, consisting of a particular number of characters, - * and being closed with a particular line delimiter. - */ -class Line implements IRegion { - - /** The offset of the line */ - public int offset; - /** The length of the line */ - public int length; - /** The delimiter of this line */ - public String delimiter; - - /** - * Creates a new Line. - * - * @param offset the offset of the line - * @param end the last including character offset of the line - * @param delimiter the line's delimiter - */ - public Line(int offset, int end, String delimiter) { - this.offset= offset; - this.length= (end - offset) +1; - this.delimiter= delimiter; - } - - /** - * Creates a new Line. - * - * @param offset the offset of the line - * @param length the length of the line - */ - public Line(int offset, int length) { - this.offset= offset; - this.length= length; - this.delimiter= null; - } - - /* - * @see org.eclipse.jface.text.IRegion#getOffset() - */ - public int getOffset() { - return offset; - } - - /* - * @see org.eclipse.jface.text.IRegion#getLength() - */ - public int getLength() { - return length; - } -} - - diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Position.java b/org.eclipse.text/src/org/eclipse/jface/text/Position.java deleted file mode 100644 index 09127fdc072..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Position.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * Positions describe text ranges of a document. Positions are adapted to - * changes applied to that document. The text range is specified by an offset - * and a length. Positions can be marked as deleted. Deleted positions are - * considered to no longer represent a valid text range in the managing - * document. - * <p> - * Positions attached to documents are usually updated by position updaters. - * Because position updaters are freely definable and because of the frequency - * in which they are used, the fields of a position are made publicly - * accessible. Clients other than position updaters are not allowed to access - * these public fields. - * <p> - * Position can not be used as keys in hash tables as they override - * <code>equals</code> and <code>hashCode</code> as they would be value - * objects. - * - * @see org.eclipse.jface.text.IDocument - */ -public class Position { - - /** The offset of the position */ - public int offset; - /** The length of the position */ - public int length; - /** Indicates whether the position has been deleted */ - public boolean isDeleted; - - /** - * Creates a new position with the given offset and length 0. - * - * @param offset the position offset, must be >= 0 - */ - public Position(int offset) { - this(offset, 0); - } - - /** - * Creates a new position with the given offset and length. - * - * @param offset the position offset, must be >= 0 - * @param length the position length, must be >= 0 - */ - public Position(int offset, int length) { - Assert.isTrue(offset >= 0); - Assert.isTrue(length >= 0); - this.offset= offset; - this.length= length; - } - - /** - * Creates a new, not initialized position. - */ - protected Position() { - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int deleted= isDeleted ? 0 : 1; - return (offset << 24) | (length << 16) | deleted; - } - - /** - * Marks this position as deleted. - */ - public void delete() { - isDeleted= true; - } - - /** - * Marks this position as not deleted. - * - * @since 2.0 - */ - public void undelete() { - isDeleted= false; - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object other) { - if (other instanceof Position) { - Position rp= (Position) other; - return (rp.offset == offset) && (rp.length == length); - } - return super.equals(other); - } - - /** - * Returns the length of this position. - * - * @return the length of this position - */ - public int getLength() { - return length; - } - - /** - * Returns the offset of this position. - * - * @return the length of this position - */ - public int getOffset() { - return offset; - } - - /** - * Checks whether the given offset is inside - * of this position's text range. - * - * @param offset the offset to check - * @return <code>true</code> if offset is inside of this position - */ - public boolean includes(int offset) { - - if (isDeleted) - return false; - - return (this.offset <= offset) && (offset < this.offset + length); - } - - /** - * Checks whether the intersection of the given text range - * and the text range represented by this position is empty - * or not. - * - * @param offset the offset of the range to check - * @param length the length of the range to check - * @return <code>true</code> if intersection is not empty - */ - public boolean overlapsWith(int offset, int length) { - - if (isDeleted) - return false; - - int end= offset + length; - int thisEnd= this.offset + this.length; - - if (length > 0) { - if (this.length > 0) - return this.offset < end && offset < thisEnd; - return offset <= this.offset && this.offset < end; - } - - if (this.length > 0) - return this.offset <= offset && offset < thisEnd; - return this.offset == offset; - } - - /** - * Returns whether this position has been deleted or not. - * - * @return <code>true</code> if position has been deleted - */ - public boolean isDeleted() { - return isDeleted; - } - - /** - * Changes the length of this position to the given length. - * - * @param length the new length of this position - */ - public void setLength(int length) { - Assert.isTrue(length >= 0); - this.length= length; - } - - /** - * Changes the offset of this position to the given offset. - * - * @param offset the new offset of this position - */ - public void setOffset(int offset) { - Assert.isTrue(offset >= 0); - this.offset= offset; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Region.java b/org.eclipse.text/src/org/eclipse/jface/text/Region.java deleted file mode 100644 index c6fd326de8d..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Region.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * The default implementation of the {@link org.eclipse.jface.text.IRegion} interface. - */ -public class Region implements IRegion { - - /** The region offset */ - private int fOffset; - /** The region length */ - private int fLength; - - /** - * Create a new region. - * - * @param offset the offset of the region - * @param length the length of the region - */ - public Region(int offset, int length) { - fOffset= offset; - fLength= length; - } - - /* - * @see org.eclipse.jface.text.IRegion#getLength() - */ - public int getLength() { - return fLength; - } - - /* - * @see org.eclipse.jface.text.IRegion#getOffset() - */ - public int getOffset() { - return fOffset; - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (o instanceof IRegion) { - IRegion r= (IRegion) o; - return r.getOffset() == fOffset && r.getLength() == fLength; - } - return false; - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return (fOffset << 24) | (fLength << 16); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java deleted file mode 100644 index 7313b684e5c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - - -/** - * A text store that optimizes a given source text store for sequential rewriting. - * While rewritten it keeps a list of replace command that serve as patches for - * the source store. Only on request, the source store is indeed manipulated - * by applying the patch commands to the source text store. - * - * @since 2.0 - */ -public class SequentialRewriteTextStore implements ITextStore { - - /** - * A buffered replace command. - */ - private static class Replace { - public int newOffset; - public final int offset; - public final int length; - public final String text; - - public Replace(int offset, int newOffset, int length, String text) { - this.newOffset= newOffset; - this.offset= offset; - this.length= length; - this.text= text; - } - } - - /** The list of buffered replacements. */ - private List fReplaceList; - /** The source text store */ - private ITextStore fSource; - /** A flag to enforce sequential access. */ - private static final boolean ASSERT_SEQUENTIALITY= false; - - - /** - * Creates a new sequential rewrite store for the given source store. - * - * @param source the source text store - */ - public SequentialRewriteTextStore(ITextStore source) { - fReplaceList= new LinkedList(); - fSource= source; - } - - /** - * Returns the source store of this rewrite store. - * - * @return the source store of this rewrite store - */ - public ITextStore getSourceStore() { - commit(); - return fSource; - } - - /* - * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String) - */ - public void replace(int offset, int length, String text) { - - if (fReplaceList.size() == 0) { - fReplaceList.add(new Replace(offset, offset, length, text)); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // backward - if (offset + length <= firstReplace.newOffset) { - int delta= text.length() - length; - if (delta != 0) { - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - replace.newOffset += delta; - } - } - - fReplaceList.add(0, new Replace(offset, offset, length, text)); - - // forward - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - fReplaceList.add(new Replace(offset - delta, offset, length, text)); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - commit(); - fSource.replace(offset, length, text); - } - } - } - - /* - * @see org.eclipse.jface.text.ITextStore#set(java.lang.String) - */ - public void set(String text) { - fSource.set(text); - fReplaceList.clear(); - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int, int) - */ - public String get(int offset, int length) { - - if (fReplaceList.size() == 0) { - return fSource.get(offset, length); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // before - if (offset + length <= firstReplace.newOffset) { - return fSource.get(offset, length); - - // after - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - return fSource.get(offset - delta, length); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - if (offset + length < replace.newOffset) { - return fSource.get(offset - delta, length); - - } else if (offset >= replace.newOffset && offset + length <= replace.newOffset + replace.text.length()) { - return replace.text.substring(offset - replace.newOffset, offset - replace.newOffset + length); - - } else if (offset >= replace.newOffset + replace.text.length()) { - delta= getDelta(replace); - continue; - - } else { - commit(); - return fSource.get(offset, length); - } - } - - return fSource.get(offset - delta, length); - } - } - } - - /** - * Returns the difference between the offset in the source store and the "same" offset in the - * rewrite store after the replace operation. - * - * @param replace the replace command - * @return the difference - */ - private static final int getDelta(Replace replace) { - return replace.newOffset - replace.offset + replace.text.length() - replace.length; - } - - /* - * @see org.eclipse.jface.text.ITextStore#get(int) - */ - public char get(int offset) { - if (fReplaceList.size() == 0) { - return fSource.get(offset); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // before - if (offset < firstReplace.newOffset) { - return fSource.get(offset); - - // after - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - return fSource.get(offset - delta); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - if (offset < replace.newOffset) - return fSource.get(offset - delta); - - else if (offset < replace.newOffset + replace.text.length()) - return replace.text.charAt(offset - replace.newOffset); - - delta= getDelta(replace); - } - - return fSource.get(offset - delta); - } - } - } - - /* - * @see org.eclipse.jface.text.ITextStore#getLength() - */ - public int getLength() { - if (fReplaceList.size() == 0) { - return fSource.getLength(); - - } else { - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - return fSource.getLength() + getDelta(lastReplace); - } - } - - /** - * Disposes this rewrite store. - */ - public void dispose() { - fReplaceList= null; - fSource= null; - } - - /** - * Commits all buffered replace commands. - */ - private void commit() { - - if (fReplaceList.size() == 0) - return; - - StringBuffer buffer= new StringBuffer(); - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - int offset= buffer.length() - delta; - buffer.append(fSource.get(offset, replace.offset - offset)); - buffer.append(replace.text); - delta= getDelta(replace); - } - - int offset= buffer.length() - delta; - buffer.append(fSource.get(offset, fSource.getLength() - offset)); - - fSource.set(buffer.toString()); - fReplaceList.clear(); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/SlaveDocumentEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/SlaveDocumentEvent.java deleted file mode 100644 index 8161c8e4123..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/SlaveDocumentEvent.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -/** - * A slave document event represents a master document event as a slave-relative - * document event. It also carries the master document event. - */ -public class SlaveDocumentEvent extends DocumentEvent { - - /** The master document event */ - private DocumentEvent fMasterEvent; - - /** - * Creates a new slave document event. - * - * @param doc the slave document - * @param offset the offset in the slave document - * @param length the length in the slave document - * @param text the substitution text - * @param masterEvent the master document event - */ - public SlaveDocumentEvent(IDocument doc, int offset, int length, String text, DocumentEvent masterEvent) { - super(doc, offset, length, text); - fMasterEvent= masterEvent; - } - - /** - * Returns this event's master event. - * - * @return this event's master event - */ - public DocumentEvent getMasterEvent() { - return fMasterEvent; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java deleted file mode 100644 index b8ea5e0575f..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java +++ /dev/null @@ -1,529 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; - - -/** - * A collection of text functions. - */ -public class TextUtilities { - - /** - * Default line delimiters used by the text functions of this class. - */ - public final static String[] DELIMITERS= new String[] { "\n", "\r", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - /** - * Default line delimiters used by these text functions. - * - * @deprecated use DELIMITERS instead - */ - public final static String[] fgDelimiters= DELIMITERS; - - - - /** - * Determines which one of default line delimiters appears first in the list. If none of them the - * hint is returned. - * - * @param text the text to be checked - * @param hint the line delimiter hint - * @return the line delimiter - */ - public static String determineLineDelimiter(String text, String hint) { - try { - int[] info= indexOf(DELIMITERS, text, 0); - return DELIMITERS[info[1]]; - } catch (ArrayIndexOutOfBoundsException x) { - } - return hint; - } - - /** - * Returns the starting position and the index of the longest matching search string - * in the given text that is greater than the given offset. Returns <code>[-1, -1]</code> - * if no match can be found. - * - * @param searchStrings the strings to search for - * @param text the text to be searched - * @param offset the offset at which to start the search - * @return an <code>int[]</code> with two elements" the first is the starting offset, the second the index of the found - * search string in the given <code>searchStrings</code> array, returns <code>[-1, -1]</code> if no match exists - */ - public static int[] indexOf(String[] searchStrings, String text, int offset) { - - int[] result= { -1, -1 }; - int zeroIndex= -1; - - for (int i= 0; i < searchStrings.length; i++) { - - int length= searchStrings[i].length(); - - if (length == 0) { - zeroIndex= i; - continue; - } - - int index= text.indexOf(searchStrings[i], offset); - if (index >= 0) { - - if (result[0] == -1) { - result[0]= index; - result[1]= i; - } else if (index < result[0]) { - result[0]= index; - result[1]= i; - } else if (index == result[0] && length > searchStrings[result[1]].length()) { - result[0]= index; - result[1]= i; - } - } - } - - if (zeroIndex > -1 && result[0] == -1) { - result[0]= 0; - result[1]= zeroIndex; - } - - return result; - } - - /** - * Returns the index of the longest search string with which the given text ends or - * <code>-1</code> if none matches. - * - * @param searchStrings the strings to search for - * @param text the text to search - * @return the index in <code>searchStrings</code> of the longest string with which <code>text</code> ends or <code>-1</code> - */ - public static int endsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.endsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns the index of the longest search string with which the given text starts or <code>-1</code> - * if none matches. - * - * @param searchStrings the strings to search for - * @param text the text to search - * @return the index in <code>searchStrings</code> of the longest string with which <code>text</code> starts or <code>-1</code> - */ - public static int startsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.startsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns the index of the first compare string that equals the given text or <code>-1</code> - * if none is equal. - * - * @param compareStrings the strings to compare with - * @param text the text to check - * @return the index of the first equal compare string or <code>-1</code> - */ - public static int equals(String[] compareStrings, String text) { - for (int i= 0; i < compareStrings.length; i++) { - if (text.equals(compareStrings[i])) - return i; - } - return -1; - } - - /** - * Returns a document event which is an accumulation of a list of document events, - * <code>null</code> if the list of documentEvents is empty. - * The document of the document events are ignored. - * - * @param unprocessedDocument the document to which the document events would be applied - * @param documentEvents the list of document events to merge - * @return returns the merged document event - * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events - */ - public static DocumentEvent mergeUnprocessedDocumentEvents(IDocument unprocessedDocument, List documentEvents) throws BadLocationException { - - if (documentEvents.size() == 0) - return null; - - final Iterator iterator= documentEvents.iterator(); - final DocumentEvent firstEvent= (DocumentEvent) iterator.next(); - - // current merged event - final IDocument document= unprocessedDocument; - int offset= firstEvent.getOffset(); - int length= firstEvent.getLength(); - final StringBuffer text= new StringBuffer(firstEvent.getText() == null ? "" : firstEvent.getText()); //$NON-NLS-1$ - - while (iterator.hasNext()) { - - final int delta= text.length() - length; - - final DocumentEvent event= (DocumentEvent) iterator.next(); - final int eventOffset= event.getOffset(); - final int eventLength= event.getLength(); - final String eventText= event.getText() == null ? "" : event.getText(); //$NON-NLS-1$ - - // event is right from merged event - if (eventOffset > offset + length + delta) { - final String string= document.get(offset + length, (eventOffset - delta) - (offset + length)); - text.append(string); - text.append(eventText); - - length= (eventOffset - delta) + eventLength - offset; - - // event is left from merged event - } else if (eventOffset + eventLength < offset) { - final String string= document.get(eventOffset + eventLength, offset - (eventOffset + eventLength)); - text.insert(0, string); - text.insert(0, eventText); - - length= offset + length - eventOffset; - offset= eventOffset; - - // events overlap each other - } else { - final int start= Math.max(0, eventOffset - offset); - final int end= Math.min(text.length(), eventLength + eventOffset - offset); - text.replace(start, end, eventText); - - offset= Math.min(offset, eventOffset); - final int totalDelta= delta + eventText.length() - eventLength; - length= text.length() - totalDelta; - } - } - - return new DocumentEvent(document, offset, length, text.toString()); - } - - /** - * Returns a document event which is an accumulation of a list of document events, - * <code>null</code> if the list of document events is empty. - * The document events being merged must all refer to the same document, to which - * the document changes have been already applied. - * - * @param documentEvents the list of document events to merge - * @return returns the merged document event - * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events - */ - public static DocumentEvent mergeProcessedDocumentEvents(List documentEvents) throws BadLocationException { - - if (documentEvents.size() == 0) - return null; - - final ListIterator iterator= documentEvents.listIterator(documentEvents.size()); - final DocumentEvent firstEvent= (DocumentEvent) iterator.previous(); - - // current merged event - final IDocument document= firstEvent.getDocument(); - int offset= firstEvent.getOffset(); - int length= firstEvent.getLength(); - int textLength= firstEvent.getText() == null ? 0 : firstEvent.getText().length(); - - while (iterator.hasPrevious()) { - - final int delta= length - textLength; - - final DocumentEvent event= (DocumentEvent) iterator.previous(); - final int eventOffset= event.getOffset(); - final int eventLength= event.getLength(); - final int eventTextLength= event.getText() == null ? 0 : event.getText().length(); - - // event is right from merged event - if (eventOffset > offset + textLength + delta) { - length= (eventOffset - delta) - (offset + textLength) + length + eventLength; - textLength= (eventOffset - delta) + eventTextLength - offset; - - // event is left from merged event - } else if (eventOffset + eventTextLength < offset) { - length= offset - (eventOffset + eventTextLength) + length + eventLength; - textLength= offset + textLength - eventOffset; - offset= eventOffset; - - // events overlap each other - } else { - final int start= Math.max(0, eventOffset - offset); - final int end= Math.min(length, eventTextLength + eventOffset - offset); - length += eventLength - (end - start); - - offset= Math.min(offset, eventOffset); - final int totalDelta= delta + eventLength - eventTextLength; - textLength= length - totalDelta; - } - } - - final String text= document.get(offset, textLength); - return new DocumentEvent(document, offset, length, text); - } - - /** - * Removes all connected document partitioners from the given document and stores them - * under their partitioning name in a map. This map is returned. After this method has been called - * the given document is no longer connected to any document partitioner. - * - * @param document the document - * @return the map containing the removed partitioners - */ - public static Map removeDocumentPartitioners(IDocument document) { - Map partitioners= new HashMap(); - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - String[] partitionings= extension3.getPartitionings(); - for (int i= 0; i < partitionings.length; i++) { - IDocumentPartitioner partitioner= extension3.getDocumentPartitioner(partitionings[i]); - if (partitioner != null) { - extension3.setDocumentPartitioner(partitionings[i], null); - partitioner.disconnect(); - partitioners.put(partitionings[i], partitioner); - } - } - } else { - IDocumentPartitioner partitioner= document.getDocumentPartitioner(); - if (partitioner != null) { - document.setDocumentPartitioner(null); - partitioner.disconnect(); - partitioners.put(IDocumentExtension3.DEFAULT_PARTITIONING, partitioner); - } - } - return partitioners; - } - - /** - * Connects the given document with all document partitioners stored in the given map under - * their partitioning name. This method cleans the given map. - * - * @param document the document - * @param partitioners the map containing the partitioners to be connected - * @since 3.0 - */ - public static void addDocumentPartitioners(IDocument document, Map partitioners) { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - Iterator e= partitioners.keySet().iterator(); - while (e.hasNext()) { - String partitioning= (String) e.next(); - IDocumentPartitioner partitioner= (IDocumentPartitioner) partitioners.get(partitioning); - partitioner.connect(document); - extension3.setDocumentPartitioner(partitioning, partitioner); - } - partitioners.clear(); - } else { - IDocumentPartitioner partitioner= (IDocumentPartitioner) partitioners.get(IDocumentExtension3.DEFAULT_PARTITIONING); - partitioner.connect(document); - document.setDocumentPartitioner(partitioner); - } - } - - /** - * Returns the content type at the given offset of the given document. - * - * @param document the document - * @param partitioning the partitioning to be used - * @param offset the offset - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over a - * closed partition starting at <code>offset</code> - * @return the content type at the given offset of the document - * @throws BadLocationException if offset is invalid in the document - * @since 3.0 - */ - public static String getContentType(IDocument document, String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - try { - return extension3.getContentType(partitioning, offset, preferOpenPartitions); - } catch (BadPartitioningException x) { - return IDocument.DEFAULT_CONTENT_TYPE; - } - } else { - return document.getContentType(offset); - } - } - - /** - * Returns the partition of the given offset of the given document. - * - * @param document the document - * @param partitioning the partitioning to be used - * @param offset the offset - * @param preferOpenPartitions <code>true</code> if precedence should be - * given to a open partition ending at <code>offset</code> over a - * closed partition starting at <code>offset</code> - * @return the content type at the given offset of this viewer's input - * document - * @throws BadLocationException if offset is invalid in the given document - * @since 3.0 - */ - public static ITypedRegion getPartition(IDocument document, String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - try { - return extension3.getPartition(partitioning, offset, preferOpenPartitions); - } catch (BadPartitioningException x) { - return new TypedRegion(0, document.getLength(), IDocument.DEFAULT_CONTENT_TYPE); - } - } else { - return document.getPartition(offset); - } - } - - /** - * Computes and returns the partitioning for the given region of the given - * document for the given partitioning name. - * - * @param document the document - * @param partitioning the partitioning name - * @param offset the region offset - * @param length the region length - * @param includeZeroLengthPartitions whether to include zero-length partitions - * @return the partitioning for the given region of the given document for - * the given partitioning name - * @throws BadLocationException if the given region is invalid for the given - * document - * @since 3.0 - */ - public static ITypedRegion[] computePartitioning(IDocument document, String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - try { - return extension3.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions); - } catch (BadPartitioningException x) { - return new ITypedRegion[0]; - } - } else { - return document.computePartitioning(offset, length); - } - } - - /** - * Computes and returns the partition managing position categories for the - * given document or <code>null</code> if this was impossible. - * - * @param document the document - * @return the partition managing position categories - * @since 3.0 - */ - public static String[] computePartitionManagingCategories(IDocument document) { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension3= (IDocumentExtension3) document; - String[] partitionings= extension3.getPartitionings(); - if (partitionings != null) { - Set categories= new HashSet(); - for (int i= 0; i < partitionings.length; i++) { - IDocumentPartitioner p= extension3.getDocumentPartitioner(partitionings[i]); - if (p instanceof IDocumentPartitionerExtension2) { - IDocumentPartitionerExtension2 extension2= (IDocumentPartitionerExtension2) p; - String[] c= extension2.getManagingPositionCategories(); - if (c != null) { - for (int j= 0; j < c.length; j++) - categories.add(c[j]); - } - } - } - String[] result= new String[categories.size()]; - categories.toArray(result); - return result; - } - } - return null; - } - - /** - * Returns the default line delimiter for the given document. This is either the delimiter of the first line, or the platform line delimiter if it is - * a legal line delimiter or the first one of the legal line delimiters. The default line delimiter should be used when performing document - * manipulations that span multiple lines. - * - * @param document the document - * @return the document's default line delimiter - * @since 3.0 - */ - public static String getDefaultLineDelimiter(IDocument document) { - - String lineDelimiter= null; - - try { - lineDelimiter= document.getLineDelimiter(0); - } catch (BadLocationException x) { - } - - if (lineDelimiter == null) { - String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ - String[] delimiters= document.getLegalLineDelimiters(); - Assert.isTrue(delimiters.length > 0); - for (int i= 0; i < delimiters.length; i++) { - if (delimiters[i].equals(sysLineDelimiter)) { - lineDelimiter= sysLineDelimiter; - break; - } - } - - if (lineDelimiter == null) - lineDelimiter= delimiters[0]; - } - - return lineDelimiter; - } - - /** - * Returns <code>true</code> if the two regions overlap. Returns <code>false</code> if one of the - * arguments is <code>null</code>. - * - * @param left the left region - * @param right the right region - * @return <code>true</code> if the two regions overlap, <code>false</code> otherwise - * @since 3.0 - */ - public static boolean overlaps(IRegion left, IRegion right) { - - if (left == null || right == null) - return false; - - int rightEnd= right.getOffset() + right.getLength(); - int leftEnd= left.getOffset()+ left.getLength(); - - if (right.getLength() > 0) { - if (left.getLength() > 0) - return left.getOffset() < rightEnd && right.getOffset() < leftEnd; - return right.getOffset() <= left.getOffset() && left.getOffset() < rightEnd; - } - - if (left.getLength() > 0) - return left.getOffset() <= right.getOffset() && right.getOffset() < leftEnd; - - return left.getOffset() == right.getOffset(); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java b/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java deleted file mode 100644 index d0b089bb13b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Convenience class for positions that have a type, similar to - * {@link org.eclipse.jface.text.ITypedRegion}. - * <p> - * As {@link org.eclipse.jface.text.Position},<code>TypedPosition</code> can - * not be used as key in hash tables as it overrides <code>equals</code> and - * <code>hashCode</code> as it would be a value object. - */ -public class TypedPosition extends Position { - - /** The type of the region described by this position */ - private String fType; - - /** - * Creates a position along the given specification. - * - * @param offset the offset of this position - * @param length the length of this position - * @param type the type of this position - */ - public TypedPosition(int offset, int length, String type) { - super(offset, length); - fType= type; - } - - /** - * Creates a position based on the typed region. - * - * @param region the typed region - */ - public TypedPosition(ITypedRegion region) { - super(region.getOffset(), region.getLength()); - fType= region.getType(); - } - - /** - * Returns the type of the position - * - * @return the type of this position - */ - public String getType() { - return fType; - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (o instanceof TypedPosition) { - if (super.equals(o)) { - TypedPosition p= (TypedPosition) o; - return (fType == null && p.getType() == null) || fType.equals(p.getType()); - } - } - return false; - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int type= fType == null ? 0 : fType.hashCode(); - return super.hashCode() | type; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java deleted file mode 100644 index 42fe410f3ae..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text; - - - -/** - * Default implementation of {@link org.eclipse.jface.text.ITypedRegion}. A - * <code>TypedRegion</code> is a value object. - */ -public class TypedRegion extends Region implements ITypedRegion { - - /** The region's type */ - private String fType; - - /** - * Creates a typed region based on the given specification. - * - * @param offset the region's offset - * @param length the region's length - * @param type the region's type - */ - public TypedRegion(int offset, int length, String type) { - super(offset, length); - fType= type; - } - - /* - * @see org.eclipse.jface.text.ITypedRegion#getType() - */ - public String getType() { - return fType; - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (o instanceof TypedRegion) { - TypedRegion r= (TypedRegion) o; - return super.equals(r) && ((fType == null && r.getType() == null) || fType.equals(r.getType())); - } - return false; - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int type= fType == null ? 0 : fType.hashCode(); - return super.hashCode() | type; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/ILinkedModeListener.java b/org.eclipse.text/src/org/eclipse/jface/text/link/ILinkedModeListener.java deleted file mode 100644 index 7fa43152d9d..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/ILinkedModeListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -/** - * Protocol used by {@link LinkedModeModel}s to communicate state changes, such - * as leaving linked mode, suspending it due to a child mode coming up, and - * resuming after a child mode has left. - * <p> - * This interface may implemented by clients. - * </p> - * - * @since 3.0 - */ -public interface ILinkedModeListener { - - /** Flag to <code>leave</code> specifying no special action. */ - int NONE= 0; - /** - * Flag to <code>leave</code> specifying that all nested modes should - * exit. - */ - int EXIT_ALL= 1 << 0; - /** - * Flag to <code>leave</code> specifying that the caret should be moved to - * the exit position. - */ - int UPDATE_CARET= 1 << 1; - /** - * Flag to <code>leave</code> specifying that a UI of a parent mode should - * select the current position. - */ - int SELECT= 1 << 2; - /** - * Flag to <code>leave</code> specifying that document content outside of - * a linked position was modified. - */ - int EXTERNAL_MODIFICATION= 1 << 3; - - /** - * The leave event occurs when linked is left. - * - * @param model the model being left - * @param flags the reason and commands for leaving linked mode - */ - void left(LinkedModeModel model, int flags); - - /** - * The suspend event occurs when a nested linked mode is installed within - * <code>model</code>. - * - * @param model the model being suspended due to a nested model being - * installed - */ - void suspend(LinkedModeModel model); - - /** - * The resume event occurs when a nested linked mode exits. - * - * @param model the linked mode model being resumed due to a nested mode - * exiting - * @param flags the commands to execute when resuming after suspend - */ - void resume(LinkedModeModel model, int flags); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/InclusivePositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/link/InclusivePositionUpdater.java deleted file mode 100644 index 5003a794236..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/InclusivePositionUpdater.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -import org.eclipse.jface.text.BadPositionCategoryException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.Position; - -/** - * Position updater that takes any change in - * <code>[position.offset, position.offset + position.length]</code> as - * belonging to the position. - * <p> - * Internal class. Do not use. Public for testing purposes only. - * </p> - * - * @since 3.0 - */ -public class InclusivePositionUpdater implements IPositionUpdater { - - /** The position category. */ - private final String fCategory; - - /** - * Creates a new updater for the given <code>category</code>. - * - * @param category the new category. - */ - public InclusivePositionUpdater(String category) { - fCategory= category; - } - - /* - * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) - */ - public void update(DocumentEvent event) { - - int eventOffset= event.getOffset(); - int eventOldLength= event.getLength(); - int eventNewLength= event.getText() == null ? 0 : event.getText().length(); - int deltaLength= eventNewLength - eventOldLength; - - try { - Position[] positions= event.getDocument().getPositions(fCategory); - - for (int i= 0; i != positions.length; i++) { - - Position position= positions[i]; - - if (position.isDeleted()) - continue; - - int offset= position.getOffset(); - int length= position.getLength(); - int end= offset + length; - - if (offset > eventOffset + eventOldLength) - // position comes way - // after change - shift - position.setOffset(offset + deltaLength); - else if (end < eventOffset) { - // position comes way before change - - // leave alone - } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { - // event completely internal to the position - adjust length - position.setLength(length + deltaLength); - } else if (offset < eventOffset) { - // event extends over end of position - adjust length - int newEnd= eventOffset + eventNewLength; - position.setLength(newEnd - offset); - } else if (end > eventOffset + eventOldLength) { - // event extends from before position into it - adjust offset - // and length - // offset becomes end of event, length adjusted accordingly - // we want to recycle the overlapping part - position.setOffset(eventOffset); - int deleted= eventOffset + eventOldLength - offset; - position.setLength(length - deleted + eventNewLength); - } else { - // event consumes the position - delete it - position.delete(); - } - } - } catch (BadPositionCategoryException e) { - // ignore and return - } - } - - /** - * Returns the position category. - * - * @return the position category - */ - public String getCategory() { - return fCategory; - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java deleted file mode 100644 index 6172996dab9..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.IDocument; - - -/** - * A linked mode manager ensures exclusive access of linked position infrastructures to documents. There - * is at most one <code>LinkedModeManager</code> installed on the same document. The <code>getManager</code> - * methods will return the existing instance if any of the specified documents already have an installed - * manager. - * - * @since 3.0 - */ -class LinkedModeManager { - - /** - * Our implementation of <code>ILinkedModeListener</code>. - */ - private class Listener implements ILinkedModeListener { - - /* - * @see org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel.ILinkedModeListener#left(org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel, int) - */ - public void left(LinkedModeModel model, int flags) { - LinkedModeManager.this.left(model, flags); - } - - /* - * @see org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel.ILinkedModeListener#suspend(org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel) - */ - public void suspend(LinkedModeModel model) { - // not interested - } - - /* - * @see org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel.ILinkedModeListener#resume(org.eclipse.jdt.internal.ui.text.link2.LinkedModeModel, int) - */ - public void resume(LinkedModeModel model, int flags) { - // not interested - } - - } - - /** Global map from documents to managers. */ - private static Map fManagers= new HashMap(); - - /** - * Returns whether there exists a <code>LinkedModeManager</code> on <code>document</code>. - * - * @param document the document of interest - * @return <code>true</code> if there exists a <code>LinkedModeManager</code> on <code>document</code>, <code>false</code> otherwise - */ - public static boolean hasManager(IDocument document) { - return fManagers.get(document) != null; - } - - /** - * Returns whether there exists a <code>LinkedModeManager</code> on any of the <code>documents</code>. - * - * @param documents the documents of interest - * @return <code>true</code> if there exists a <code>LinkedModeManager</code> on any of the <code>documents</code>, <code>false</code> otherwise - */ - public static boolean hasManager(IDocument[] documents) { - for (int i= 0; i < documents.length; i++) { - if (hasManager(documents[i])) - return true; - } - return false; - } - - /** - * Returns the manager for the given documents. If <code>force</code> is - * <code>true</code>, any existing conflicting managers are canceled, otherwise, - * the method may return <code>null</code> if there are conflicts. - * - * @param documents the documents of interest - * @param force whether to kill any conflicting managers - * @return a manager able to cover the requested documents, or <code>null</code> if there is a conflict and <code>force</code> was set to <code>false</code> - */ - public static LinkedModeManager getLinkedManager(IDocument[] documents, boolean force) { - if (documents == null || documents.length == 0) - return null; - - Set mgrs= new HashSet(); - LinkedModeManager mgr= null; - for (int i= 0; i < documents.length; i++) { - mgr= (LinkedModeManager) fManagers.get(documents[i]); - if (mgr != null) - mgrs.add(mgr); - } - if (mgrs.size() > 1) - if (force) { - for (Iterator it= mgrs.iterator(); it.hasNext(); ) { - LinkedModeManager m= (LinkedModeManager) it.next(); - m.closeAllEnvironments(); - } - } else { - return null; - } - - if (mgrs.size() == 0) - mgr= new LinkedModeManager(); - - for (int i= 0; i < documents.length; i++) - fManagers.put(documents[i], mgr); - - return mgr; - } - - /** - * Cancels any linked mode manager for the specified document. - * - * @param document the document whose <code>LinkedModeManager</code> should be cancelled - */ - public static void cancelManager(IDocument document) { - LinkedModeManager mgr= (LinkedModeManager) fManagers.get(document); - if (mgr != null) - mgr.closeAllEnvironments(); - } - - /** The hierarchy of environments managed by this manager. */ - private Stack fEnvironments= new Stack(); - private Listener fListener= new Listener(); - - /** - * Notify the manager about a leaving model. - * - * @param model - * @param flags - */ - private void left(LinkedModeModel model, int flags) { - if (!fEnvironments.contains(model)) - return; - - while (!fEnvironments.isEmpty()) { - LinkedModeModel env= (LinkedModeModel) fEnvironments.pop(); - if (env == model) - break; - else - env.exit(ILinkedModeListener.NONE); - } - - if (fEnvironments.isEmpty()) { - removeManager(); - } - } - - private void closeAllEnvironments() { - while (!fEnvironments.isEmpty()) { - LinkedModeModel env= (LinkedModeModel) fEnvironments.pop(); - env.exit(ILinkedModeListener.NONE); - } - - removeManager(); - } - - private void removeManager() { - for (Iterator it= fManagers.keySet().iterator(); it.hasNext();) { - IDocument doc= (IDocument) it.next(); - if (fManagers.get(doc) == this) - it.remove(); - } - } - - /** - * Tries to nest the given <code>LinkedModeModel</code> onto the top of - * the stack of environments managed by the receiver. If <code>force</code> - * is <code>true</code>, any environments on the stack that create a conflict - * are killed. - * - * @param model the model to nest - * @param force whether to force the addition of the model - * @return <code>true</code> if nesting was successful, <code>false</code> otherwise (only possible if <code>force</code> is <code>false</code> - */ - public boolean nestEnvironment(LinkedModeModel model, boolean force) { - Assert.isNotNull(model); - - try { - while (true) { - if (fEnvironments.isEmpty()) { - model.addLinkingListener(fListener); - fEnvironments.push(model); - return true; - } - - LinkedModeModel top= (LinkedModeModel) fEnvironments.peek(); - if (model.canNestInto(top)) { - model.addLinkingListener(fListener); - fEnvironments.push(model); - return true; - } else if (!force) { - return false; - } else { // force - fEnvironments.pop(); - top.exit(ILinkedModeListener.NONE); - // continue; - } - } - } finally { - // if we remove any, make sure the new one got inserted - Assert.isTrue(fEnvironments.size() > 0); - } - } - - /** - * @return - */ - public LinkedModeModel getTopEnvironment() { - if (fEnvironments.isEmpty()) - return null; - else - return (LinkedModeModel) fEnvironments.peek(); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java deleted file mode 100644 index 98bd061600f..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java +++ /dev/null @@ -1,760 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.TextEdit; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.BadPositionCategoryException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.IDocumentExtension.IReplace; - -/** - * A <code>LinkedModeModel</code> umbrellas several - * <code>LinkedPositionGroup</code>s. Once installed, the model - * propagates any changes to a position to all its siblings in the same position - * group. - * <p> - * Setting up a model consists of first adding - * <code>LinkedPositionGroup</code> s to it, and then installing the - * model by either calling {@link #forceInstall()} or - * {@link #tryInstall()}. After installing the model, it becomes - * <em>sealed</em> and no more groups may be added. - * </p> - * <p> - * If the document is changed outside any linked position, the model is - * torn down and all positions are deleted. The same happens upon calling - * {@link #exit(int)}. - * </p> - * <h4>Nesting</h4> - * <p> - * A <code>LinkedModeModel</code> may be nested into another model. This - * happens when installing a model the positions of which all fit into a - * single position in a parent model that has previously been installed on - * the same document(s). - * </p> - * <p> - * Clients may instantiate instances of this class. - * </p> - * - * @since 3.0 - */ -public class LinkedModeModel { - - /** - * Checks whether there is already a model installed on <code>document</code>. - * - * @param document the <code>IDocument</code> of interest - * @return <code>true</code> if there is an existing model, <code>false</code> - * otherwise - */ - public static boolean hasInstalledModel(IDocument document) { - // if there is a manager, there also is a model - return LinkedModeManager.hasManager(document); - } - - /** - * Checks whether there is already a linked mode model installed on any of - * the <code>documents</code>. - * - * @param documents the <code>IDocument</code>s of interest - * @return <code>true</code> if there is an existing model, <code>false</code> - * otherwise - */ - public static boolean hasInstalledModel(IDocument[] documents) { - // if there is a manager, there also is a model - return LinkedModeManager.hasManager(documents); - } - - /** - * Cancels any linked mode model on the specified document. If there is no - * model, nothing happens. - * - * @param document the document whose <code>LinkedModeModel</code> should - * be cancelled - */ - public static void closeAllModels(IDocument document) { - LinkedModeManager.cancelManager(document); - } - - /** - * Returns the model currently active on <code>document</code> at - * <code>offset</code>, or <code>null</code> if there is none. - * - * @param document the document for which the caller asks for a - * model - * @param offset the offset into <code>document</code>, as there may be - * several models on a document - * @return the model currently active on <code>document</code>, or - * <code>null</code> - */ - public static LinkedModeModel getModel(IDocument document, int offset) { - LinkedModeManager mgr= LinkedModeManager.getLinkedManager(new IDocument[] {document}, false); - if (mgr != null) - return mgr.getTopEnvironment(); - else - return null; - } - - /** - * Encapsulates the edition triggered by a change to a linking position. Can - * be applied to a document as a whole. - */ - private class Replace implements IReplace { - - /** The edition to apply on a document. */ - private TextEdit fEdit; - - /** - * Creates a new instance. - * - * @param edit the edition to apply to a document. - */ - public Replace(TextEdit edit) { - fEdit= edit; - } - - /* - * @see org.eclipse.jface.text.IDocumentExtension.IReplace#perform(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocumentListener) - */ - public void perform(IDocument document, IDocumentListener owner) throws RuntimeException, MalformedTreeException { - document.removeDocumentListener(owner); - fIsChanging= true; - try { - fEdit.apply(document, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO); - } catch (BadLocationException e) { - /* perform should really throw a BadLocationException - * TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=52950 - */ - throw new RuntimeException(e); - } finally { - document.addDocumentListener(owner); - fIsChanging= false; - } - } - - } - - /** - * The document listener triggering the linked updating of positions - * managed by this model. - */ - private class DocumentListener implements IDocumentListener { - - private DocumentEvent fLastEvent; - private boolean fExit= false; - - /** - * Checks whether <code>event</code> occurs within any of the positions - * managed by this model. If not, the linked mode is left. - * - * @param event {@inheritDoc} - */ - public void documentAboutToBeChanged(DocumentEvent event) { - // don't react on changes executed by the parent model - if (fParentEnvironment != null && fParentEnvironment.isChanging()) - return; - - fExit= false; - fLastEvent= event; - - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - if (group.isLegalEvent(event)) - // take the first hit - exlusion is guaranteed by enforcing - // disjointness when adding positions - return; - } - - // the event describes a change that lies outside of any managed - // position -> signal to exit - // don't exit here already, since we want to make sure that the positions - // are updated to the document event. - // TODO we might not always want to exit, e.g. we want to stay - // linked if code completion has inserted import statements - fExit= true; - } - - /** - * Propagates a change to a linked position to all its sibling positions. - * - * @param event {@inheritDoc} - */ - public void documentChanged(DocumentEvent event) { - // don't react on changes executed by the parent model - if (fParentEnvironment != null && fParentEnvironment.isChanging()) - return; - - if (event.equals(fLastEvent) && fExit) - LinkedModeModel.this.exit(ILinkedModeListener.EXTERNAL_MODIFICATION); - - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - - Map result= group.handleEvent(event); - if (result == null) - continue; - - // edit all documents - for (Iterator it2= result.keySet().iterator(); it2.hasNext(); ) { - IDocument doc= (IDocument) it2.next(); - TextEdit edit= (TextEdit) result.get(doc); - Replace replace= new Replace(edit); - - // apply the edition, either as post notification replace - // on the calling document or directly on any other - // document - if (doc == event.getDocument()) { - if (doc instanceof IDocumentExtension) { - ((IDocumentExtension) doc).registerPostNotificationReplace(this, replace); - } else { - // ignore - there is no way we can log from jface text... - } - } else { - replace.perform(doc, this); - } - } - - // take the first hit - exlusion is guaranteed by enforcing - // disjointness when adding positions - return; - } - } - - } - - /** The set of linked position groups. */ - private final List fGroups= new ArrayList(); - /** The set of documents spanned by this group. */ - private final Set fDocuments= new HashSet(); - /** The position updater for linked positions. */ - private final IPositionUpdater fUpdater= new InclusivePositionUpdater(getCategory()); - /** The document listener on the documents affected by this model. */ - private final IDocumentListener fDocumentListener= new DocumentListener(); - /** The parent model for a hierarchical set up, or <code>null</code>. */ - private LinkedModeModel fParentEnvironment; - /** - * The position in <code>fParentEnvironment</code> that includes all - * positions in this object, or <code>null</code> if there is no parent - * model. - */ - private LinkedPosition fParentPosition= null; - /** - * A model is sealed once it has children - no more positions can be - * added. - */ - private boolean fIsSealed= false; - /** <code>true</code> when this model is changing documents. */ - private boolean fIsChanging= false; - /** The linked listeners. */ - private final List fListeners= new ArrayList(); - /** Flag telling whether we have exited: */ - private boolean fIsActive= true; - /** - * The sequence of document positions as we are going to iterate through - * them. - */ - private List fPositionSequence= new ArrayList(); - - /** - * Whether we are in the process of editing documents (set by <code>Replace</code>, - * read by <code>DocumentListener</code>. - * - * @return <code>true</code> if we are in the process of editing a - * document, <code>false</code> otherwise - */ - private boolean isChanging() { - return fIsChanging || fParentEnvironment != null && fParentEnvironment.isChanging(); - } - - /** - * Throws a <code>BadLocationException</code> if <code>group</code> - * conflicts with this model's groups. - * - * @param group the group being checked - * @throws BadLocationException if <code>group</code> conflicts with this - * model's groups - */ - private void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup g= (LinkedPositionGroup) it.next(); - g.enforceDisjoint(group); - } - } - - /** - * Causes this model to exit. Called either if a document change - * outside this model is detected, or by the UI. - * - * <p> - * This method part of the private protocol between - * <code>LinkedUIControl</code> and <code>LinkedModeModel</code>. - * </p> - * - * @param flags the exit flags. - */ - public void exit(int flags) { - if (!fIsActive) - return; - fIsActive= false; - - for (Iterator it= fDocuments.iterator(); it.hasNext(); ) { - IDocument doc= (IDocument) it.next(); - try { - doc.removePositionCategory(getCategory()); - } catch (BadPositionCategoryException e) { - // won't happen - Assert.isTrue(false); - } - doc.removePositionUpdater(fUpdater); - doc.removeDocumentListener(fDocumentListener); - } - - fDocuments.clear(); - fGroups.clear(); - - List listeners= new ArrayList(fListeners); - fListeners.clear(); - for (Iterator it= listeners.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); - listener.left(this, flags); - } - - - if (fParentEnvironment != null) - fParentEnvironment.resume(flags); - } - - /** - * Puts <code>document</code> into the set of managed documents. This - * involves registering the document listener and adding our position - * category. - * - * @param document the new document - */ - private void manageDocument(IDocument document) { - if (!fDocuments.contains(document)) { - fDocuments.add(document); - document.addPositionCategory(getCategory()); - document.addPositionUpdater(fUpdater); - document.addDocumentListener(fDocumentListener); - } - - } - - /** - * Returns the position category used by this model. - * - * @return the position category used by this model - */ - private String getCategory() { - return toString(); - } - - /** - * Adds a position group to this <code>LinkedModeModel</code>. This - * method may not be called if the model has been installed. Also, if - * a UI has been set up for this model, it may not pick up groups - * added afterwards. - * <p> - * If the positions in <code>group</code> conflict with any other group in - * this model, a <code>BadLocationException</code> is thrown. Also, - * if this model is nested inside another one, all positions in all - * groups of the child model have to reside within a single position in the - * parent model, otherwise a <code>BadLocationException</code> is thrown. - * </p> - * <p> - * If <code>group</code> already exists, nothing happens. - * </p> - * - * @param group the group to be added to this model - * @throws BadLocationException if the group conflicts with the other groups - * in this model or violates the nesting requirements. - * @throws IllegalStateException if the method is called when the - * model is already sealed - */ - public void addGroup(LinkedPositionGroup group) throws BadLocationException { - if (group == null) - throw new IllegalArgumentException("group may not be null"); //$NON-NLS-1$ - if (fIsSealed) - throw new IllegalStateException("model is already installed"); //$NON-NLS-1$ - if (fGroups.contains(group)) - // nothing happens - return; - - enforceDisjoint(group); - group.seal(); - fGroups.add(group); - } - - /** - * Installs this model, which includes registering as document - * listener on all involved documents and storing global information about - * this model. Any conflicting model already present will be - * closed. - * <p> - * If an exception is thrown, the installation failed and - * the model is unusable. - * </p> - * - * @throws BadLocationException if some of the positions of this model - * were not valid positions on their respective documents - */ - public void forceInstall() throws BadLocationException { - if (!install(true)) - Assert.isTrue(false); - } - - /** - * Installs this model, which includes registering as document - * listener on all involved documents and storing global information about - * this model. If there is another model installed on the - * document(s) targeted by the receiver that conflicts with it, installation - * may fail. - * <p> - * The return value states whether installation was - * successful; if not, the model is not installed and will not work. - * </p> - * - * @return <code>true</code> if installation was successful, - * <code>false</code> otherwise - * @throws BadLocationException if some of the positions of this model - * were not valid positions on their respective documents - */ - public boolean tryInstall() throws BadLocationException { - return install(false); - } - - /** - * Installs this model, which includes registering as document - * listener on all involved documents and storing global information about - * this model. The return value states whether installation was - * successful; if not, the model is not installed and will not work. - * The return value can only then become <code>false</code> if - * <code>force</code> was set to <code>false</code> as well. - * - * @param force if <code>true</code>, any other model that cannot - * coexist with this one is canceled; if <code>false</code>, - * install will fail when conflicts occur and return false - * @return <code>true</code> if installation was successful, - * <code>false</code> otherwise - * @throws BadLocationException if some of the positions of this model - * were not valid positions on their respective documents - */ - private boolean install(boolean force) throws BadLocationException { - if (fIsSealed) - throw new IllegalStateException("model is already installed"); //$NON-NLS-1$ - enforceNotEmpty(); - - IDocument[] documents= getDocuments(); - LinkedModeManager manager= LinkedModeManager.getLinkedManager(documents, force); - // if we force creation, we require a valid manager - Assert.isTrue(!(force && manager == null)); - if (manager == null) - return false; - - if (!manager.nestEnvironment(this, force)) - if (force) - Assert.isTrue(false); - else - return false; - - // we set up successfully. After this point, exit has to be called to - // remove registered listeners... - fIsSealed= true; - if (fParentEnvironment != null) - fParentEnvironment.suspend(); - - // register positions - try { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - group.register(this); - } - return true; - } catch (BadLocationException e){ - // if we fail to add, make sure to release all listeners again - exit(ILinkedModeListener.NONE); - throw e; - } - } - - /** - * Asserts that there is at least one linked position in this linked mode - * model, throws an IllegalStateException otherwise. - */ - private void enforceNotEmpty() { - boolean hasPosition= false; - for (Iterator it= fGroups.iterator(); it.hasNext(); ) - if (!((LinkedPositionGroup) it.next()).isEmtpy()) { - hasPosition= true; - break; - } - if (!hasPosition) - throw new IllegalStateException("must specify at least one linked position"); //$NON-NLS-1$ - - } - - /** - * Collects all the documents that contained positions are set upon. - * @return the set of documents affected by this model - */ - private IDocument[] getDocuments() { - Set docs= new HashSet(); - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - docs.addAll(Arrays.asList(group.getDocuments())); - } - return (IDocument[]) docs.toArray(new IDocument[docs.size()]); - } - - /** - * Returns whether the receiver can be nested into the given <code>parent</code> - * model. If yes, the parent model and its position that the receiver - * fits in are remembered. - * - * @param parent the parent model candidate - * @return <code>true</code> if the receiver can be nested into <code>parent</code>, <code>false</code> otherwise - */ - boolean canNestInto(LinkedModeModel parent) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - if (!enforceNestability(group, parent)) { - fParentPosition= null; - return false; - } - } - - Assert.isNotNull(fParentPosition); - fParentEnvironment= parent; - return true; - } - - /** - * Called by nested models when a group is added to them. All - * positions in all groups of a nested model have to fit inside a - * single position in the parent model. - * - * @param group the group of the nested model to be adopted. - * @param model the model to check against - * @return <code>false</code> if it failed to enforce nestability - */ - private boolean enforceNestability(LinkedPositionGroup group, LinkedModeModel model) { - Assert.isNotNull(model); - Assert.isNotNull(group); - - try { - for (Iterator it= model.fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup pg= (LinkedPositionGroup) it.next(); - LinkedPosition pos; - pos= pg.adopt(group); - if (pos != null && fParentPosition != null && fParentPosition != pos) - return false; // group does not fit into one parent position, which is illegal - else if (fParentPosition == null && pos != null) - fParentPosition= pos; - } - } catch (BadLocationException e) { - return false; - } - - // group must fit into exactly one of the parent's positions - return fParentPosition != null; - } - - /** - * Returns whether this model is nested. - * - * <p> - * This method is part of the private protocol between - * <code>LinkedUIControl</code> and <code>LinkedModeModel</code>. - * </p> - * - * @return <code>true</code> if this model is nested, - * <code>false</code> otherwise - */ - public boolean isNested() { - return fParentEnvironment != null; - } - - /** - * Returns the positions in this model that have a tab stop, in the - * order they were added. - * - * <p> - * This method is part of the private protocol between - * <code>LinkedUIControl</code> and <code>LinkedModeModel</code>. - * </p> - * - * @return the positions in this model that have a tab stop, in the - * order they were added - */ - public List getTabStopSequence() { - return fPositionSequence; - } - - /** - * Adds <code>listener</code> to the set of listeners that are informed - * upon state changes. - * - * @param listener the new listener - */ - public void addLinkingListener(ILinkedModeListener listener) { - Assert.isNotNull(listener); - if (!fListeners.contains(listener)) - fListeners.add(listener); - } - - /** - * Removes <code>listener</code> from the set of listeners that are - * informed upon state changes. - * - * @param listener the new listener - */ - public void removeLinkingListener(ILinkedModeListener listener) { - fListeners.remove(listener); - } - - /** - * Finds the position in this model that is closest after - * <code>toFind</code>. <code>toFind</code> needs not be a position in - * this model and serves merely as an offset. - * - * <p> - * This method part of the private protocol between - * <code>LinkedUIControl</code> and <code>LinkedModeModel</code>. - * </p> - * - * @param toFind the position to search from - * @return the closest position in the same document as <code>toFind</code> - * after the offset of <code>toFind</code>, or <code>null</code> - */ - public LinkedPosition findPosition(LinkedPosition toFind) { - LinkedPosition position= null; - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - position= group.getPosition(toFind); - if (position != null) - break; - } - return 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); - } - } - - /** - * Suspends this model. - */ - private void suspend() { - List l= new ArrayList(fListeners); - for (Iterator it= l.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); - listener.suspend(this); - } - } - - /** - * Resumes this model. <code>flags</code> can be <code>NONE</code> - * or <code>SELECT</code>. - * - * @param flags <code>NONE</code> or <code>SELECT</code> - */ - private void resume(int flags) { - List l= new ArrayList(fListeners); - for (Iterator it= l.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); - listener.resume(this, flags); - } - } - - /** - * Returns whether an offset is contained by any position in this - * model. - * - * @param offset the offset to check - * @return <code>true</code> if <code>offset</code> is included by any - * position (see {@link LinkedPosition#includes(int)}) in this - * model, <code>false</code> otherwise - */ - public boolean anyPositionContains(int offset) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - if (group.contains(offset)) - // take the first hit - exlusion is guaranteed by enforcing - // disjointness when adding positions - return true; - } - return false; - } - - /** - * Returns the linked position group that contains <code>position</code>, - * or <code>null</code> if <code>position</code> is not contained in any - * group within this model. Group containment is tested by calling - * <code>group.contains(position)</code> for every <code>group</code> in - * this model. - * - * <p> - * This method part of the private protocol between - * <code>LinkedUIControl</code> and <code>LinkedModeModel</code>. - * </p> - * - * @param position the position the group of which is requested - * @return the first group in this model for which - * <code>group.contains(position)</code> returns <code>true</code>, - * or <code>null</code> if no group contains <code>position</code> - */ - public LinkedPositionGroup getGroupForPosition(Position position) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); - if (group.contains(position)) - return group; - } - return null; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPosition.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPosition.java deleted file mode 100644 index ad6ac92de1e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPosition.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - -/** - * A <code>Position</code> on a document that knows which document it is - * registered with and has a sequence number for tab stops. - * <p> - * Clients may extend this class. - * </p> - * @since 3.0 - */ -public class LinkedPosition extends Position { - - /** The document this position belongs to. */ - private IDocument fDocument; - private int fSequenceNumber; - - /** - * Creates a new instance. - * - * @param document the document - * @param offset the offset of the position - * @param length the length of the position - * @param sequence the iteration sequence rank - */ - public LinkedPosition(IDocument document, int offset, int length, int sequence) { - super(offset, length); - Assert.isNotNull(document); - fDocument= document; - fSequenceNumber= sequence; - } - - /** - * Creates a new instance. Equivalent to calling - * <code>LinkedPosition(document, offset, length, LinkedPositionGroup.NO_STOP)</code> - * - * @param document the document - * @param offset the offset of the position - * @param length the length of the position - */ - public LinkedPosition(IDocument document, int offset, int length) { - this(document, offset, length, LinkedPositionGroup.NO_STOP); - } - - /** - * @return Returns the document. - */ - public IDocument getDocument() { - return fDocument; - } - - /* - * @see org.eclipse.jface.text.Position#equals(java.lang.Object) - */ - public boolean equals(Object other) { - if (other instanceof LinkedPosition) { - LinkedPosition p= (LinkedPosition) other; - return p.offset == offset && p.length == length && p.fDocument == fDocument; - } - return false; - } - - /** - * 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>event</code>. - * - * @param event the event to check. - * @return <code>true</code> if this position includes <code>event</code>, - * <code>false</code> otherwise - */ - public boolean includes(DocumentEvent event) { - return includes(event.getDocument(), event.getOffset(), event.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()); - } - - /** - * Overrides {@link Position#includes(int)}so every offset is considered - * included that lies in between the first and last offset of this position, - * and offsets that are right at the end of the position. - * - * @param pOffset the offset to check - * @return <code>true</code> if <code>pOffset</code> is in - * <code>[offset, offset + length]</code> - */ - public boolean includes(int pOffset) { - return this.offset <= pOffset && pOffset <= this.offset + this.length; - } - - /** - * Returns whether this position includes the range given by - * <code>offset</code> and <code>length</code>. A range is included by - * a <code>LinkedPosition</code> if {@link #includes(int) includes(offset)} - * returns true for every offset in the range, including the borders of the - * range. - * - * @param doc the document that the given range refers to, may be <code>null</code> - * @param off the offset of the range, referring to <code>document</code> - * @param len the length of the range - * @return <code>true</code> if <code>doc</code> is the same document as - * this position refers to, and if the entire range is included in - * this position - */ - protected boolean includes(IDocument doc, int off, int len) { - return doc == fDocument && off >= offset && len + off <= offset + length; - - } - - /** - * Returns the content of this position on the referenced document. - * - * @return the content of the document at this position - * @throws BadLocationException if the position is not valid - */ - public String getContent() throws BadLocationException { - return fDocument.get(offset, length); - } - - /** - * Returns the sequence number of this position. - * - * @return the sequence number of this position - */ - public int getSequenceNumber() { - return fSequenceNumber; - } - - /** - * Sets the sequence number of this position. - * - * @param sequence the new sequence number - */ - public void setSequenceNumber(int sequence) { - fSequenceNumber= sequence; - } - - /* - * @see org.eclipse.jface.text.Position#hashCode() - */ - public int hashCode() { - return fDocument.hashCode() | super.hashCode() | fSequenceNumber; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java deleted file mode 100644 index 9ef37eb0b92..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java +++ /dev/null @@ -1,353 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.link; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - -/** - * A group of positions in multiple documents that are simultaneously modified - - * if one gets edited, all other positions in a <code>PositionGroup</code> - * are edited the same way. All linked positions in a group have the same - * content. - * <p> - * Normally, new positions are given a tab stop weight which can be used by - * clients, e.g. the UI. If no weight is given, a position will not be visited. - * If no weights are used at all, the first position in a document is taken as - * the only stop as to comply with the behavior of the old linked position - * infrastructure. - * </p> - * <p> - * Clients may instantiate this class. - * </p> - * - * @since 3.0 - */ -public class LinkedPositionGroup { - - /** Sequence constant declaring that a position should not be stopped by. */ - public static final int NO_STOP= -1; - - /* members */ - - /** The linked positions of this group. */ - private final List fPositions= new LinkedList(); - /** Whether we are sealed or not. */ - private boolean fIsSealed= false; - /** - * <code>true</code> if there are custom iteration weights. For backward - * compatibility. - */ - private boolean fHasCustomIteration= false; - - /* - * iteration variables, set to communicate state between isLegalEvent and - * handleEvent - */ - /** The position including the most recent <code>DocumentEvent</code>. */ - private LinkedPosition fLastPosition; - /** The offset of <code>fLastPosition</code>. */ - private int fLastPositionOffset; - - /** - * Adds a position to this group. The document region defined by the - * position must contain the same content (and thus have the same length) as - * any of the other positions already in this group. Additionally, all - * positions added must be disjoint; otherwise a - * <code>BadLocationException</code> is thrown. - * <p> - * Positions added using this method are owned by this group afterwards and - * may not be updated or modified thereafter. - * </p> - * <p> - * Once a group has been added to a <code>LinkedModeModel</code>, it - * becomes <em>sealed</em> and no positions may be added any more. - * </p> - * - * @param position the position to add - * @throws BadLocationException if the position is invalid or conflicts with - * other positions in the group - * @throws IllegalStateException if the group has already been added to a - * model - */ - public void addPosition(LinkedPosition position) throws BadLocationException { - /* - * Enforces constraints and sets the custom iteration flag. If the - * position is already in this group, nothing happens. - */ - Assert.isNotNull(position); - if (fIsSealed) - throw new IllegalStateException("cannot add positions after the group is added to an model"); //$NON-NLS-1$ - - if (!fPositions.contains(position)) { - enforceDisjoint(position); - enforceEqualContent(position); - fPositions.add(position); - fHasCustomIteration |= position.getSequenceNumber() != LinkedPositionGroup.NO_STOP; - } else - return; // nothing happens - } - - /** - * Enforces the invariant that all positions must contain the same string. - * - * @param position the position to check - * @throws BadLocationException if the equal content check fails - */ - private void enforceEqualContent(LinkedPosition position) throws BadLocationException { - if (fPositions.size() > 0) { - String groupContent= ((LinkedPosition) fPositions.get(0)).getContent(); - String positionContent= position.getContent(); - if (!groupContent.equals(positionContent)) - throw new BadLocationException(); - } - } - - /** - * Enforces the invariant that all positions must be disjoint. - * - * @param position the position to check - * @throws BadLocationException if the disjointness check fails - */ - private void enforceDisjoint(LinkedPosition position) throws BadLocationException { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); - if (p.overlapsWith(position)) - throw new BadLocationException(); - } - } - - /** - * Enforces the disjointness for another group - * - * @param group the group to check - * @throws BadLocationException if the disjointness check fails - */ - void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException { - Assert.isNotNull(group); - for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); - enforceDisjoint(p); - } - } - - /** - * Checks whether <code>event</code> fits in any of the positions of this - * group. - * - * @param event the document event to check - * @return <code>true</code> if <code>event</code> fits in any position - */ - boolean isLegalEvent(DocumentEvent event) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); - if (pos.includes(event)) { - fLastPosition= pos; - fLastPositionOffset= pos.getOffset(); - return true; - } - } - fLastPosition= null; - fLastPositionOffset= -1; - return false; - } - - /** - * Creates an edition of a document change that will forward any - * modification in one position to all linked siblings. The return value is - * a map from <code>IDocument</code> to <code>TextEdit</code>. - * - * @param event the document event to check - * @return a map of edits, grouped by edited document - */ - Map handleEvent(DocumentEvent event) { - - if (fLastPosition != null) { - - Map map= new HashMap(); - - int relOffset= event.getOffset() - fLastPositionOffset; - int length= event.getLength(); - String text= event.getText(); - - for (Iterator it2= fPositions.iterator(); it2.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it2.next(); - if (p == fLastPosition) - continue; // don't re-update the origin of the change - - List edits= (List) map.get(p.getDocument()); - if (edits == null) { - edits= new ArrayList(); - map.put(p.getDocument(), edits); - } - - edits.add(new ReplaceEdit(p.getOffset() + relOffset, length, text)); - } - - for (Iterator it2= map.keySet().iterator(); it2.hasNext(); ) { - IDocument d= (IDocument) it2.next(); - TextEdit edit= new MultiTextEdit(0, d.getLength()); - edit.addChildren((TextEdit[]) ((List) map.get(d)).toArray(new TextEdit[0])); - map.put(d, edit); - } - - return map; - - } - - return null; - } - - /** - * Sets the model of this group. Once a model has been set, no - * more positions can be added and the model cannot be changed. - */ - void seal() { - Assert.isTrue(!fIsSealed); - fIsSealed= true; - - if (fHasCustomIteration == false && fPositions.size() > 0) { - ((LinkedPosition) fPositions.get(0)).setSequenceNumber(0); - } - } - - IDocument[] getDocuments() { - IDocument[] docs= new IDocument[fPositions.size()]; - int i= 0; - for (Iterator it= fPositions.iterator(); it.hasNext(); i++) { - LinkedPosition pos= (LinkedPosition) it.next(); - docs[i]= pos.getDocument(); - } - return docs; - } - - void register(LinkedModeModel model) throws BadLocationException { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); - model.register(pos); - } - } - - /** - * Returns the position in this group that encompasses all positions in - * <code>group</code>. - * - * @param group the group to be adopted - * @return a position in the receiver that contains all positions in <code>group</code>, - * or <code>null</code> if none can be found - * @throws BadLocationException if more than one position are affected by - * <code>group</code> - */ - LinkedPosition adopt(LinkedPositionGroup group) throws BadLocationException { - LinkedPosition found= null; - for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); - LinkedPosition localFound= null; - for (Iterator it2= fPositions.iterator(); it2.hasNext(); ) { - LinkedPosition myPos= (LinkedPosition) it2.next(); - if (myPos.includes(pos)) { - if (found == null) - found= myPos; - else if (found != myPos) - throw new BadLocationException(); - if (localFound == null) - localFound= myPos; - } - } - - if (localFound != found) - throw new BadLocationException(); - } - return found; - } - - /** - * Finds the closest position to <code>toFind</code>. - * - * @param toFind the linked position for which to find the closest position - * @return the closest position to <code>toFind</code>. - */ - LinkedPosition getPosition(LinkedPosition toFind) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); - if (p.includes(toFind)) - return p; - } - return null; - } - - /** - * Returns <code>true</code> if <code>offset</code> is contained in any - * position in this group. - * - * @param offset the offset to check - * @return <code>true</code> if offset is contained by this group - */ - boolean contains(int offset) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); - if (pos.includes(offset)) { - return true; - } - } - return false; - } - - /** - * Returns whether this group contains any positions. - * - * @return <code>true</code> if this group is empty, <code>false</code> - * if it is not - */ - public boolean isEmtpy() { - return fPositions.size() == 0; - } - - /** - * Returns the positions contained in the receiver as an array. The - * positions are the actual positions and must not be modified; the array - * is a copy of internal structures. - * - * @return the positions of this group in no particular order - */ - public LinkedPosition[] getPositions() { - return (LinkedPosition[]) fPositions.toArray(new LinkedPosition[0]); - } - - /** - * Returns <code>true</code> if the receiver contains <code>position</code>. - * - * @param position the position to check - * @return <code>true</code> if the receiver contains <code>position</code> - */ - boolean contains(Position position) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); - if (position.equals(p)) - return true; - } - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/package.html b/org.eclipse.text/src/org/eclipse/jface/text/link/package.html deleted file mode 100644 index bc58040011e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/package.html +++ /dev/null @@ -1,55 +0,0 @@ -<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> -<html><head> - <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> - <meta content="IBM" name="Author"> - <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]" name="GENERATOR"><title>Linked Position Infrastructure</title></head> - -<body> -Application programming interfaces for interaction -with the Eclipse Java User Interface text support. -<h2>Linked Position Infrastructure</h2> -<h3>package <span style="font-family: monospace;">org.eclipse.jface.text.link -</span><span style="font-family: monospace;"></span></h3> -<h3><code></code></h3> -The Linked Position Infrastructure lets one set up a mode in an editor -in which regions in a document (or several documents) are <em>linked</em>, -i.e. editions -of one linked position will be reflected in the others. -<h4>Classes</h4> -<ul> - <li><code>LinkedPositionGroup</code>: a set of linked positions. Add -positions to a group using the <code>addPosition</code> method. See <span style="font-family: monospace;">LinkedPosition</span><code><span style="font-family: helvetica,arial,sans-serif;"> and</span></code> <span style="font-family: monospace;">ProposalPosition</span><code><span style="font-family: helvetica,arial,sans-serif;"> </span></code><span style="font-family: helvetica,arial,sans-serif;">for a position type -that lets one attach </span><span style="font-family: monospace;">ICompletionProposals</span><span style="font-family: monospace;"></span><span style="font-family: helvetica,arial,sans-serif;"> </span><span style="font-family: helvetica,arial,sans-serif;">to</span> -be shown when the position is hit.</li> - <li><code>LinkedModeModel</code>: umbrellas several <code>LinkedPositionGroup</code>s, -e.g. in a template that has several groups of linked positions. Handles -the forwarding of updates received via an IDocumentListener. Add <code>LinkedPositionGroup</code>s -to -an model using the <code>addGroup</code> method. Existence of a <span style="font-family: monospace;">LinkedModeModel </span>can be -tested by one of the static methods.<br> - </li> - <li><code>LinkedModeUI</code>: The UI for linked mode (for one -model, to be precise). Monitors key etc. activity, monitors exit -conditions, creates a painter etc. <br> -Properties: - <ul> - <li><b>cycling mode</b> (whether to jump to the first position -after the last): either of <code>CYCLE_ALWAYS</code>, <code>CYCLE_NEVER</code> -and <code>CYCLE_WHEN_NO_PARENT</code> (default).</li> - <li><b>exit position</b>: where to jump upon leaving the linked -mode (e.g. using Enter, or Tab from the last position when not -cycling). Set <code>isTabStop</code> to <code>true</code> if tabbing -should stop over when cycling.</li> - <li><span style="font-weight: bold;">position listener</span>: -extending classes may register a position listener which will get -notified whenever -the focus position changes. An example is <span style="font-family: monospace;">org.eclipse.ui.texteditor.link.EditorLinkedModeUI.EditorHistoryUpdater</span> -which will store the edit location in the editor navigation history.<br> - </li> - </ul> - </li> -. -</ul> -<h4>Example</h4> -<pre> IDocument doc1, doc2;<br> ITextViewer viewer1, viewer2;<br> <br> /* create groups - this step is independent of the linked mode */<br> LinkedPositionGroup group1= new LinkedPositionGroup();<br> group1.addPosition(new LinkedPosition(doc1, 3, 4));<br> group1.addPosition(new LinkedPosition(doc1, 7, 8));<br> <br> LinkedPositionGroup group2= new LinkedPositionGroup();<br> group2.addPosition(new LinkedPosition(doc1, 15, 25));<br> group2.addPosition(new LinkedPosition(doc2, 0, 10));<br> <br> /* set up linked mode */<br> LinkedModeModel model= new LinkedModeModel();<br> model.addGroup(group1);<br> model.addGroup(group2);<br> model.forceInstall();<br> <br> /* create UI */<br> LinkedModeUI ui= new LinkedModeUI(model, new ITextViewer[] { viewer1, viewer2 });<br> ui.enter();<span style="font-family: sans-serif;"><br><br></span></pre> -</body></html>
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/package.html b/org.eclipse.text/src/org/eclipse/jface/text/package.html deleted file mode 100644 index 81dc7fb0414..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/package.html +++ /dev/null @@ -1,30 +0,0 @@ -<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> -<html><head> - <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> - <meta content="IBM" name="Author"> - <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]" name="GENERATOR"><title>text infrastructure</title></head> - -<body> -<p>Provides a framework for creating and manipulating text documents.</p> -<h3>Package Specification</h3> -<p><tt>IDocument</tt> is the major text - model abstraction. It provides content management, position management using - position categories, document partition management, and change notification. - In order to be notified about document changes, an object must implements <tt>IDocumentListener - </tt>and must be registered with the document. <tt>Position</tt> - updating in responds to a document change is performed by implementers of <tt>IDocumentPositionUpdater</tt>. - Partition updating in responds to a document change is performed by implements - of <tt>IDocumentPartitioner</tt>. In order - to be notified about document partition changes, objects must implement <tt>IDocumentParititoningListener</tt> - and must be registered with the document.</p> -<p>The package contains default implementations for document position updaters - and for documents. <tt>AbstractDocument</tt> - uses <tt>ITextStorage</tt> for storing - and managing its content and <tt>ILineTracker</tt> - to maintain a line structure of its content. As defaults a gap text implementation - of <tt>ITextStore</tt> is provided, together - with a line tracker understanding the three standard line delimiters ("\r", - "\n", "\r\n") and a line tracker which can be freely configured - to consider any given set of strings as valid line delimiters. </p> -<p></p> -</body></html>
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/Annotation.java b/org.eclipse.text/src/org/eclipse/jface/text/source/Annotation.java deleted file mode 100644 index 6cdd3ecf876..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/Annotation.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -/** - * Annotation managed by an - * {@link org.eclipse.jface.text.source.IAnnotationModel}. - * <p> - * Annotations are types, associated text, and can be marked as persistent and - * deleted. Annotations which are not explicitly initialized with an annotation - * type are of type <code>"org.eclipse.text.annotation.unknown"</code>. - */ -public class Annotation { - - /** - * Constant for unknown annotation types.<p> - * Value: <code>"org.eclipse.text.annotation.unknown"</code> - * @since 3.0 - */ - public final static String TYPE_UNKNOWN= "org.eclipse.text.annotation.unknown"; //$NON-NLS-1$ - - - /** - * The type of this annotation. - * @since 3.0 - */ - private String fType; - /** - * Indicates whether this annotation is persistent or not. - * @since 3.0 - */ - private boolean fIsPersistent= false; - /** - * Indicates whether this annotation is marked as deleted or not. - * @since 3.0 - */ - private boolean fMarkedAsDeleted= false; - /** - * The text associated with this annotation. - * @since 3.0 - */ - private String fText; - - - /** - * Creates a new annotation that is not persistent and type less. - */ - protected Annotation() { - this(null, false, null); - } - - /** - * Creates a new annotation with the given properties. - * - * @param type the type of this annotation - * @param isPersistent <code>true</code> if this annotation is - * persistent, <code>false</code> otherwise - * @param text the text associated with this annotation - * @since 3.0 - */ - public Annotation(String type, boolean isPersistent, String text) { - fType= type; - fIsPersistent= isPersistent; - fText= text; - } - - /** - * Creates a new annotation with the given persistence state. - * - * @param isPersistent <code>true</code> if persistent, <code>false</code> otherwise - * @since 3.0 - */ - public Annotation(boolean isPersistent) { - this(null, isPersistent, null); - } - - /** - * Returns whether this annotation is persistent. - * - * @return <code>true</code> if this annotation is persistent, <code>false</code> - * otherwise - * @since 3.0 - */ - public boolean isPersistent() { - return fIsPersistent; - } - - /** - * Sets the type of this annotation. - * - * @param type the annotation type - * @since 3.0 - */ - public void setType(String type) { - fType= type; - } - - /** - * Returns the type of the annotation. - * - * @return the type of the annotation - * @since 3.0 - */ - public String getType() { - return fType == null? TYPE_UNKNOWN : fType; - } - - /** - * Marks this annotation deleted according to the value of the - * <code>deleted</code> parameter. - * - * @param deleted <code>true</code> if annotation should be marked as deleted - * @since 3.0 - */ - public void markDeleted(boolean deleted) { - fMarkedAsDeleted= deleted; - } - - /** - * Returns whether this annotation is marked as deleted. - * - * @return <code>true</code> if annotation is marked as deleted, <code>false</code> - * otherwise - * @since 3.0 - */ - public boolean isMarkedDeleted() { - return fMarkedAsDeleted; - } - - /** - * Sets the text associated with this annotation. - * - * @param text the text associated with this annotation - * @since 3.0 - */ - public void setText(String text) { - fText= text; - } - - /** - * Returns the text associated with this annotation. - * - * @return the text associated with this annotation or <code>null</code> - * @since 3.0 - */ - public String getText() { - return fText; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java deleted file mode 100644 index b99a1e51bcc..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - - -/** - * Internal implementation of {@link org.eclipse.jface.text.source.IAnnotationMap}. - * - * @since 3.0 - */ -class AnnotationMap implements IAnnotationMap { - - /** - * The lock object used to synchronize the operations explicitly defined by - * <code>IAnnotationMap</code> - */ - private Object fLockObject; - - /** The map holding the annotations */ - private Map fInternalMap; - - /** - * Creates a new annotation map with the given capacity. - * - * @param capacity the capacity - */ - public AnnotationMap(int capacity) { - fInternalMap = new HashMap(capacity); - } - - /* - * @see org.eclipse.jface.text.source.ISynchronizable#setLockObject(java.lang.Object) - */ - public void setLockObject(Object lockObject) { - fLockObject = lockObject; - } - - /* - * @see org.eclipse.jface.text.source.ISynchronizable#getLockObject() - */ - public Object getLockObject() { - if (fLockObject == null) return this; - return fLockObject; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationMap#valuesIterator() - */ - public Iterator valuesIterator() { - synchronized (getLockObject()) { - return new ArrayList(fInternalMap.values()).iterator(); - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationMap#keySetIterator() - */ - public Iterator keySetIterator() { - synchronized (getLockObject()) { - return new ArrayList(fInternalMap.keySet()).iterator(); - } - } - - /* - * @see java.util.Map#containsKey(java.lang.Object) - */ - public boolean containsKey(Object annotation) { - synchronized (getLockObject()) { - return fInternalMap.containsKey(annotation); - } - } - - /* - * @see java.util.Map#put(java.lang.Object, java.lang.Object) - */ - public Object put(Object annotation, Object position) { - synchronized (getLockObject()) { - return fInternalMap.put(annotation, position); - } - } - - /* - * @see java.util.Map#get(java.lang.Object) - */ - public Object get(Object annotation) { - synchronized (getLockObject()) { - return fInternalMap.get(annotation); - } - } - - /* - * @see java.util.Map#clear() - */ - public void clear() { - synchronized (getLockObject()) { - fInternalMap.clear(); - } - } - - /* - * @see java.util.Map#remove(java.lang.Object) - */ - public Object remove(Object annotation) { - synchronized (getLockObject()) { - return fInternalMap.remove(annotation); - } - } - - /* - * @see java.util.Map#size() - */ - public int size() { - synchronized (getLockObject()) { - return fInternalMap.size(); - } - } - - /* - * @see java.util.Map#isEmpty() - */ - public boolean isEmpty() { - synchronized (getLockObject()) { - return fInternalMap.isEmpty(); - } - } - - /* - * @see java.util.Map#containsValue(java.lang.Object) - */ - public boolean containsValue(Object value) { - synchronized(getLockObject()) { - return fInternalMap.containsValue(value); - } - } - - /* - * @see java.util.Map#putAll(java.util.Map) - */ - public void putAll(Map map) { - synchronized (getLockObject()) { - fInternalMap.putAll(map); - } - } - - /* - * @see IAnnotationMap#entrySet() - */ - public Set entrySet() { - synchronized (getLockObject()) { - return fInternalMap.entrySet(); - } - } - - /* - * @see IAnnotationMap#keySet() - */ - public Set keySet() { - synchronized (getLockObject()) { - return fInternalMap.keySet(); - } - } - - /* - * @see IAnnotationMap#values() - */ - public Collection values() { - synchronized (getLockObject()) { - return fInternalMap.values(); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java deleted file mode 100644 index 2e595844239..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java +++ /dev/null @@ -1,767 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.ISynchronizable; -import org.eclipse.jface.text.Position; - - -/** - * Standard implementation of {@link IAnnotationModel}and its extension - * interfaces. This class can directly be used by clients. Subclasses may adapt - * this annotation model to other existing annotation mechanisms. This class - * also implements {@link org.eclipse.jface.text.ISynchronizable}. All - * modifications of the model's internal annotation map are synchronized using - * the model's lock object. - */ -public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtension, ISynchronizable { - - /** - * Internal annotation model listener for forwarding annotation model changes from the attached models to the - * registered listeners of the outer most annotation model. - * - * @since 3.0 - */ - private class InternalModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension { - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelListener#modelChanged(org.eclipse.jface.text.source.IAnnotationModel) - */ - public void modelChanged(IAnnotationModel model) { - AnnotationModel.this.fireModelChanged(new AnnotationModelEvent(model, true)); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelListenerExtension#modelChanged(org.eclipse.jface.text.source.AnnotationModelEvent) - */ - public void modelChanged(AnnotationModelEvent event) { - AnnotationModel.this.fireModelChanged(event); - } - } - - /** - * The list of managed annotations - * @deprecated since 3.0 use <code>getAnnotationMap</code> instead - */ - protected Map fAnnotations; - /** The list of annotation model listeners */ - protected ArrayList fAnnotationModelListeners; - /** The document connected with this model */ - protected IDocument fDocument; - /** The number of open connections to the same document */ - private int fOpenConnections= 0; - /** The document listener for tracking whether document positions might have been changed. */ - private IDocumentListener fDocumentListener; - /** The flag indicating whether the document positions might have been changed. */ - private boolean fDocumentChanged= true; - /** - * The model's attachment. - * @since 3.0 - */ - private Map fAttachments= new HashMap(); - /** - * The annotation model listener on attached sub-models. - * @since 3.0 - */ - private IAnnotationModelListener fModelListener= new InternalModelListener(); - /** - * The current annotation model event. - * @since 3.0 - */ - private AnnotationModelEvent fModelEvent; - /** - * The modification stamp. - * @since 3.0 - */ - private Object fModificationStamp= new Object(); - - /** - * Creates a new annotation model. The annotation is empty, i.e. does not - * manage any annotations and is not connected to any document. - */ - public AnnotationModel() { - fAnnotations= new AnnotationMap(10); - fAnnotationModelListeners= new ArrayList(2); - - fDocumentListener= new IDocumentListener() { - - public void documentAboutToBeChanged(DocumentEvent event) { - } - - public void documentChanged(DocumentEvent event) { - fDocumentChanged= true; - } - }; - } - - /** - * Returns the annotation map internally used by this annotation model. - * - * @return the annotation map internally used by this annotation model - * @since 3.0 - */ - protected IAnnotationMap getAnnotationMap() { - return (IAnnotationMap) fAnnotations; - } - - /* - * @see org.eclipse.jface.text.ISynchronizable#getLockObject() - * @since 3.0 - */ - public Object getLockObject() { - return getAnnotationMap().getLockObject(); - } - - /* - * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object) - * @since 3.0 - */ - public void setLockObject(Object lockObject) { - getAnnotationMap().setLockObject(lockObject); - } - - /** - * Returns the current annotation model event. This is the event that will be sent out - * when calling <code>fireModelChanged</code>. - * - * @return the current annotation model event - * @since 3.0 - */ - protected final AnnotationModelEvent getAnnotationModelEvent() { - synchronized (getLockObject()) { - if (fModelEvent == null) { - fModelEvent= createAnnotationModelEvent(); - fModelEvent.markWorldChange(false); - fModificationStamp= fModelEvent; - } - return fModelEvent; - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#addAnnotation(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position) - */ - public void addAnnotation(Annotation annotation, Position position) { - try { - addAnnotation(annotation, position, true); - } catch (BadLocationException e) { - // ignore invalid position - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#replaceAnnotations(org.eclipse.jface.text.source.Annotation[], java.util.Map) - * @since 3.0 - */ - public void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd) { - try { - replaceAnnotations(annotationsToRemove, annotationsToAdd, true); - } catch (BadLocationException x) { - } - } - - /** - * Replaces the given annotations in this model and if advised fires a - * model change event. - * - * @param annotationsToRemove the annotations to be removed - * @param annotationsToAdd the annotations to be added - * @param fireModelChanged <code>true</code> if a model change event - * should be fired, <code>false</code> otherwise - * @throws BadLocationException in case an annotation should be added at an - * invalid position - * @since 3.0 - */ - protected void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged) throws BadLocationException { - - if (annotationsToRemove != null) { - for (int i= 0, length= annotationsToRemove.length; i < length; i++) - removeAnnotation(annotationsToRemove[i], false); - } - - if (annotationsToAdd != null) { - Iterator iter= annotationsToAdd.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry mapEntry= (Map.Entry) iter.next(); - Annotation annotation= (Annotation) mapEntry.getKey(); - Position position= (Position) mapEntry.getValue(); - addAnnotation(annotation, position, false); - } - } - - if (fireModelChanged) - fireModelChanged(); - } - - /** - * Adds the given annotation to this model. Associates the - * annotation with the given position. If requested, all annotation - * model listeners are informed about this model change. If the annotation - * is already managed by this model nothing happens. - * - * @param annotation the annotation to add - * @param position the associate position - * @param fireModelChanged indicates whether to notify all model listeners - * @throws BadLocationException if the position is not a valid document position - */ - protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException { - if (!fAnnotations.containsKey(annotation)) { - - addPosition(fDocument, position); - fAnnotations.put(annotation, position); - synchronized (getLockObject()) { - getAnnotationModelEvent().annotationAdded(annotation); - } - - if (fireModelChanged) - fireModelChanged(); - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#addAnnotationModelListener(org.eclipse.jface.text.source.IAnnotationModelListener) - */ - public void addAnnotationModelListener(IAnnotationModelListener listener) { - if (!fAnnotationModelListeners.contains(listener)) { - fAnnotationModelListeners.add(listener); - if (listener instanceof IAnnotationModelListenerExtension) { - IAnnotationModelListenerExtension extension= (IAnnotationModelListenerExtension) listener; - AnnotationModelEvent event= createAnnotationModelEvent(); - event.markSealed(); - extension.modelChanged(event); - } else - listener.modelChanged(this); - } - } - - /** - * 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); - } - - /** - * Removes the given position from the default position category of the - * given document. - * - * @param document the document to which to add the position - * @param position the position to add - * - * @since 3.0 - */ - protected void removePosition(IDocument document, Position position) { - if (document != null) - document.removePosition(position); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#connect(org.eclipse.jface.text.IDocument) - */ - public void connect(IDocument document) { - Assert.isTrue(fDocument == null || fDocument == document); - - if (fDocument == null) { - fDocument= document; - Iterator e= getAnnotationMap().valuesIterator(); - while (e.hasNext()) - try { - addPosition(fDocument, (Position) e.next()); - } catch (BadLocationException x) { - // ignore invalid position - } - } - - ++ fOpenConnections; - if (fOpenConnections == 1) { - fDocument.addDocumentListener(fDocumentListener); - connected(); - } - - for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { - IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); - model.connect(document); - } - } - - /** - * Hook method. Is called as soon as this model becomes connected to a document. - * Subclasses may re-implement. - */ - protected void connected() { - } - - /** - * Hook method. Is called as soon as this model becomes disconnected from its document. - * Subclasses may re-implement. - */ - protected void disconnected() { - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#disconnect(org.eclipse.jface.text.IDocument) - */ - public void disconnect(IDocument document) { - - Assert.isTrue(fDocument == document); - - for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { - IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); - model.disconnect(document); - } - - -- fOpenConnections; - if (fOpenConnections == 0) { - - disconnected(); - fDocument.removeDocumentListener(fDocumentListener); - - if (fDocument != null) { - Iterator e= getAnnotationMap().valuesIterator(); - while (e.hasNext()) { - Position p= (Position) e.next(); - removePosition(fDocument, p); - } - fDocument= null; - } - } - } - - /** - * Informs all annotation model listeners that this model has been changed. - */ - protected void fireModelChanged() { - AnnotationModelEvent modelEvent= null; - - synchronized(getLockObject()) { - if (fModelEvent != null) { - modelEvent= fModelEvent; - fModelEvent= null; - } - } - - if (modelEvent != null) - fireModelChanged(modelEvent); - } - - /** - * Creates and returns a new annotation model event. Subclasses may override. - * - * @return a new and empty annotation model event - * @since 3.0 - */ - protected AnnotationModelEvent createAnnotationModelEvent() { - return new AnnotationModelEvent(this); - } - - /** - * Informs all annotation model listeners that this model has been changed - * as described in the annotation model event. The event is sent out - * to all listeners implementing <code>IAnnotationModelListenerExtension</code>. - * All other listeners are notified by just calling <code>modelChanged(IAnnotationModel)</code>. - * - * @param event the event to be sent out to the listeners - * @since 2.0 - */ - protected void fireModelChanged(AnnotationModelEvent event) { - - event.markSealed(); - - if (event.isEmpty()) - return; - - ArrayList v= new ArrayList(fAnnotationModelListeners); - Iterator e= v.iterator(); - while (e.hasNext()) { - IAnnotationModelListener l= (IAnnotationModelListener) e.next(); - if (l instanceof IAnnotationModelListenerExtension) - ((IAnnotationModelListenerExtension) l).modelChanged(event); - else - l.modelChanged(this); - } - } - - /** - * Removes the given annotations from this model. If requested all - * annotation model listeners will be informed about this change. - * <code>modelInitiated</code> indicates whether the deletion has - * been initiated by this model or by one of its clients. - * - * @param annotations the annotations to be removed - * @param fireModelChanged indicates whether to notify all model listeners - * @param modelInitiated indicates whether this changes has been initiated by this model - */ - protected void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated) { - if (annotations.size() > 0) { - Iterator e= annotations.iterator(); - while (e.hasNext()) - removeAnnotation((Annotation) e.next(), false); - - if (fireModelChanged) - fireModelChanged(); - } - } - - /** - * Removes all annotations from the model whose associated positions have been - * deleted. If requested inform all model listeners about the change. - * - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void cleanup(boolean fireModelChanged) { - cleanup(fireModelChanged, true); - } - - /** - * Removes all annotations from the model whose associated positions have been - * deleted. If requested inform all model listeners about the change. If requested - * a new thread is created for the notification of the model listeners. - * - * @param fireModelChanged indicates whether to notify all model listeners - * @param forkNotification <code>true</code> iff notification should be done in a new thread - * @since 3.0 - */ - private void cleanup(boolean fireModelChanged, boolean forkNotification) { - if (fDocumentChanged) { - fDocumentChanged= false; - - ArrayList deleted= new ArrayList(); - Iterator e= getAnnotationMap().keySetIterator(); - while (e.hasNext()) { - Annotation a= (Annotation) e.next(); - Position p= (Position) fAnnotations.get(a); - if (p == null || p.isDeleted()) - deleted.add(a); - } - - if (fireModelChanged && forkNotification) { - removeAnnotations(deleted, false, false); - synchronized (getLockObject()) { - if (fModelEvent != null) - new Thread() { - public void run() { - fireModelChanged(); - } - }.start(); - } - } else - removeAnnotations(deleted, fireModelChanged, false); - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#getAnnotationIterator() - */ - public Iterator getAnnotationIterator() { - return getAnnotationIterator(true, true); - } - - /** - * Returns all annotations managed by this model. <code>cleanup</code> - * indicates whether all annotations whose associated positions are - * deleted should previously be removed from the model. <code>recurse</code> indicates - * whether annotations of attached sub-models should also be returned. - * - * @param cleanup indicates whether annotations with deleted associated positions are removed - * @param recurse whether to return annotations managed by sub-models. - * @return all annotations managed by this model - * @since 3.0 - */ - private Iterator getAnnotationIterator(boolean cleanup, boolean recurse) { - - if (!recurse) - return getAnnotationIterator(cleanup); - - List iterators= new ArrayList(fAttachments.size() + 1); - iterators.add(getAnnotationIterator(cleanup)); - for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { - iterators.add(((IAnnotationModel) fAttachments.get(it.next())).getAnnotationIterator()); - } - - final Iterator iter= iterators.iterator(); - - // Meta iterator... - return new Iterator() { - - /** The current iterator. */ - private Iterator fCurrent= (Iterator) iter.next(); // there is at least one. - /** The current element. */ - private Object fCurrentElement; - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - if (fCurrentElement != null) - return true; - - if (fCurrent.hasNext()) { - fCurrentElement= fCurrent.next(); - return true; - } else if (iter.hasNext()) { - fCurrent= (Iterator) iter.next(); - return hasNext(); - } else - return false; - } - - public Object next() { - if (!hasNext()) - throw new NoSuchElementException(); - - Object element= fCurrentElement; - fCurrentElement= null; - return element; - } - - }; - } - - /** - * Returns all annotations managed by this model. <code>cleanup</code> - * indicates whether all annotations whose associated positions are - * deleted should previously be removed from the model. - * - * @param cleanup indicates whether annotations with deleted associated positions are removed - * @return all annotations managed by this model - */ - protected Iterator getAnnotationIterator(boolean cleanup) { - if (cleanup) - cleanup(true); - - return getAnnotationMap().keySetIterator(); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#getPosition(org.eclipse.jface.text.source.Annotation) - */ - public Position getPosition(Annotation annotation) { - Position position= (Position) fAnnotations.get(annotation); - if (position != null) - return position; - - Iterator it= fAttachments.values().iterator(); - while (position == null && it.hasNext()) - position= ((IAnnotationModel) it.next()).getPosition(annotation); - return position; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#removeAllAnnotations() - * @since 3.0 - */ - public void removeAllAnnotations() { - removeAllAnnotations(true); - } - - /** - * Removes all annotations from the annotation model. If requested - * inform all model change listeners about this change. - * - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void removeAllAnnotations(boolean fireModelChanged) { - - if (fDocument != null) { - Iterator e= getAnnotationMap().keySetIterator(); - while (e.hasNext()) { - Annotation a= (Annotation) e.next(); - Position p= (Position) fAnnotations.get(a); - removePosition(fDocument, p); -// p.delete(); - synchronized (getLockObject()) { - getAnnotationModelEvent().annotationRemoved(a, p); - } - } - } - - fAnnotations.clear(); - - if (fireModelChanged) - fireModelChanged(); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModel#removeAnnotation(org.eclipse.jface.text.source.Annotation) - */ - public void removeAnnotation(Annotation annotation) { - removeAnnotation(annotation, true); - } - - /** - * Removes the given annotation from the annotation model. - * If requested inform all model change listeners about this change. - * - * @param annotation the annotation to be removed - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) { - if (fAnnotations.containsKey(annotation)) { - - Position p= null; - if (fDocument != null) { - p= (Position) fAnnotations.get(annotation); - removePosition(fDocument, p); -// p.delete(); - } - - fAnnotations.remove(annotation); - synchronized (getLockObject()) { - getAnnotationModelEvent().annotationRemoved(annotation, p); - } - - if (fireModelChanged) - fireModelChanged(); - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#modifyAnnotationPosition(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position) - * @since 3.0 - */ - public void modifyAnnotationPosition(Annotation annotation, Position position) { - modifyAnnotationPosition(annotation, position, true); - } - - /** - * Modifies the associated position of the given annotation to the given - * position. If the annotation is not yet managed by this annotation model, - * the annotation is added. When the position is <code>null</code>, the - * annotation is removed from the model. - * <p> - * If requested, all annotation model change listeners will be informed - * about the change. - * - * @param annotation the annotation whose associated position should be - * modified - * @param position the position to whose values the associated position - * should be changed - * @param fireModelChanged indicates whether to notify all model listeners - * @since 3.0 - */ - protected void modifyAnnotationPosition(Annotation annotation, Position position, boolean fireModelChanged) { - if (position == null) { - removeAnnotation(annotation, fireModelChanged); - } else { - Position p= (Position) fAnnotations.get(annotation); - if (p != null) { - - if (position.getOffset() != p.getOffset() || position.getLength() != p.getLength()) { - p.setOffset(position.getOffset()); - p.setLength(position.getLength()); - } - synchronized (getLockObject()) { - getAnnotationModelEvent().annotationChanged(annotation); - } - if (fireModelChanged) - fireModelChanged(); - - } else { - try { - addAnnotation(annotation, position, fireModelChanged); - } catch (BadLocationException x) { - // ignore invalid position - } - } - } - } - - /** - * Modifies the given annotation if the annotation is managed by this - * annotation model. - * <p> - * If requested, all annotation model change listeners will be informed - * about the change. - * - * @param annotation the annotation to be modified - * @param fireModelChanged indicates whether to notify all model listeners - * @since 3.0 - */ - protected void modifyAnnotation(Annotation annotation, boolean fireModelChanged) { - if (fAnnotations.containsKey(annotation)) { - synchronized (getLockObject()) { - getAnnotationModelEvent().annotationChanged(annotation); - } - if (fireModelChanged) - fireModelChanged(); - } - } - - /* - * @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener) - */ - public void removeAnnotationModelListener(IAnnotationModelListener listener) { - fAnnotationModelListeners.remove(listener); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#attach(java.lang.Object, java.lang.Object) - * @since 3.0 - */ - public void addAnnotationModel(Object key, IAnnotationModel attachment) { - Assert.isNotNull(attachment); - if (!fAttachments.containsValue(attachment)) { - fAttachments.put(key, attachment); - for (int i= 0; i < fOpenConnections; i++) - attachment.connect(fDocument); - attachment.addAnnotationModelListener(fModelListener); - } - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#get(java.lang.Object) - * @since 3.0 - */ - public IAnnotationModel getAnnotationModel(Object key) { - return (IAnnotationModel) fAttachments.get(key); - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#detach(java.lang.Object) - * @since 3.0 - */ - public IAnnotationModel removeAnnotationModel(Object key) { - IAnnotationModel ret= (IAnnotationModel) fAttachments.remove(key); - if (ret != null) { - for (int i= 0; i < fOpenConnections; i++) - ret.disconnect(fDocument); - ret.removeAnnotationModelListener(fModelListener); - } - return ret; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationModelExtension#getModificationStamp() - * @since 3.0 - */ - public Object getModificationStamp() { - return fModificationStamp; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java deleted file mode 100644 index f188b09212a..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import org.eclipse.jface.text.Position; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - - -/** - * Specification of changes applied to annotation models. The event carries the - * changed annotation model as well as added, removed, and modified annotations. - * <p> - * An event can be sealed. Afterwards it can not be modified. Thus, the normal - * process is that an empty event is created, filled with the changed - * information, and before it is sent to the listeners, the event is sealed. - * - * @see org.eclipse.jface.text.source.IAnnotationModel - * @see org.eclipse.jface.text.source.IAnnotationModelListenerExtension - * @since 2.0 - */ -public class AnnotationModelEvent { - - /** The model this event refers to. */ - private IAnnotationModel fAnnotationModel; - /** - * The added annotations. - * @since 3.0 - */ - private Set fAddedAnnotations= new HashSet(); - /** - * The removed annotations. - * @since 3.0 - */ - private Map fRemovedAnnotations= new HashMap(); - /** - * The changed annotations. - * @since 3.0 - */ - private Set fChangedAnnotations= new HashSet(); - /** - * Indicates that this event does not contain detailed information. - * @since 3.0 - */ - private boolean fIsWorldChange; - /** - * The modification stamp. - * @since 3.0 - */ - private Object fModificationStamp; - - /** - * Creates a new annotation model event for the given model. - * - * @param model the model - */ - public AnnotationModelEvent(IAnnotationModel model) { - this(model, true); - } - - /** - * Creates a new annotation model event for the given model. - * - * @param model the model - * @param isWorldChange <code>true</code> if world change - * @since 3.0 - */ - public AnnotationModelEvent(IAnnotationModel model, boolean isWorldChange) { - fAnnotationModel= model; - fIsWorldChange= isWorldChange; - } - - /** - * Returns the model this event refers to. - * - * @return the model this events belongs to - */ - public IAnnotationModel getAnnotationModel() { - return fAnnotationModel; - } - - /** - * Adds the given annotation to the set of annotations that are reported as - * being added from the model. If this event is considered a world change, - * it is no longer so after this method has successfully finished. - * - * @param annotation the added annotation - * @since 3.0 - */ - public void annotationAdded(Annotation annotation) { - fAddedAnnotations.add(annotation); - fIsWorldChange= false; - } - - /** - * Returns the added annotations. - * - * @return the added annotations - * @since 3.0 - */ - public Annotation[] getAddedAnnotations() { - int size= fAddedAnnotations.size(); - Annotation[] added= new Annotation[size]; - fAddedAnnotations.toArray(added); - return added; - } - - /** - * Adds the given annotation to the set of annotations that are reported as - * being removed from the model. If this event is considered a world - * change, it is no longer so after this method has successfully finished. - * - * @param annotation the removed annotation - * @since 3.0 - */ - public void annotationRemoved(Annotation annotation) { - annotationRemoved(annotation, null); - } - - /** - * Adds the given annotation to the set of annotations that are reported as - * being removed from the model. If this event is considered a world - * change, it is no longer so after this method has successfully finished. - * - * @param annotation the removed annotation - * @param position the position of the removed annotation - * @since 3.0 - */ - public void annotationRemoved(Annotation annotation, Position position) { - fRemovedAnnotations.put(annotation, position); - fIsWorldChange= false; - } - - /** - * Returns the removed annotations. - * - * @return the removed annotations - * @since 3.0 - */ - public Annotation[] getRemovedAnnotations() { - int size= fRemovedAnnotations.size(); - Annotation[] removed= new Annotation[size]; - fRemovedAnnotations.keySet().toArray(removed); - return removed; - } - - /** - * Returns the position of the removed annotation at that point in time - * when the annotation has been removed. - * - * @param annotation the removed annotation - * @return the position of the removed annotation or <code>null</code> - * @since 3.0 - */ - public Position getPositionOfRemovedAnnotation(Annotation annotation) { - return (Position) fRemovedAnnotations.get(annotation); - } - - /** - * Adds the given annotation to the set of annotations that are reported as - * being changed from the model. If this event is considered a world - * change, it is no longer so after this method has successfully finished. - * - * @param annotation the changed annotation - * @since 3.0 - */ - public void annotationChanged(Annotation annotation) { - fChangedAnnotations.add(annotation); - fIsWorldChange= false; - } - - /** - * Returns the changed annotations. - * - * @return the changed annotations - * @since 3.0 - */ - public Annotation[] getChangedAnnotations() { - int size= fChangedAnnotations.size(); - Annotation[] changed= new Annotation[size]; - fChangedAnnotations.toArray(changed); - return changed; - } - - /** - * Returns whether this annotation model event is empty or not. If this - * event represents a world change, this method returns <code>false</code> - * although the event does not carry any added, removed, or changed - * annotations. - * - * @return <code>true</code> if this event is empty - * @since 3.0 - */ - public boolean isEmpty() { - return !fIsWorldChange && fAddedAnnotations.isEmpty() && fRemovedAnnotations.isEmpty() && fChangedAnnotations.isEmpty(); - } - - /** - * Returns whether this annotation model events contains detailed - * information about the modifications applied to the event annotation - * model or whether it represents a world change. I.e. everything in the - * model might have changed. - * - * @return <code>true</code> if world change, <code>false</code> otherwise - * @since 3.0 - */ - public boolean isWorldChange() { - return fIsWorldChange; - } - - /** - * Marks this event as world change according to the given flag. - * - * @param isWorldChange <code>true</code> if this event is a world change, <code>false</code> otherwise - * @since 3.0 - */ - void markWorldChange(boolean isWorldChange) { - fIsWorldChange= isWorldChange; - } - - /** - * Returns whether this annotation model event is still valid. - * - * @return <code>true</code> if this event is still valid, <code>false</code> otherwise - * @since 3.0 - */ - public boolean isValid() { - if (fModificationStamp != null && fAnnotationModel instanceof IAnnotationModelExtension) { - IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel; - return fModificationStamp == extension.getModificationStamp(); - } - return true; - } - - /** - * Seals this event. Any direct modification to the annotation model after the event has been sealed - * invalidates this event. - * - * @since 3.0 - */ - public void markSealed() { - if (fAnnotationModel instanceof IAnnotationModelExtension) { - IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel; - fModificationStamp= extension.getModificationStamp(); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java deleted file mode 100644 index 3aa9ba6b3df..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jface.text.ISynchronizable; - - -/** - * An annotation map is a map specialized for the requirements of an annotation - * model. The annotation map supports a customizable lock object which is used - * to synchronize concurrent operations on the map (see - * {@link org.eclipse.jface.text.ISynchronizable}. The map supports two - * iterator methods, one for the values and one for the keys of the map. The - * returned iterators are robust, i.e. they work on a copy of the values and - * keys set that is made at the point in time the iterator methods are called. - * <p> - * The returned collections of the methods <code>values</code>, - * <code>entrySet</code>, and <code>keySet</code> are not synchronized on - * the annotation map's lock object. - * <p> - * - * @see org.eclipse.jface.text.source.IAnnotationModel - * @since 3.0 - */ -public interface IAnnotationMap extends Map, ISynchronizable { - - /** - * Returns an iterator for a copy of this annotation map's values. - * - * @return an iterator for a copy of this map's values - */ - Iterator valuesIterator(); - - /** - * Returns an iterator for a copy of this map's key set. - * - * @return an iterator for a copy of this map's key set - */ - Iterator keySetIterator(); - - /** - * {@inheritDoc} - * - * The returned set is not synchronized on this annotation map's lock object. - */ - Set entrySet(); - - /** - * {@inheritDoc} - * - * The returned set is not synchronized on this annotation map's lock object. - */ - Set keySet(); - - /** - * {@inheritDoc} - * - * The returned collection is not synchronized on this annotation map's lock object. - */ - Collection values(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java deleted file mode 100644 index 385f463edc3..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import java.util.Iterator; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - - -/** - * This interface defines the model for managing annotations attached to a document. - * The model maintains a set of annotations for a given document and notifies registered annotation - * model listeners about annotation model changes. It also provides methods - * for querying the current position of an annotation managed - * by this model. - * <p> - * In order to provide backward compatibility for clients of <code>IAnnotationModel</code>, extension - * interfaces are used to provide a means of evolution. The following extension interfaces - * exist: - * <ul> - * <li> {@link org.eclipse.jface.text.source.IAnnotationModelExtension} since version 3.0 introducing the concept - * of model piggybacking annotation models, modification time stamps, and enhanced manipulation methods. - * </li> - * </ul> - * </p> - * - * Clients may implement this interface or use the default implementation provided - * by <code>AnnotationModel</code>. - * - * @see org.eclipse.jface.text.source.IAnnotationModelExtension - * @see org.eclipse.jface.text.source.Annotation - * @see org.eclipse.jface.text.source.IAnnotationModelListener - */ -public interface IAnnotationModel { - - /** - * Registers the annotation model listener with this annotation model. - * After registration listener is informed about each change of this model. - * If the listener is already registered nothing happens. - * - * @param listener the listener to be registered, may not be <code>null</code> - */ - void addAnnotationModelListener(IAnnotationModelListener listener); - - /** - * Removes the listener from the model's list of annotation model listeners. - * If the listener is not registered with the model nothing happens. - * - * @param listener the listener to be removed, may not be <code>null</code> - */ - void removeAnnotationModelListener(IAnnotationModelListener listener); - - /** - * Connects the annotation model to a document. The annotations managed - * by this model must subsequently update according to the changes applied - * to the document. Once an annotation model is connected to a document, - * all further <code>connect</code> calls must mention the document the - * model is already connected to. An annotation model primarily uses - * <code>connect</code> and <code>disconnect</code> for reference counting - * the document. Reference counting frees the clients from keeping tracker - * whether a model has already been connected to a document. - * - * @param document the document the model gets connected to, - * may not be <code>null</code> - * - * @see #disconnect(IDocument) - */ - void connect(IDocument document); - - /** - * Disconnects this model from a document. After that, document changes no longer matter. - * An annotation model may only be disconnected from a document to which it has been - * connected before. If the model reference counts the connections to a document, - * the connection to the document may only be terminated if the reference count does - * down to 0. - * - * @param document the document the model gets disconnected from, - * may not be <code>null</code> - * - * @see #connect(IDocument) for further specification details - */ - void disconnect(IDocument document); - - /** - * Adds a annotation to this annotation model. The annotation is associated with - * with the given position which describes the range covered by the annotation. - * All registered annotation model listeners are informed about the change. - * If the model is connected to a document, the position is automatically - * updated on document changes. If the annotation is already managed by - * this annotation model or is not a valid position in the connected nothing happens. - * - * @param annotation the annotation to add, may not be <code>null</code> - * @param position the position describing the range covered by this annotation, - * may not be <code>null</code> - */ - void addAnnotation(Annotation annotation, Position position); - - /** - * Removes the given annotation from the model. I.e. the annotation is no - * longer managed by this model. The position associated with the annotation - * is no longer updated on document changes. If the annotation is not - * managed by this model, nothing happens. - * - * @param annotation the annotation to be removed from this model, - * may not be <code>null</code> - */ - void removeAnnotation(Annotation annotation); - - /** - * Returns all annotations managed by this model. - * - * @return all annotations managed by this model - */ - Iterator getAnnotationIterator(); - - /** - * Returns the position associated with the given annotation. - * - * @param annotation the annotation whose position should be returned - * @return the position of the given annotation or <code>null</code> if no - * associated annotation exists - */ - Position getPosition(Annotation annotation); -} - diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java deleted file mode 100644 index dd33fd4f4ab..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -import java.util.Map; - -import org.eclipse.jface.text.Position; - - -/** - * Extends {@link org.eclipse.jface.text.source.IAnnotationModel}with the - * ability piggyback other annotation models. It also introduces the concept of - * modification time stamps and adds methods for richer manipulation methods. - * - * @since 3.0 - */ -public interface IAnnotationModelExtension { - - /** - * Attaches <code>attachment</code> to the receiver. Connects - * <code>attachment</code> to the currently connected document. If - * <code>attachment</code> is already attached (even) under a different - * key), it is not attached again. - * - * @param key the key through which the attachment is identified. - * @param attachment the attached <code>IAnnotationModel</code> - */ - void addAnnotationModel(Object key, IAnnotationModel attachment); - - /** - * Returns the attached <code>IAnnotationModel</code> for <code>key</code>, - * or <code>null</code> if none is attached for <code>key</code>. - * - * @param key the key through which the attachment is identified. - * @return an <code>IAnnotationModel</code> attached under - * <code>key</code>, or <code>null</code> - */ - IAnnotationModel getAnnotationModel(Object key); - - /** - * Removes and returns the attached <code>IAnnotationModel</code> for - * <code>key</code>. - * - * @param key the key through which the attachment is identified. - * @return an <code>IAnnotationModel</code> attached under - * <code>key</code>, or <code>null</code> - */ - IAnnotationModel removeAnnotationModel(Object key); - - /** - * Adds and removes annotations to/from this annotation model in a single - * step. The annotations to remove are given in an array. The annotations to - * add are provided in a map associating the annotations with the positions - * at which they should be added. All registered annotation model listeners - * are informed about the change. If the model is connected to a document, - * the positions are automatically updated on document changes. Annotations - * that are already managed by this annotation model or are not associated - * with a valid position in the connected document have no effect. - * - * @param annotationsToRemove the annotations to be removed, may be - * <code>null</code> - * @param annotationsToAdd the annotations which will be added, may be - * <code>null</code> each map entry has an - * <code>Annotation</code> as key and a <code>Position</code> - * as value - * @throws ClassCastException if one of the map key or values has a wrong - * type - */ - void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd) throws ClassCastException; - - /** - * Modifies the position associated with the given annotation to equal the - * given position. If the annotation is not yet managed by this annotation - * model, the annotation is added. If the given position is - * <code>null</code> the annotation is removed from the model. All - * annotation model change listeners will be informed about the change. - * - * @param annotation the annotation whose associated position should be - * modified - * @param position the position to whose values the associated position - * should be changed - */ - void modifyAnnotationPosition(Annotation annotation, Position position); - - /** - * Removes all annotations from this annotation model. - */ - void removeAllAnnotations(); - - /** - * Returns the modification stamp of this annotation model. - * - * @return the modification stamp of this annotation model - */ - Object getModificationStamp(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java deleted file mode 100644 index 9cadfe03989..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -/** - * Interface for objects interested in getting informed about annotation model - * changes. Changes are the addition or removal of annotations managed by the - * model. Clients may implement this interface. - * - * In order to provided backward compatibility for clients of - * <code>IAnnotationModelListener</code>, extension interfaces are used to - * provide a means of evolution. The following extension interfaces exist: - * <ul> - * <li>{@link org.eclipse.jface.text.source.IAnnotationModelListenerExtension} - * since version 2.0 replacing the change notification mechanisms.</li> - * </ul> - * - * @see org.eclipse.jface.text.source.IAnnotationModel - */ -public interface IAnnotationModelListener { - - /** - * Called if a model change occurred on the given model.<p> - * Replaced by {@link IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)}. - * - * @param model the changed annotation model - */ - void modelChanged(IAnnotationModel model); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java deleted file mode 100644 index ed480250352..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.source; - - -/** - * Extension interface for {@link IAnnotationModelListener}. Introduces a - * notification mechanism that notifies the user by means of <code>AnnotationModelEvent</code>s. - * Thus, more detailed information can be sent to the listener. This mechanism replaces the original notification - * mechanism of <code>IAnnotationModelListener</code>. - * - * @since 2.0 - */ -public interface IAnnotationModelListenerExtension { - - /** - * Called if a model change occurred on the given model. - * - * @param event the event to be sent out - */ - void modelChanged(AnnotationModelEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/package.html b/org.eclipse.text/src/org/eclipse/jface/text/source/package.html deleted file mode 100644 index 3d0a9718a1e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> -<html><head> - <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> - <meta content="IBM" name="Author"> - <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]" name="GENERATOR"><title>annotation models</title></head> - -<body> -<p>Provides a support for managing annotations attached to a document.</p> -<h3>Package Specification</h3> -<p><tt>IAnnotationModels</tt> manage <tt>Annotations</tt>. - When an annotation model is connected to an <tt>IDocument</tt>, - any change to the document is reflected in the position of the managed annotations. - Implementers of <tt>IAnnotationModelListener</tt> - registered with an <tt>IAnnotationModel</tt> - object get informed about changes of the model in respect to annotations.</p> -</body></html>
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java deleted file mode 100644 index 54c1273067e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A typical text based document template context. - * <p> - * Clients may instantiate and extend this class. - * </p> - * - * @since 3.0 - */ -public class DocumentTemplateContext extends TemplateContext { - - /** The text of the document. */ - private final IDocument fDocument; - /** The completion offset. */ - private int fCompletionOffset; - /** The completion length. */ - private int fCompletionLength; - - /** - * Creates a document template context. - * - * @param type the context type - * @param document the document this context applies to - * @param completionOffset the completion offset (for usage in content - * assist) - * @param completionLength the completion length - */ - public DocumentTemplateContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength) { - super(type); - - Assert.isNotNull(document); - Assert.isTrue(completionOffset >= 0 && completionOffset <= document.getLength()); - Assert.isTrue(completionLength >= 0); - - fDocument= document; - fCompletionOffset= completionOffset; - fCompletionLength= completionLength; - } - - /** - * Returns the document. - * - * @return the document - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * Returns the completion offset within the string of the context. - * - * @return the completion offset within the string of the context - */ - public int getCompletionOffset() { - return fCompletionOffset; - } - - /** - * Sets the completion offset. - * - * @param newOffset the new completion offset - */ - protected void setCompletionOffset(int newOffset) { - fCompletionOffset= newOffset; - } - - /** - * Returns the completion length within the string of the context. - * - * @return the completion length within the string of the context - */ - public int getCompletionLength() { - return fCompletionLength; - } - - /** - * Sets the completion length. - * - * @param newLength the new completion length - */ - protected void setCompletionLength(int newLength) { - fCompletionLength= newLength; - } - - /** - * Returns the keyword which triggered template insertion. - * - * @return the keyword which triggered template insertion - */ - public String getKey() { - int offset= getStart(); - int length= getEnd() - offset; - try { - return fDocument.get(offset, length); - } catch (BadLocationException e) { - return ""; //$NON-NLS-1$ - } - } - - /** - * Returns the beginning offset of the keyword. - * - * @return the beginning offset of the keyword - */ - public int getStart() { - return fCompletionOffset; - } - - /** - * Returns the end offset of the keyword. - * - * @return the end offset of the keyword - */ - public int getEnd() { - return fCompletionOffset + fCompletionLength; - } - - /* - * @see org.eclipse.jface.text.templates.TemplateContext#canEvaluate(org.eclipse.jface.text.templates.Template) - */ - public boolean canEvaluate(Template template) { - return true; - } - - /* - * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template) - */ - public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { - if (!canEvaluate(template)) - return null; - - TemplateTranslator translator= new TemplateTranslator(); - TemplateBuffer buffer= translator.translate(template); - - getContextType().resolve(buffer, this); - - return buffer; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java deleted file mode 100644 index b35a02aefd3..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Sebastian Davids: sdavids@gmx.de - see bug 25376 - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import java.text.DateFormat; -import java.util.Calendar; - - -/** - * Global variables which are available in any context. - * <p> - * Clients may instantiate the classes contained within this class. - * </p> - * - * @since 3.0 - */ -public class GlobalTemplateVariables { - - /** The type of the selection variables. */ - public static final String SELECTION= "selection"; //$NON-NLS-1$ - - /** - * The cursor variable determines the cursor placement after template edition. - */ - public static class Cursor extends SimpleTemplateVariableResolver { - - /** Name of the cursor variable, value= {@value} */ - public static final String NAME= "cursor"; //$NON-NLS-1$ - - /** - * Creates a new cursor variable - */ - public Cursor() { - super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ - setEvaluationString(""); //$NON-NLS-1$ - } - } - - /** - * The word selection variable determines templates that work on a full - * lines selection. - */ - public static class WordSelection extends SimpleTemplateVariableResolver { - - /** Name of the word selection variable, value= {@value} */ - public static final String NAME= "word_selection"; //$NON-NLS-1$ - - /** - * Creates a new word selection variable - */ - public WordSelection() { - super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$ - } - protected String resolve(TemplateContext context) { - String selection= context.getVariable(SELECTION); //$NON-NLS-1$ - if (selection == null) - return ""; //$NON-NLS-1$ - else - return selection; - } - } - - /** - * The line selection variable determines templates that work on selected - * lines. - */ - public static class LineSelection extends SimpleTemplateVariableResolver { - - /** Name of the line selection variable, value= {@value} */ - public static final String NAME= "line_selection"; //$NON-NLS-1$ - - /** - * Creates a new line selection variable - */ - public LineSelection() { - super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$ - } - protected String resolve(TemplateContext context) { - String selection= context.getVariable(SELECTION); //$NON-NLS-1$ - if (selection == null) - return ""; //$NON-NLS-1$ - else - return selection; - } - } - - /** - * The dollar variable inserts an escaped dollar symbol. - */ - public static class Dollar extends SimpleTemplateVariableResolver { - /** - * Creates a new dollar variable - */ - public Dollar() { - super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$ - setEvaluationString("$"); //$NON-NLS-1$ - } - } - - /** - * The date variable evaluates to the current date. - */ - public static class Date extends SimpleTemplateVariableResolver { - /** - * Creates a new date variable - */ - public Date() { - super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ - } - protected String resolve(TemplateContext context) { - return DateFormat.getDateInstance().format(new java.util.Date()); - } - } - - /** - * The year variable evaluates to the current year. - */ - public static class Year extends SimpleTemplateVariableResolver { - /** - * Creates a new year variable - */ - public Year() { - super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$ - } - protected String resolve(TemplateContext context) { - return Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); - } - } - - /** - * The time variable evaluates to the current time. - */ - public static class Time extends SimpleTemplateVariableResolver { - /** - * Creates a new time variable - */ - public Time() { - super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * {@inheritDoc} - */ - protected String resolve(TemplateContext context) { - return DateFormat.getTimeInstance().format(new java.util.Date()); - } - } - - /** - * The user variable evaluates to the current user. - */ - public static class User extends SimpleTemplateVariableResolver { - /** - * Creates a new user name variable - */ - public User() { - super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * {@inheritDoc} - */ - protected String resolve(TemplateContext context) { - return System.getProperty("user.name"); //$NON-NLS-1$ - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java deleted file mode 100644 index 87324983c6b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - - -/** - * A simple template variable resolver, which always evaluates to a defined string. - * <p> - * Clients may instantiate and extend this class. - * </p> - * - * @since 3.0 - */ -public class SimpleTemplateVariableResolver extends TemplateVariableResolver { - - /** The string to which this variable evaluates. */ - private String fEvaluationString; - - /* - * @see TemplateVariableResolver#TemplateVariableResolver(String, String) - */ - protected SimpleTemplateVariableResolver(String type, String description) { - super(type, description); - } - - /** - * Sets the string to which this variable evaluates. - * - * @param evaluationString the evaluation string, may be <code>null</code>. - */ - public final void setEvaluationString(String evaluationString) { - fEvaluationString= evaluationString; - } - - /* - * @see TemplateVariableResolver#evaluate(TemplateContext) - */ - protected String resolve(TemplateContext context) { - return fEvaluationString; - } - - /** - * Returns always <code>true</code>, since simple variables are normally - * unambiguous. - * - * @param context {@inheritDoc} - * @return <code>true</code> - */ - protected boolean isUnambiguous(TemplateContext context) { - return true; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java deleted file mode 100644 index 7058ca6d7e4..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import org.eclipse.jface.text.Assert; - -/** - * A template consisting of a name and a pattern. - * <p> - * Clients may instantiate this class. May become final in the future. - * </p> - * @since 3.0 - */ -public class Template { - /* XXX this class should be final or implement Cloneable, or both. */ - - /** The name of this template */ - private String fName; - /** A description of this template */ - private String fDescription; - /** The name of the context type of this template */ - private String fContextTypeId; - /** The template pattern. */ - private String fPattern; - - /** - * Creates an empty template. - */ - public Template() { - this("", "", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - - /** - * Creates a copy of a template. - * - * @param template the template to copy - */ - public Template(Template template) { - this(template.getName(), template.getDescription(), template.getContextTypeId(), template.getPattern()); - } - - /** - * Creates a template. - * - * @param name the name of the template - * @param description the description of the template - * @param contextTypeId the id of the context type in which the template can be applied - * @param pattern the template pattern - */ - public Template(String name, String description, String contextTypeId, String pattern) { - setDescription(description); - setName(name); - setContextTypeId(contextTypeId); - setPattern(pattern); - } - - /* - * @see Object#hashCode() - */ - public int hashCode() { - return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeId.hashCode(); - } - - /** - * Sets the description of the template. - * - * @param description the new description - */ - public void setDescription(String description) { - Assert.isNotNull(description); - fDescription= description; - } - - /** - * Returns the description of the template. - * - * @return the description of the template - */ - public String getDescription() { - return fDescription; - } - - /** - * Sets the name of the context type in which the template can be applied. - * - * @param contextTypeId the new context type name - */ - public void setContextTypeId(String contextTypeId) { - Assert.isNotNull(contextTypeId); - fContextTypeId= contextTypeId; - } - - /** - * Returns the id of the context type in which the template can be applied. - * - * @return the id of the context type in which the template can be applied - */ - public String getContextTypeId() { - return fContextTypeId; - } - - /** - * Sets the name of the template. - * - * @param name the name of the template - */ - public void setName(String name) { - fName= name; - } - - /** - * Returns the name of the template. - * - * @return the name of the template - */ - public String getName() { - return fName; - } - - /** - * Sets the pattern of the template. - * - * @param pattern the new pattern of the template - */ - public void setPattern(String pattern) { - fPattern= pattern; - } - - /** - * Returns the template pattern. - * - * @return the template pattern - */ - public String getPattern() { - return fPattern; - } - - /** - * Returns <code>true</code> if template is enabled and matches the context, - * <code>false</code> otherwise. - * - * @param prefix the prefix (e.g. inside a document) to match - * @param contextTypeName the context type name to match - * @return <code>true</code> if template is enabled and matches the context, - * <code>false</code> otherwise - */ - public boolean matches(String prefix, String contextTypeName) { - return fContextTypeId.equals(contextTypeName); - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (!(o instanceof Template)) - return false; - - Template t= (Template) o; - if (t == this) - return true; - - return t.fName.equals(fName) - && t.fPattern.equals(fPattern) - && t.fContextTypeId.equals(fContextTypeId) - && t.fDescription.equals(fDescription); - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java deleted file mode 100644 index cbd00db6229..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import org.eclipse.jface.text.Assert; - -/** - * A template buffer is a container for a string and variables. - * <p> - * Clients may instantiate this class. - * </p> - * - * @since 3.0 - */ -public final class TemplateBuffer { - - /** The string of the template buffer */ - private String fString; - /** The variable positions of the template buffer */ - private TemplateVariable[] fVariables; - - /** - * Creates a template buffer. - * - * @param string the string - * @param variables the variable positions - */ - public TemplateBuffer(String string, TemplateVariable[] variables) { - setContent(string, variables); - } - - /** - * Sets the content of the template buffer. - * - * @param string the string - * @param variables the variable positions - */ - public final void setContent(String string, TemplateVariable[] variables) { - Assert.isNotNull(string); - Assert.isNotNull(variables); - - // XXX assert non-overlapping variable properties - - fString= string; - fVariables= variables; - } - - /** - * Returns the string of the template buffer. - * - * @return the string representation of the template buffer - */ - public final String getString() { - return fString; - } - - /** - * Returns the variable positions of the template buffer. - * - * @return the variable positions of the template buffer - */ - public final TemplateVariable[] getVariables() { - return fVariables; - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java deleted file mode 100644 index cad34a9184b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.text.BadLocationException; - -/** - * Provides the context for a <code>Template</code> being resolved. Keeps track - * of resolved variables. - * <p> - * Clients may extend this class. - * </p> - * - * @since 3.0 - */ -public abstract class TemplateContext { - - /** The context type of this context */ - private final TemplateContextType fContextType; - /** Additional variables. */ - private final Map fVariables= new HashMap(); - /** A flag to indicate that the context should not be modified. */ - private boolean fReadOnly; - - /** - * Creates a template context of a particular context type. - * - * @param contextType the context type of this context - */ - protected TemplateContext(TemplateContextType contextType) { - fContextType= contextType; - fReadOnly= true; - } - - /** - * Returns the context type of this context. - * - * @return the context type of this context - */ - public TemplateContextType getContextType() { - return fContextType; - } - - /** - * Sets or clears the read-only flag. - * - * @param readOnly the new read-only state - */ - public void setReadOnly(boolean readOnly) { - fReadOnly= readOnly; - } - - /** - * Returns <code>true</code> if the receiver is read-only, <code>false</code> otherwise. - * - * @return <code>true</code> if the receiver is read-only, <code>false</code> otherwise - */ - public boolean isReadOnly() { - return fReadOnly; - } - - /** - * Defines the value of a variable. - * - * @param name the name of the variable - * @param value the value of the variable, <code>null</code> to undefine a variable - */ - public void setVariable(String name, String value) { - fVariables.put(name, value); - } - - /** - * Returns the value of a defined variable. - * - * @param name the name of the variable - * @return returns the value of the variable, <code>null</code> if the variable was not defined - */ - public String getVariable(String name) { - return (String) fVariables.get(name); - } - - /** - * Evaluates the template in this context and returns a template buffer. - * <p> - * Evaluation means translating the template into a <code>TemplateBuffer</code>, - * resolving the defined variables in this context and possibly formatting - * the resolved buffer.</p> - * - * @param template the template to evaluate - * @return returns the buffer with the evaluated template or <code>null</code> if the buffer could not be created - * @throws BadLocationException if evaluation fails due to concurrently changed documents etc. - * @throws TemplateException if the template specification is not valid - */ - public abstract TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException; - - /** - * Tests if the specified template can be evaluated in this context. - * <p>Examples are templates defined for a different context (e.g. a javadoc - * template cannot be evaluated in Java context).</p> - * - * @param template the <code>Template</code> to check - * @return <code>true</code> if <code>template</code> can be evaluated - * in this context, <code>false</code> otherwise - */ - public abstract boolean canEvaluate(Template template); - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java deleted file mode 100644 index b480a39d580..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.RangeMarker; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; - - -/** - * A context type defines a context within which templates are resolved. It - * stores a number of <code>TemplateVariableResolver</code>s. A - * <code>TemplateBuffer</code> can be resolved in a - * <code>TemplateContext</code> using the - * {@link #resolve(TemplateBuffer, TemplateContext)} method. - * <p> - * Clients may extend this class. - * </p> - * - * @since 3.0 - */ -public class TemplateContextType { - - /** Name of the context type. */ - private /* final */ String fId= null; - - /** Variable resolvers used by this content type. */ - private final Map fResolvers= new HashMap(); - - /** The name of the context type. */ - private String fName= null; - - /** - * Creates a context type with an identifier. The identifier must be unique, - * a qualified name is suggested. The id is also used as name. - * - * @param id the unique identifier of the context type - */ - public TemplateContextType(String id) { - this(id, id); - } - - /** - * Creates a context type with an identifier. The identifier must be unique, a qualified name is suggested. - * - * @param id the unique identifier of the context type - * @param name the name of the context type - */ - public TemplateContextType(String id, String name) { - Assert.isNotNull(id); - Assert.isNotNull(name); - fId= id; - fName= name; - } - - /** - * Returns the name of the context type. - * - * @return the name of the receiver - */ - public String getId() { - return fId; - } - - - /** - * Returns the name of the context type. - * - * @return the name of the context type - */ - public String getName() { - return fName; - } - - /** - * Creates a context type with a <code>null</code> identifier. - * <p> - * This is a framework-only constructor that exists only so that context - * types can be contributed via an extension point and that should not be - * called in client code except for subclass constructors; use - * {@link #TemplateContextType(String)} instead. - * </p> - */ - public TemplateContextType() { - } - - /** - * Sets the id of this context. - * <p> - * This is a framework-only method that exists solely so that context types - * can be contributed via an extension point and that should not be called - * in client code; use {@link #TemplateContextType(String)} instead. - * </p> - * - * @param id the identifier of this context - * @throws RuntimeException an unspecified exception if the id has already - * been set on this context type - */ - public final void setId(String id) throws RuntimeException { - Assert.isNotNull(id); - Assert.isTrue(fId == null); // may only be called once when the context is instantiated - fId= id; - } - - /** - * Sets the name of the context type. - * - * <p> - * This is a framework-only method that exists solely so that context types - * can be contributed via an extension point and that should not be called - * in client code; use {@link #TemplateContextType(String, String)} instead. - * </p> - * - * @param name the name of the context type - */ - public final void setName(String name) { - Assert.isTrue(fName == null); // only initialized by extension code - fName= name; - } - - /** - * Adds a variable resolver to the context type. If there already is a resolver - * for the same type, the previous one gets replaced by <code>resolver</code>. - * - * @param resolver the resolver to be added under its name - */ - public void addResolver(TemplateVariableResolver resolver) { - Assert.isNotNull(resolver); - fResolvers.put(resolver.getType(), resolver); - } - - /** - * Removes a template variable from the context type. - * - * @param resolver the variable to be removed - */ - public void removeResolver(TemplateVariableResolver resolver) { - Assert.isNotNull(resolver); - fResolvers.remove(resolver.getType()); - } - - /** - * Removes all template variables from the context type. - */ - public void removeAllResolvers() { - fResolvers.clear(); - } - - /** - * Returns an iterator for the variables known to the context type. - * - * @return an iterator over the variables in this context type - */ - public Iterator resolvers() { - return Collections.unmodifiableMap(fResolvers).values().iterator(); - } - - /** - * Returns the resolver for the given type. - * - * @param type the type for which a resolver is needed - * @return a resolver for the given type, or <code>null</code> if none is registered - */ - protected TemplateVariableResolver getResolver(String type) { - return (TemplateVariableResolver) fResolvers.get(type); - } - - /** - * Validates a pattern, a <code>TemplateException</code> is thrown if - * validation fails. - * - * @param pattern the template pattern to validate - * @throws TemplateException if the pattern is invalid - */ - public void validate(String pattern) throws TemplateException { - TemplateTranslator translator= new TemplateTranslator(); - TemplateBuffer buffer= translator.translate(pattern); - validateVariables(buffer.getVariables()); - } - - /** - * Validates the variables in this context type. If a variable is not valid, - * e.g. if its type is not known in this context type, a - * <code>TemplateException</code> is thrown. - * <p> - * The default implementation does nothing. - * </p> - * - * @param variables the variables to validate - * @throws TemplateException if one of the variables is not valid in this - * context type - */ - protected void validateVariables(TemplateVariable[] variables) throws TemplateException { - } - - /** - * Resolves the variables in <code>buffer</code> within <code>context</code> - * and edits the template buffer to reflect the resolved variables. - * - * @param buffer the template buffer - * @param context the template context - * @throws MalformedTreeException if the positions in the buffer overlap - * @throws BadLocationException if the buffer cannot be successfully modified - */ - public void resolve(TemplateBuffer buffer, TemplateContext context) throws MalformedTreeException, BadLocationException { - Assert.isNotNull(context); - TemplateVariable[] variables= buffer.getVariables(); - - List positions= variablesToPositions(variables); - List edits= new ArrayList(5); - - // iterate over all variables and try to resolve them - for (int i= 0; i != variables.length; i++) { - TemplateVariable variable= variables[i]; - - if (variable.isUnambiguous()) - continue; - - // remember old values - int[] oldOffsets= variable.getOffsets(); - int oldLength= variable.getLength(); - String oldValue= variable.getDefaultValue(); - - String type= variable.getType(); - TemplateVariableResolver resolver= (TemplateVariableResolver) fResolvers.get(type); - if (resolver == null) - resolver= new TemplateVariableResolver(type, ""); //$NON-NLS-1$ - resolver.resolve(variable, context); - - String value= variable.getDefaultValue(); - - if (!oldValue.equals(value)) - // update buffer to reflect new value - for (int k= 0; k != oldOffsets.length; k++) - edits.add(new ReplaceEdit(oldOffsets[k], oldLength, value)); - - } - - IDocument document= new Document(buffer.getString()); - MultiTextEdit edit= new MultiTextEdit(0, document.getLength()); - edit.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()])); - edit.addChildren((TextEdit[]) edits.toArray(new TextEdit[edits.size()])); - edit.apply(document, TextEdit.UPDATE_REGIONS); - - positionsToVariables(positions, variables); - - buffer.setContent(document.get(), variables); - } - - private static List variablesToPositions(TemplateVariable[] variables) { - List positions= new ArrayList(5); - for (int i= 0; i != variables.length; i++) { - int[] offsets= variables[i].getOffsets(); - for (int j= 0; j != offsets.length; j++) - positions.add(new RangeMarker(offsets[j], 0)); - } - - return positions; - } - - private static void positionsToVariables(List positions, TemplateVariable[] variables) { - Iterator iterator= positions.iterator(); - - for (int i= 0; i != variables.length; i++) { - TemplateVariable variable= variables[i]; - - int[] offsets= new int[variable.getOffsets().length]; - for (int j= 0; j != offsets.length; j++) - offsets[j]= ((TextEdit) iterator.next()).getOffset(); - - variable.setOffsets(offsets); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java deleted file mode 100644 index dda57ddebd4..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.text.templates; - - -/** - * Thrown when a template cannot be validated. - * <p> - * Clients may instantiate this class. - * </p> - * - * @since 3.0 - */ -public class TemplateException extends Exception { - - /** - * Creates a new template exception. - */ - public TemplateException() { - super(); - } - - /** - * Creates a new template exception. - * - * @param message the message describing the problem that arised - */ - public TemplateException(String message) { - super(message); - } - - /** - * Creates a new template exception. - * - * @param message the message describing the problem that arised - * @param cause the original exception - */ - public TemplateException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Creates a new template exception. - * - * @param cause the original exception - */ - public TemplateException(Throwable cause) { - super(cause); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java deleted file mode 100644 index 2703b767102..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Vector; - -/** - * The template translator translates a string into a template buffer. Regions - * marked as variables are translated into <code>TemplateVariable</code>s. - * <p> - * The EBNF grammar of a valid string is as follows:</p> - * <p> - * template := (text | escape)*. <br /> - * text := character - dollar. <br /> - * escape := dollar ('{' identifier '}' | dollar). <br /> - * dollar := '$'. <br /> - * </p> - * <p> - * Clients may extend the <code>createVariable</code> method of this class. - * </p> - * - * @since 3.0 - */ -public class TemplateTranslator { - - // states - private static final int TEXT= 0; - private static final int ESCAPE= 1; - private static final int IDENTIFIER= 2; - - // tokens - private static final char ESCAPE_CHARACTER= '$'; - private static final char IDENTIFIER_BEGIN= '{'; - private static final char IDENTIFIER_END= '}'; - - /** a buffer for the translation result string */ - private final StringBuffer fBuffer= new StringBuffer(); - /** position offsets of variables */ - private final Vector fOffsets= new Vector(); - /** position lengths of variables */ - private final Vector fLengths= new Vector(); - - /** the current parsing state */ - private int fState; - /** the last translation error */ - private String fErrorMessage; - - /** - * Returns an error message if an error occurred for the last translation, - * <code>null</code> otherwise. - * - * @return the error message if an error occurred during the most recent - * translation, <code>null</code> otherwise - */ - public String getErrorMessage() { - return fErrorMessage; - } - - /** - * Translates a template to a <code>TemplateBuffer</code>. <code>null</code> - * is returned if there was an error. <code>getErrorMessage()</code> retrieves the - * associated error message. - * - * @param template the template to translate. - * @return returns the template buffer corresponding to the string, <code>null</code> - * if there was an error. - * @see #getErrorMessage() - * @throws TemplateException if translation failed - */ - public TemplateBuffer translate(Template template) throws TemplateException { - return translate(template.getPattern()); - } - - /** - * Translates a template string to <code>TemplateBuffer</code>. <code>null</code> - * is returned if there was an error. <code>getErrorMessage()</code> retrieves the - * associated error message. - * - * @param string the string to translate. - * @return returns the template buffer corresponding to the string, <code>null</code> - * if there was an error. - * @see #getErrorMessage() - * @throws TemplateException if translation failed - */ - public TemplateBuffer translate(String string) throws TemplateException { - - fBuffer.setLength(0); - fOffsets.clear(); - fLengths.clear(); - fState= TEXT; - fErrorMessage= null; - - if (!parse(string)) - throw new TemplateException(fErrorMessage); - - switch (fState) { - case TEXT: - break; - - // illegal - case ESCAPE: - throw new TemplateException(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$ - - // illegal - case IDENTIFIER: - throw new TemplateException(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$ - } - - int[] offsets= new int[fOffsets.size()]; - int[] lengths= new int[fLengths.size()]; - - for (int i= 0; i < fOffsets.size(); i++) { - offsets[i]= ((Integer) fOffsets.get(i)).intValue(); - lengths[i]= ((Integer) fLengths.get(i)).intValue(); - } - - String translatedString= fBuffer.toString(); - TemplateVariable[] variables= findVariables(translatedString, offsets, lengths); - - return new TemplateBuffer(translatedString, variables); - } - - private TemplateVariable[] findVariables(String string, int[] offsets, int[] lengths) { - - Map map= new HashMap(); - - for (int i= 0; i != offsets.length; i++) { - int offset= offsets[i]; - int length= lengths[i]; - - String content= string.substring(offset, offset + length); - Vector vector= (Vector) map.get(content); - if (vector == null) { - vector= new Vector(); - map.put(content, vector); - } - vector.add(new Integer(offset)); - } - - TemplateVariable[] variables= new TemplateVariable[map.size()]; - int k= 0; - - Set keys= map.keySet(); - for (Iterator i= keys.iterator(); i.hasNext(); ) { - String name= (String) i.next(); - Vector vector= (Vector) map.get(name); - - int[] offsets_= new int[vector.size()]; - for (int j= 0; j != offsets_.length; j++) - offsets_[j]= ((Integer) vector.get(j)).intValue(); - - variables[k]= createVariable(name, name, offsets_); - k++; - } - - return variables; - } - - /** - * Hook method to create new variables. Subclasses may override to supply their - * custom variable type. - * <p> - * Clients may replace this method. - * </p> - * - * @param type the type of the new variable. - * @param name the name of the new variable. - * @param offsets the offsets where the variable occurs in the template - * @return a new instance of <code>TemplateVariable</code> - */ - protected TemplateVariable createVariable(String type, String name, int[] offsets) { - return new TemplateVariable(type, name, offsets); - } - - /** - * Internal parser. - * - * @param string the string to parse - * @return <code>true</code> if parsing was successful - */ - private boolean parse(String string) { - - for (int i= 0; i != string.length(); i++) { - char ch= string.charAt(i); - - switch (fState) { - case TEXT: - switch (ch) { - case ESCAPE_CHARACTER: - fState= ESCAPE; - break; - - default: - fBuffer.append(ch); - break; - } - break; - - case ESCAPE: - switch (ch) { - case ESCAPE_CHARACTER: - fBuffer.append(ch); - fState= TEXT; - break; - - case IDENTIFIER_BEGIN: - fOffsets.add(new Integer(fBuffer.length())); - fState= IDENTIFIER; - break; - - default: - // illegal single escape character, but be tolerant - fErrorMessage= TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable"); //$NON-NLS-1$ - fBuffer.append(ESCAPE_CHARACTER); - fBuffer.append(ch); - fState= TEXT; - return false; - } - break; - - case IDENTIFIER: - switch (ch) { - case IDENTIFIER_END: - int offset = ((Integer) fOffsets.get(fOffsets.size() - 1)).intValue(); - fLengths.add(new Integer(fBuffer.length() - offset)); - fState= TEXT; - break; - - default: - if (!Character.isUnicodeIdentifierStart(ch) && - !Character.isUnicodeIdentifierPart(ch)) - { - // illegal identifier character - fErrorMessage= TextTemplateMessages.getString("TemplateTranslator.error.invalid.identifier"); //$NON-NLS-1$ - return false; - } - - fBuffer.append(ch); - break; - } - break; - } - } - - return true; - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java deleted file mode 100644 index 8d47a2b430c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import org.eclipse.jface.text.Assert; - -/** - * A <code>TemplateVariable</code> represents a set of positions into a - * <code>TemplateBuffer</code> with identical content each. <code>TemplateVariableResolver</code>s - * can be used to resolve a template variable to a symbol available from the - * <code>TemplateContext</code>. - * <p> - * Clients may instantiate and extend this class. - * </p> - * - * @see TemplateVariableResolver - * @see TemplateBuffer - * @since 3.0 - */ -public class TemplateVariable { - - /** The type name of the variable */ - private final String fType; - /** The name of the variable. */ - private final String fName; - /** The offsets of the variable. */ - private int[] fOffsets; - /** Flag indicating if the variable has been resolved unambiguously. */ - private boolean fIsUnambiguous; - /** - * The proposal strings available for this variable. The first string is - * the default value. - */ - private String[] fValues; - - /** - * Creates a template variable. The type is used as the name of the - * variable. - * - * @param type the type of the variable - * @param defaultValue the default value of the variable - * @param offsets the array of offsets of the variable - */ - public TemplateVariable(String type, String defaultValue, int[] offsets) { - this(type, new String[] { defaultValue }, offsets); - } - - /** - * Creates a template variable. - * - * @param type the type of the variable - * @param name the name of the variable - * @param defaultValue the default value of the variable - * @param offsets the array of offsets of the variable - */ - public TemplateVariable(String type, String name, String defaultValue, int[] offsets) { - this(type, name, new String[] { defaultValue }, offsets); - } - - /** - * Creates a template variable with multiple possible values. The type is - * used as the name of the template. - * - * @param type the type of the template variable - * @param values the values available at this variable, non-empty - * @param offsets the array of offsets of the variable - */ - public TemplateVariable(String type, String[] values, int[] offsets) { - this(type, type, values, offsets); - } - - /** - * Creates a template variable with multiple possible values. - * - * @param type the type of the variable - * @param name the name of the variable - * @param values the values available at this variable, non-empty - * @param offsets the array of offsets of the variable - */ - public TemplateVariable(String type, String name, String[] values, int[] offsets) { - Assert.isNotNull(type); - Assert.isNotNull(name); - fType= type; - fName= name; - setValues(values); - setOffsets(offsets); - setUnambiguous(false); - } - - /** - * Returns the type of the variable. - * - * @return the type of the variable - */ - public String getType() { - return fType; - } - - /** - * Returns the name of the variable. - * - * @return the name of the variable - */ - public String getName() { - return fName; - } - - /** - * Returns the default value of the variable. - * - * @return the default value of the variable - */ - public String getDefaultValue() { - return getValues()[0]; - } - - /** - * Returns the possible values for this variable. The returned array is - * owned by this variable and must not be modified. - * - * @return the possible values for this variable - */ - public String[] getValues() { - return fValues; - } - - /** - * Returns the length of the variable. - * - * @return the length of the variable - */ - public int getLength() { - return getDefaultValue().length(); - } - - /** - * Sets the offsets of the variable. - * - * @param offsets the new offsets of the variable - */ - public void setOffsets(int[] offsets) { - fOffsets= offsets; - } - - /** - * Returns the offsets of the variable. - * - * @return the length of the variable - */ - public int[] getOffsets() { - return fOffsets; - } - - /** - * Sets the default value for this variable. This is a shortcut for - * <code>setValues(new String[] { value })</code>. - * - * @param value the new default value - */ - public final void setValue(String value) { - setValues(new String[] { value }); - } - - /** - * Sets the possible values for this variable, with the first being the - * default value. - * - * @param values a non-empty array of values - */ - public void setValues(String[] values) { - Assert.isTrue(values.length > 0); - fValues= values; - } - - /** - * Sets the isUnambiguous flag of the variable. - * - * @param unambiguous the new unambiguous state of the variable - */ - public void setUnambiguous(boolean unambiguous) { - fIsUnambiguous= unambiguous; - } - - /** - * Returns <code>true</code> if the variable is unambiguously resolved, <code>false</code> otherwise. - * - * @return <code>true</code> if the variable is unambiguously resolved, <code>false</code> otherwise - */ - public boolean isUnambiguous() { - return fIsUnambiguous; - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java deleted file mode 100644 index 1b12fa4f5f6..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import org.eclipse.jface.text.Assert; - -/** - * A <code>TemplateVariableResolver</code> resolves <code>TemplateVariables</code> - * of a certain type inside a <code>TemplateContext</code>. - * <p> - * Clients may instantiate and extend this class. - * </p> - * - * @see TemplateVariable - * @since 3.0 - */ -public class TemplateVariableResolver { - - /** Type of this resolver. */ - private String fType= null; - - /** Description of the type resolved by this resolver. */ - private String fDescription= null; - - /** - * Creates an instance of <code>TemplateVariableResolver</code>. - * - * @param type the name of the type - * @param description the description for the type - */ - protected TemplateVariableResolver(String type, String description) { - setType(type); - setDescription(description); - } - - /** - * Creates an empty instance. - * <p> - * This is a framework-only constructor that exists only so that resolvers - * can be contributed via an extension point and that should not be called - * in client code except for subclass constructors; use - * {@link #TemplateVariableResolver(String, String)} instead. - * </p> - */ - public TemplateVariableResolver() { - } - - /** - * Returns the type of this resolver. - * - * @return the type - */ - public String getType() { - return fType; - } - - /** - * Returns the description for the resolver. - * - * @return the description for the resolver - */ - public String getDescription() { - return fDescription; - } - - /** - * Returns an instance of the type resolved by the receiver available in <code>context</code>. - * To resolve means to provide a binding to a concrete text object (a - * <code>String</code>) in the given context. - * <p> - * The default implementation looks up the type in the context.</p> - * - * @param context the context in which to resolve the type - * @return the name of the text object of this type, or <code>null</code> if it cannot be determined - */ - protected String resolve(TemplateContext context) { - return context.getVariable(getType()); - } - - /** - * Returns all possible bindings available in <code>context</code>. The default - * implementation simply returns an array which contains the result of - * {@link #resolve(TemplateContext)}, or an empty array if that call returns - * <code>null</code>. - * - * @param context the context in which to resolve the type - * @return an array of possible bindings of this type in <code>context</code> - */ - protected String[] resolveAll(TemplateContext context) { - String binding= resolve(context); - if (binding == null) - return new String[0]; - else - return new String[] { binding }; - } - - /** - * Resolves <code>variable</code> in <code>context</code>. To resolve - * means to find a valid binding of the receiver's type in the given <code>TemplateContext</code>. - * If the variable can be successfully resolved, its value is set using - * {@link TemplateVariable#setValues(String[])}. - * - * @param context the context in which variable is resolved - * @param variable the variable to resolve - */ - public void resolve(TemplateVariable variable, TemplateContext context) { - String[] bindings= resolveAll(context); - if (bindings.length != 0) - variable.setValues(bindings); - if (bindings.length > 1) - variable.setUnambiguous(false); - else - variable.setUnambiguous(isUnambiguous(context)); - } - - /** - * Returns whether this resolver is able to resolve unambiguously. When - * resolving a <code>TemplateVariable</code>, its <code>isUmambiguous</code> - * state is set to the one of this resolver. By default, this method - * returns <code>false</code>. Clients can overwrite this method to give - * a hint about whether there should be e.g. prompting for input values for - * ambiguous variables. - * - * @param context the context in which the resolved check should be - * evaluated - * @return <code>true</code> if the receiver is unambiguously resolvable - * in <code>context</code>, <code>false</code> otherwise - */ - protected boolean isUnambiguous(TemplateContext context) { - return false; - } - - /** - * Sets the description. - * <p> - * This is a framework-only method that exists only so that resolvers - * can be contributed via an extension point and that should not be called - * in client code; use {@link #TemplateVariableResolver(String, String)} instead. - * </p> - * - * @param description the description of this resolver - */ - public final void setDescription(String description) { - Assert.isNotNull(description); - Assert.isTrue(fDescription == null); // may only be called once when initialized - fDescription= description; - } - - /** - * Sets the type. - * <p> - * This is a framework-only method that exists only so that resolvers - * can be contributed via an extension point and that should not be called - * in client code; use {@link #TemplateVariableResolver(String, String)} instead. - * </p> - * - * @param type the type of this resolver - */ - public final void setType(String type) { - Assert.isNotNull(type); - Assert.isTrue(fType == null); // may only be called once when initialized - fType= type; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java deleted file mode 100644 index c300969b5b8..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.templates; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * @since 3.0 - */ -class TextTemplateMessages { - - private static final String RESOURCE_BUNDLE= TextTemplateMessages.class.getName(); - private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); - - private TextTemplateMessages() { - } - - /** - * @param key - * @return - */ - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - /** - * Gets a string from the resource bundle and formats it with the argument - * - * @param key the string used to get the bundle value, must not be null - * @param arg - * @return - */ - public static String getFormattedString(String key, Object arg) { - return MessageFormat.format(getString(key), new Object[] { arg }); - } - - - /** - * Gets a string from the resource bundle and formats it with arguments - * @param key - * @param args - * @return - */ - public static String getFormattedString(String key, Object[] args) { - return MessageFormat.format(getString(key), args); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties deleted file mode 100644 index cf0e49e19d5..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties +++ /dev/null @@ -1,24 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -# template translator -TemplateTranslator.error.incomplete.variable=Template has incomplete variables. Use '$$' to insert the dollar symbol. -TemplateTranslator.error.invalid.identifier=Template has invalid variable identifiers. - -# global variables -GlobalVariables.variable.description.cursor=The cursor position after editing template variables -GlobalVariables.variable.description.dollar=The dollar symbol -GlobalVariables.variable.description.date=Current date -GlobalVariables.variable.description.year=Current year -GlobalVariables.variable.description.time=Current time -GlobalVariables.variable.description.user=User name -GlobalVariables.variable.description.selectedWord= The selected word -GlobalVariables.variable.description.selectedLines= The selected lines diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/package.html b/org.eclipse.text/src/org/eclipse/jface/text/templates/package.html deleted file mode 100644 index e70145a0f58..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/package.html +++ /dev/null @@ -1,113 +0,0 @@ -<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta content="text/html; charset=iso-8859-1" - http-equiv="Content-Type"> - <meta content="IBM" name="Author"> - <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]" - name="GENERATOR"> - <title>Templates</title> - <meta content="Template Infrastructure package description" - name="description"> -</head> -<body> -Application programming interfaces for interaction -with the Eclipse Java User Interface text support. -<h2>Templates<br> -</h2> -<h3>packages</h3> -<ul> - <li style="font-weight: bold;"><big><span - style="font-family: monospace;">org.eclipse.jface.text.templates</span></big></li> - <li style="font-weight: bold;"><big><span - style="font-family: monospace;">org.eclipse.ui.workbench.texteditor.templates</span><br> - <span style="font-family: monospace;"></span></big></li> - <li><big><span style="font-family: monospace; font-weight: bold;">org.eclipse.ui.editors.templates</span></big><br> - <span style="font-family: monospace;"></span></li> -</ul> -<h3><code></code></h3> -Templates are shortcuts for frequently used fragments of text such as -code patterns or complex text entities. They may contain variables -which are only resolved at the time when the template is inserted -within a context. Together with linked mode, inserting a template can -create a on-the-fly edit mask within a text viewer.<br> -<br> -Templates are specified as text, variables are defined using the <span - style="font-family: monospace;">${variable}</span> notation known from -Ant, for example. The following snippet shows an example template for -an instance check in Java:<br> -<pre>if (${name} instanceof ${type}) {<br> ${type} ${new_name} = (${type})${name};<br> ${cursor}<br>}<br></pre> -In this template, the variables (<span style="font-family: monospace;">name, -type, ...</span><span style="font-family: sans-serif;">) are resolved -when inserted into java source and changing one variable instance will -also change the other. When leaving linked mode, the caret is placed at -the </span><span style="font-family: monospace;">cursor</span><span - style="font-family: sans-serif;"> variable.<br> -<br> -Template functionality can be added to a custom text editor by offering -</span><span style="font-family: monospace;">TemplateProposal</span><span - style="font-family: sans-serif;">s as content assist choices, which is -simplified by using a </span><span style="font-family: sans-serif;"><span - style="font-family: sans-serif;">subclass of </span></span><span - style="font-family: monospace;">TemplateCompletionProcessor</span><span - style="font-family: sans-serif;">. User template management can be -offered by including a </span><span style="font-family: monospace;">TemplatePreferencePage</span><span - style="font-family: sans-serif;"> which uses a </span><span - style="font-family: monospace;">TemplateStore</span><span - style="font-family: sans-serif;"> and <span - style="font-family: monospace;">ContextTypeRegistry</span> as the -underlying model to store templates. The <span - style="font-family: monospace;">org.eclipse.ui.editors.templates</span> -extension point can be used to allow other plug-ins to contribute -templates to an editor. This is accomplished by using the <span - style="font-family: monospace;">ContributionTemplateStore</span> and <span - style="font-family: monospace;">ContributionContextTypeRegistry</span> -subclasses of the above types.<br> -<br> -Template variables are resolved by a <span - style="font-family: monospace;">TemplateVariableResolver.</span> <span - style="font-family: monospace;">GlobalTemplateVariables</span> offers -some default variables such as date, user, and selection, but advanced -features such as resolving to language constructs can be performed in -subclasses.<br> -</span> -<h4>Classes</h4> -<ul> - <li><span style="font-family: monospace;">Template</span><span - style="font-family: sans-serif;"> a template consists of name, context -type identifier, and a pattern.</span></li> - <li><span style="font-family: sans-serif;"><span - style="font-family: monospace;">TemplateTranslator</span> and <span - style="font-family: monospace;">TemplateBuffer</span> are used to -parse the template grammar and don't need to be used usually.</span></li> - <li><span style="font-family: sans-serif;">A <span - style="font-family: monospace;">TemplateProposal </span>can be -offered in content assist, possibly created by a subclass of <span - style="font-family: monospace;">TemplateCompletionProcessor.</span></span></li> - <li><span style="font-family: sans-serif;"><span - style="font-family: monospace;">TemplateStore</span> and <span - style="font-family: monospace;">ContextTypeRegistry</span> manage a -set of templates within a plug-in and offer ways to store them in the -preferences or externally in XML streams via a <span - style="font-family: monospace;">TemplateReaderWriter</span>.<br> - </span></li> - <li><span style="font-family: sans-serif;"><span - style="font-family: monospace;">ContributionTemplateStore</span> and <span - style="font-family: monospace;">ContributionContextTypeRegistry</span> -add awareness for the </span><span style="font-family: sans-serif;"><span - style="font-family: sans-serif;"> <span - style="font-family: monospace;">org.eclipse.ui.editors.templates</span> -extension point.</span></span></li> - <li style="font-family: monospace;"><span - style="font-family: sans-serif;"><span style="font-family: sans-serif;"><span - style="font-family: monospace;">TemplatePreferencePage</span> allows -the user to access the templates within a <span - style="font-family: monospace;">TemplateStore</span>.</span></span></li> -</ul> -<ul> -</ul> -<h4>Example</h4> -<pre><span style="font-family: sans-serif;">See the Template Editor Example in the <span - style="font-weight: bold;">org.eclipse.ui.examples.javaeditor</span> project.<br></span></pre> -</body> -</html> diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java deleted file mode 100644 index fcd83ac3117..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java +++ /dev/null @@ -1,309 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A copy source edit denotes the source of a copy operation. Copy - * source edits are only valid inside an edit tree if they have a - * corresponding traget edit. Furthermore the corresponding - * target edit can't be a direct or indirect child of the source - * edit. Violating one of two requirements will result in a <code> - * MalformedTreeException</code> when executing the edit tree. - * <p> - * A copy source edit can manange an optional source modifier. A - * source modifier can provide a set of replace edits which will - * to applied to the source before it gets inserted at the target - * position. - * - * @see org.eclipse.text.edits.CopyTargetEdit - * - * @since 3.0 - */ -public final class CopySourceEdit extends TextEdit { - - private CopyTargetEdit fTarget; - private ISourceModifier fModifier; - - private String fSourceContent; - private TextEdit fSourceRoot; - - private static class PartialCopier extends TextEditVisitor { - TextEdit fResult; - List fParents= new ArrayList(); - TextEdit fCurrentParent; - - public static TextEdit perform(TextEdit source) { - PartialCopier copier= new PartialCopier(); - source.accept(copier); - return copier.fResult; - } - private void manageCopy(TextEdit copy) { - if (fResult == null) - fResult= copy; - if (fCurrentParent != null) { - fCurrentParent.addChild(copy); - } - fParents.add(fCurrentParent); - fCurrentParent= copy; - } - public void postVisit(TextEdit edit) { - fCurrentParent= (TextEdit)fParents.remove(fParents.size() - 1); - } - public boolean visitNode(TextEdit edit) { - manageCopy(edit.doCopy()); - return true; - } - public boolean visit(CopySourceEdit edit) { - manageCopy(new RangeMarker(edit.getOffset(), edit.getLength())); - return true; - } - public boolean visit(CopyTargetEdit edit) { - manageCopy(new InsertEdit(edit.getOffset(), edit.getSourceEdit().getContent())); - return true; - } - public boolean visit(MoveSourceEdit edit) { - manageCopy(new DeleteEdit(edit.getOffset(), edit.getLength())); - return true; - } - public boolean visit(MoveTargetEdit edit) { - manageCopy(new InsertEdit(edit.getOffset(), edit.getSourceEdit().getContent())); - return true; - } - } - - /** - * Constructs a new copy source edit. - * - * @param offset the edit's offset - * @param length the edit's length - */ - public CopySourceEdit(int offset, int length) { - super(offset, length); - } - - /** - * Constructs a new copy source edit. - * - * @param offset the edit's offset - * @param length the edit's length - * @param target the edit's target - */ - public CopySourceEdit(int offset, int length, CopyTargetEdit target) { - this(offset, length); - setTargetEdit(target); - } - - /* - * Copy Constructor - */ - private CopySourceEdit(CopySourceEdit other) { - super(other); - if (other.fModifier != null) - fModifier= other.fModifier.copy(); - } - - /** - * Returns the associated traget edit or <code>null</code> - * if no target edit is associated yet. - * - * @return the target edit or <code>null</code> - */ - public CopyTargetEdit getTargetEdit() { - return fTarget; - } - - /** - * Sets the target edit. - * - * @param edit the new target edit. - * - * @exception MalformedTreeException is thrown if the target edit - * is a direct or indirect child of the source edit - */ - public void setTargetEdit(CopyTargetEdit edit) throws MalformedTreeException { - Assert.isNotNull(edit); - if (fTarget != edit) { - fTarget= edit; - fTarget.setSourceEdit(this); - } - } - - /** - * Returns the current source modifier or <code>null</code> - * if no source modifier is set. - * - * @return the source modifier - */ - public ISourceModifier getSourceModifier() { - return fModifier; - } - - /** - * Sets the optional source modifier. - * - * @param modifier the source modifier or <code>null</code> - * if no source modification is need. - */ - public void setSourceModifier(ISourceModifier modifier) { - fModifier= modifier; - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new CopySourceEdit(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - //---- API for CopyTargetEdit ------------------------------------------------ - - /* package */ String getContent() { - // The source content can be null if the edit wasn't executed - // due to an exclusion list of the text edit processor. Return - // the empty string which can be moved without any harm. - if (fSourceContent == null) - return ""; //$NON-NLS-1$ - return fSourceContent; - } - - /* package */ void clearContent() { - fSourceContent= null; - } - - /* non Java-doc - * @see TextEdit#postProcessCopy - */ - protected void postProcessCopy(TextEditCopier copier) { - if (fTarget != null) { - CopySourceEdit source= (CopySourceEdit)copier.getCopy(this); - CopyTargetEdit target= (CopyTargetEdit)copier.getCopy(fTarget); - if (source != null && target != null) - source.setTargetEdit(target); - } - } - - //---- consistency check ---------------------------------------------------- - - /* package */ int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { - int result= super.traverseConsistencyCheck(processor, document, sourceEdits); - // Since source computation takes place in a recursive fashion (see - // performSourceComputation) we only do something if we don't have a - // computated source already. - if (fSourceContent == null) { - if (sourceEdits.size() <= result) { - List list= new ArrayList(); - list.add(this); - for (int i= sourceEdits.size(); i < result; i++) - sourceEdits.add(null); - sourceEdits.add(list); - } else { - List list= (List)sourceEdits.get(result); - if (list == null) { - list= new ArrayList(); - sourceEdits.add(result, list); - } - list.add(this); - } - } - return result; - } - - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { - if (fTarget == null) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.no_target")); //$NON-NLS-1$ - if (fTarget.getSourceEdit() != this) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.different_source")); //$NON-NLS-1$ - } - - //---- source computation ------------------------------------------------------- - - /* package */ void traverseSourceComputation(TextEditProcessor processor, IDocument document) { - if (processor.considerEdit(this)) { - performSourceComputation(processor, document); - } - } - - /* package */ void performSourceComputation(TextEditProcessor processor, IDocument document) { - try { - MultiTextEdit root= new MultiTextEdit(getOffset(), getLength()); - root.internalSetChildren(internalGetChildren()); - fSourceContent= document.get(getOffset(), getLength()); - fSourceRoot= PartialCopier.perform(root); - fSourceRoot.moveTree(-getOffset()); - if (fSourceRoot.hasChildren()) { - EditDocument subDocument= new EditDocument(fSourceContent); - fSourceRoot.apply(subDocument, TextEdit.NONE); - if (needsTransformation()) - applyTransformation(subDocument); - fSourceContent= subDocument.get(); - fSourceRoot= null; - } else { - if (needsTransformation()) { - EditDocument subDocument= new EditDocument(fSourceContent); - applyTransformation(subDocument); - fSourceContent= subDocument.get(); - } - } - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false); - } - } - - private boolean needsTransformation() { - return fModifier != null; - } - - private void applyTransformation(IDocument document) throws MalformedTreeException { - TextEdit newEdit= new MultiTextEdit(0, document.getLength()); - ReplaceEdit[] replaces= fModifier.getModifications(document.get()); - for (int i= 0; i < replaces.length; i++) { - newEdit.addChild(replaces[i]); - } - try { - newEdit.apply(document, TextEdit.NONE); - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false); - } - } - - //---- document updating ---------------------------------------------------------------- - - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - fDelta= 0; - return fDelta; - } - - //---- region updating ---------------------------------------------------------------- - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java deleted file mode 100644 index 1ad57de5cdd..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A copy target edit denotes the target of a copy operation. Copy - * target edits are only valid inside an edit tree if they have a - * corresponding source edit. Furthermore a target edit can't - * can't be a direct or indirect child of the associated source edit. - * Violating one of two requirements will result in a <code> - * MalformedTreeException</code> when executing the edit tree. - * <p> - * Copy target edits can't be used as a parent for other edits. - * Trying to add an edit to a copy target edit results in a <code> - * MalformedTreeException</code> as well. - * - * @see org.eclipse.text.edits.CopySourceEdit - * - * @since 3.0 - */ -public final class CopyTargetEdit extends TextEdit { - - private CopySourceEdit fSource; - - /** - * Constructs a new copy target edit - * - * @param offset the edit's offset - */ - public CopyTargetEdit(int offset) { - super(offset, 0); - } - - /** - * Constructs an new copy target edit - * - * @param offset the edit's offset - * @param source the corresponding source edit - */ - public CopyTargetEdit(int offset, CopySourceEdit source) { - this(offset); - setSourceEdit(source); - } - - /* - * Copy constructor - */ - private CopyTargetEdit(CopyTargetEdit other) { - super(other); - } - - /** - * Returns the associated source edit or <code>null</code> - * if no source edit is associated yet. - * - * @return the source edit or <code>null</code> - */ - public CopySourceEdit getSourceEdit() { - return fSource; - } - - /** - * Sets the source edit. - * - * @param edit the source edit - * - * @exception MalformedTreeException is thrown if the target edit - * is a direct or indirect child of the source edit - */ - public void setSourceEdit(CopySourceEdit edit) throws MalformedTreeException { - Assert.isNotNull(edit); - if (fSource != edit) { - fSource= edit; - fSource.setTargetEdit(this); - TextEdit parent= getParent(); - while (parent != null) { - if (parent == fSource) - throw new MalformedTreeException(parent, this, TextEditMessages.getString("CopyTargetEdit.wrong_parent")); //$NON-NLS-1$ - parent= parent.getParent(); - } - } - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new CopyTargetEdit(this); - } - - /* non Java-doc - * @see TextEdit#postProcessCopy - */ - protected void postProcessCopy(TextEditCopier copier) { - if (fSource != null) { - CopyTargetEdit target= (CopyTargetEdit)copier.getCopy(this); - CopySourceEdit source= (CopySourceEdit)copier.getCopy(fSource); - if (target != null && source != null) - target.setSourceEdit(source); - } - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#traverseConsistencyCheck - */ - /* package */ int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { - return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; - } - - /* non Java-doc - * @see TextEdit#performConsistencyCheck - */ - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { - if (fSource == null) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.no_source")); //$NON-NLS-1$ - if (fSource.getTargetEdit() != this) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.different_target")); //$NON-NLS-1$ - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - String source= fSource.getContent(); - document.replace(getOffset(), getLength(), source); - fDelta= source.length() - getLength(); - fSource.clearContent(); - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopyingRangeMarker.java b/org.eclipse.text/src/org/eclipse/text/edits/CopyingRangeMarker.java deleted file mode 100644 index 04b8f7d7044..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/CopyingRangeMarker.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A <code>CopyingRangeMarker</code> can be used to track positions when executing - * text edits. Additionally a copying range marker stores a local copy of the - * text it captures when it gets executed. - * - * @since 3.0 - */ -public final class CopyingRangeMarker extends TextEdit { - - private String fText; - - /** - * Creates a new <tt>CopyRangeMarker</tt> for the given - * offset and length. - * - * @param offset the marker's offset - * @param length the marker's length - */ - public CopyingRangeMarker(int offset, int length) { - super(offset, length); - } - - /* - * Copy constructor - */ - private CopyingRangeMarker(CopyingRangeMarker other) { - super(other); - fText= other.fText; - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new CopyingRangeMarker(this); - } - - /* - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - fText= document.get(getOffset(), getLength()); - fDelta= 0; - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/DeleteEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/DeleteEdit.java deleted file mode 100644 index f53b6b6dc24..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/DeleteEdit.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * Text edit to delete a range in a document. - * <p> - * A delete edit is equivalent to <code>ReplaceEdit( - * offset, length, "")</code>. - * - * @since 3.0 - */ -public final class DeleteEdit extends TextEdit { - - /** - * Constructs a new delete edit. - * - * @param offset the offset of the range to replace - * @param length the length of the range to replace - */ - public DeleteEdit(int offset, int length) { - super(offset, length); - } - - /* - * Copy constructor - */ - private DeleteEdit(DeleteEdit other) { - super(other); - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new DeleteEdit(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - document.replace(getOffset(), getLength(), ""); //$NON-NLS-1$ - fDelta= -getLength(); - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return true; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/EditDocument.java b/org.eclipse.text/src/org/eclipse/text/edits/EditDocument.java deleted file mode 100644 index e0cced15a9d..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/EditDocument.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.BadPositionCategoryException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.IDocumentPartitioningListener; -import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Position; - -/* package */ class EditDocument implements IDocument { - - private StringBuffer fBuffer; - - public EditDocument(String content) { - fBuffer= new StringBuffer(content); - } - - public void addDocumentListener(IDocumentListener listener) { - throw new UnsupportedOperationException(); - } - - public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) { - throw new UnsupportedOperationException(); - } - - public void addPosition(Position position) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { - throw new UnsupportedOperationException(); - } - - public void addPositionCategory(String category) { - throw new UnsupportedOperationException(); - } - - public void addPositionUpdater(IPositionUpdater updater) { - throw new UnsupportedOperationException(); - } - - public void addPrenotifiedDocumentListener(IDocumentListener documentAdapter) { - throw new UnsupportedOperationException(); - } - - public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException { - throw new UnsupportedOperationException(); - } - - public int computeNumberOfLines(String text) { - throw new UnsupportedOperationException(); - } - - public ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public boolean containsPosition(String category, int offset, int length) { - throw new UnsupportedOperationException(); - } - - public boolean containsPositionCategory(String category) { - throw new UnsupportedOperationException(); - } - - public String get() { - return fBuffer.toString(); - } - - public String get(int offset, int length) throws BadLocationException { - char[] result= new char[length]; - fBuffer.getChars(offset, offset + length, result, 0); - return new String(result); - } - - public char getChar(int offset) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public String getContentType(int offset) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public IDocumentPartitioner getDocumentPartitioner() { - throw new UnsupportedOperationException(); - } - - public String[] getLegalContentTypes() { - throw new UnsupportedOperationException(); - } - - public String[] getLegalLineDelimiters() { - throw new UnsupportedOperationException(); - } - - public int getLength() { - return fBuffer.length(); - } - - public String getLineDelimiter(int line) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public IRegion getLineInformation(int line) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public IRegion getLineInformationOfOffset(int offset) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public int getLineLength(int line) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public int getLineOffset(int line) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public int getLineOfOffset(int offset) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public int getNumberOfLines() { - throw new UnsupportedOperationException(); - } - - public int getNumberOfLines(int offset, int length) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public ITypedRegion getPartition(int offset) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public String[] getPositionCategories() { - throw new UnsupportedOperationException(); - } - - public Position[] getPositions(String category) throws BadPositionCategoryException { - throw new UnsupportedOperationException(); - } - - public IPositionUpdater[] getPositionUpdaters() { - throw new UnsupportedOperationException(); - } - - public void insertPositionUpdater(IPositionUpdater updater, int index) { - throw new UnsupportedOperationException(); - } - - public void removeDocumentListener(IDocumentListener listener) { - throw new UnsupportedOperationException(); - } - - public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) { - throw new UnsupportedOperationException(); - } - - public void removePosition(Position position) { - throw new UnsupportedOperationException(); - } - - public void removePosition(String category, Position position) throws BadPositionCategoryException { - throw new UnsupportedOperationException(); - } - - public void removePositionCategory(String category) throws BadPositionCategoryException { - throw new UnsupportedOperationException(); - } - - public void removePositionUpdater(IPositionUpdater updater) { - throw new UnsupportedOperationException(); - } - - public void removePrenotifiedDocumentListener(IDocumentListener documentAdapter) { - throw new UnsupportedOperationException(); - } - - public void replace(int offset, int length, String text) throws BadLocationException { - fBuffer.replace(offset, offset + length, text); - } - - public int search(int startOffset, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException { - throw new UnsupportedOperationException(); - } - - public void set(String text) { - throw new UnsupportedOperationException(); - } - - public void setDocumentPartitioner(IDocumentPartitioner partitioner) { - throw new UnsupportedOperationException(); - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/ISourceModifier.java b/org.eclipse.text/src/org/eclipse/text/edits/ISourceModifier.java deleted file mode 100644 index 87cbf6cdd06..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/ISourceModifier.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -/** - * A source modifier can be used to modify the source of - * a move or copy edit before it gets inserted at the target - * position. This is useful if the text to be copied has to - * be modified before it is inserted without changing the - * original source. - * - * @since 3.0 - */ -public interface ISourceModifier { - /** - * Returns the modification to be done to the passed - * string in form of replace edits. The set of returned - * replace edits must modify disjoint text regions. - * Violating this requirement will result in a <code> - * BadLocationException</code> while executing the - * associated move or copy edit. - * <p> - * The caller of this method is responsible to apply - * the returned edits to the passed source. - * - * @param source the source to be copied or moved - * @return an array of <code>ReplaceEdits</code> - * describing the modifications. - */ - public ReplaceEdit[] getModifications(String source); - - /** - * Creates a copy of this source modifier object. The copy will - * be used in a different text edit object. So it should be - * created in a way that is doesn't conflict with other text edits - * refering to this source modifier. - * - * @return the copy of the source modifier - */ - public ISourceModifier copy(); -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/InsertEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/InsertEdit.java deleted file mode 100644 index d3d808e4ef2..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/InsertEdit.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * Text edit to insert a text at a given position in a - * document. - * <p> - * An insert edit is equivalent to <code>ReplaceEdit(offset, 0, text) - * </code> - * - * @since 3.0 - */ -public final class InsertEdit extends TextEdit { - - private String fText; - - /** - * Constructs a new insert edit. - * - * @param offset the insertion offset - * @param text the text to insert - */ - public InsertEdit(int offset, String text) { - super(offset, 0); - fText= text; - } - - /* - * Copy constructor - */ - private InsertEdit(InsertEdit other) { - super(other); - fText= other.fText; - } - - /** - * Returns the text to be inserted. - * - * @return the edit's text. - */ - public String getText() { - return fText; - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new InsertEdit(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - document.replace(getOffset(), getLength(), fText); - fDelta= fText.length() - getLength(); - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } - - /* non Java-doc - * @see java.lang.Object#toString() - */ - public String toString() { - return super.toString() + " <<" + fText; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MalformedTreeException.java b/org.eclipse.text/src/org/eclipse/text/edits/MalformedTreeException.java deleted file mode 100644 index f2b343615e4..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/MalformedTreeException.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -/** - * Thrown to indicate that an edit got added to a parent edit - * but the child edit somehow conflicts with the parent or - * one of it siblings. - * - * @see TextEdit#addChild(TextEdit) - * @see TextEdit#addChildren(TextEdit[]) - * - * @since 3.0 - */ -public class MalformedTreeException extends RuntimeException { - - private TextEdit fParent; - private TextEdit fChild; - - /** - * Constructs a new malformed tree exception. - * - * @param parent the parent edit - * @param child the child edit - * @param message the detail message - */ - public MalformedTreeException(TextEdit parent, TextEdit child, String message) { - super(message); - fParent= parent; - fChild= child; - } - - /** - * Returns the parent edit that caused the exception. - * - * @return the parent edit - */ - public TextEdit getParent() { - return fParent; - } - - /** - * Returns the child edit that caused the exception. - * - * @return the child edit - */ - public TextEdit getChild() { - return fChild; - } - - /* package */ void setParent(TextEdit parent) { - fParent= parent; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/Messages.properties b/org.eclipse.text/src/org/eclipse/text/edits/Messages.properties deleted file mode 100644 index 4e0918c6676..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/Messages.properties +++ /dev/null @@ -1,33 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -TextEdit.range_outside= Range of child edit lies outside of parent edit -TextEdit.overlapping= Overlapping text edits -TextEdit.deleted_edit= Cannot add deleted edit - -CopySourceEdit.no_target= No target edit provided. -CopySourceEdit.different_source= Target edit has different source edit. - -CopyTargetEdit.no_source= No source edit provided. -CopyTargetEdit.different_target= Source edit has different target edit. -CopyTargetEdit.wrong_parent=Source edit must not be the parent of the target. - -MoveSourceEdit.no_target= No target edit provided. -MoveSourceEdit.different_source= Target edit has different source edit. - -MoveTargetEdit.no_source= No source edit provided. -MoveTargetEdit.different_target= Source edit has different target edit. -MoveTargetEdit.wrong_parent=Source edit must not be the parent of the target. - -TextEditProcessor.invalid_length=End position lies outside document range - -UndoEdit.no_children=Cannot add children to an undo edit -UndoEdit.can_not_be_added=Cannot add an undo edit to another edit diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java deleted file mode 100644 index a7241e619cf..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; - -/** - * A move source edit denotes the source of a move operation. Move - * source edits are only valid inside an edit tree if they have a - * corresponding traget edit. Furthermore the corresponding target - * edit can't be a direct or indirect child of the source edit. - * Violating one of two requirements will result in a <code> - * MalformedTreeException</code> when executing the edit tree. - * <p> - * A move source edit can manange an optional source modifier. A - * source modifier can provide a set of replace edits which will - * to applied to the source before it gets inserted at the target - * position. - * - * @see org.eclipse.text.edits.MoveTargetEdit - * @see org.eclipse.text.edits.CopySourceEdit - * - * @since 3.0 - */ -public final class MoveSourceEdit extends TextEdit { - - private MoveTargetEdit fTarget; - private ISourceModifier fModifier; - - private String fSourceContent; - private MultiTextEdit fSourceRoot; - - /** - * Constructs a new move source edit. - * - * @param offset the edit's offset - * @param length the edit's length - */ - public MoveSourceEdit(int offset, int length) { - super(offset, length); - } - - /** - * Constructs a new copy source edit. - * - * @param offset the edit's offset - * @param length the edit's length - * @param target the edit's target - */ - public MoveSourceEdit(int offset, int length, MoveTargetEdit target) { - this(offset, length); - setTargetEdit(target); - } - - /* - * Copy constructor - */ - private MoveSourceEdit(MoveSourceEdit other) { - super(other); - if (other.fModifier != null) - fModifier= other.fModifier.copy(); - } - - /** - * Returns the associated traget edit or <code>null</code> - * if no target edit is associated yet. - * - * @return the target edit or <code>null</code> - */ - public MoveTargetEdit getTargetEdit() { - return fTarget; - } - - /** - * Sets the target edit. - * - * @param edit the new target edit. - * - * @exception MalformedTreeException is thrown if the target edit - * is a direct or indirect child of the source edit - */ - public void setTargetEdit(MoveTargetEdit edit) { - fTarget= edit; - fTarget.setSourceEdit(this); - } - - /** - * Returns the current source modifier or <code>null</code> - * if no source modifier is set. - * - * @return the source modifier - */ - public ISourceModifier getSourceModifier() { - return fModifier; - } - - /** - * Sets the optional source modifier. - * - * @param modifier the source modifier or <code>null</code> - * if no source modification is need. - */ - public void setSourceModifier(ISourceModifier modifier) { - fModifier= modifier; - } - - //---- API for MoveTargetEdit --------------------------------------------- - - /* package */ String getContent() { - // The source content can be null if the edit wasn't executed - // due to an exclusion list of the text edit processor. Return - // the empty string which can be moved without any harm. - if (fSourceContent == null) - return ""; //$NON-NLS-1$ - return fSourceContent; - } - - /* package */ MultiTextEdit getRoot() { - return fSourceRoot; - } - - /* package */ void clearContent() { - fSourceContent= null; - fSourceRoot= null; - } - - //---- Copying ------------------------------------------------------------- - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new MoveSourceEdit(this); - } - - /* non Java-doc - * @see TextEdit#postProcessCopy - */ - protected void postProcessCopy(TextEditCopier copier) { - if (fTarget != null) { - MoveSourceEdit source= (MoveSourceEdit)copier.getCopy(this); - MoveTargetEdit target= (MoveTargetEdit)copier.getCopy(fTarget); - if (source != null && target != null) - source.setTargetEdit(target); - } - } - - //---- Visitor ------------------------------------------------------------- - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - //---- consistency check ---------------------------------------------------------------- - - /* package */ int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { - int result= super.traverseConsistencyCheck(processor, document, sourceEdits); - // Since source computation takes place in a recursive fashion (see - // performSourceComputation) we only do something if we don't have a - // computated source already. - if (fSourceContent == null) { - if (sourceEdits.size() <= result) { - List list= new ArrayList(); - list.add(this); - for (int i= sourceEdits.size(); i < result; i++) - sourceEdits.add(null); - sourceEdits.add(list); - } else { - List list= (List)sourceEdits.get(result); - if (list == null) { - list= new ArrayList(); - sourceEdits.add(result, list); - } - list.add(this); - } - } - return result; - } - - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { - if (fTarget == null) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.no_target")); //$NON-NLS-1$ - if (fTarget.getSourceEdit() != this) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.different_source")); //$NON-NLS-1$ - } - - //---- source computation -------------------------------------------------------------- - - /* package */ void traverseSourceComputation(TextEditProcessor processor, IDocument document) { - if (processor.considerEdit(this)) { - performSourceComputation(processor, document); - } - } - - /* package */ void performSourceComputation(TextEditProcessor processor, IDocument document) { - try { - TextEdit[] children= removeChildren(); - if (children.length > 0) { - String content= document.get(getOffset(), getLength()); - EditDocument subDocument= new EditDocument(content); - fSourceRoot= new MultiTextEdit(getOffset(), getLength()); - fSourceRoot.addChildren(children); - fSourceRoot.moveTree(-getOffset()); - int processingStyle= getStyle(processor); - fSourceRoot.apply(subDocument, processingStyle); - if (needsTransformation()) - applyTransformation(subDocument, processingStyle); - fSourceContent= subDocument.get(); - } else { - fSourceContent= document.get(getOffset(), getLength()); - if (needsTransformation()) { - EditDocument subDocument= new EditDocument(fSourceContent); - applyTransformation(subDocument, getStyle(processor)); - fSourceContent= subDocument.get(); - } - } - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false); - } - } - - private int getStyle(TextEditProcessor processor) { - // we never need undo while performing local edits. - if ((processor.getStyle() & TextEdit.UPDATE_REGIONS) != 0) - return TextEdit.UPDATE_REGIONS; - return TextEdit.NONE; - } - - //---- document updating ---------------------------------------------------------------- - - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - document.replace(getOffset(), getLength(), ""); //$NON-NLS-1$ - fDelta= -getLength(); - return fDelta; - } - - //---- region updating -------------------------------------------------------------- - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } - - //---- content transformation -------------------------------------------------- - - private boolean needsTransformation() { - return fModifier != null; - } - - private void applyTransformation(IDocument document, int style) throws MalformedTreeException { - if ((style & TextEdit.UPDATE_REGIONS) != 0 && fSourceRoot != null) { - Map editMap= new HashMap(); - TextEdit newEdit= createEdit(editMap); - List replaces= new ArrayList(Arrays.asList(fModifier.getModifications(document.get()))); - insertEdits(newEdit, replaces); - try { - newEdit.apply(document, style); - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false); - } - restorePositions(editMap); - } else { - MultiTextEdit newEdit= new MultiTextEdit(0, document.getLength()); - TextEdit[] replaces= fModifier.getModifications(document.get()); - for (int i= 0; i < replaces.length; i++) { - newEdit.addChild(replaces[i]); - } - try { - newEdit.apply(document, style); - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false); - } - } - } - - private TextEdit createEdit(Map editMap) { - MultiTextEdit result= new MultiTextEdit(0, fSourceRoot.getLength()); - editMap.put(result, fSourceRoot); - createEdit(fSourceRoot, result, editMap); - return result; - } - - private static void createEdit(TextEdit source, TextEdit target, Map editMap) { - TextEdit[] children= source.getChildren(); - for (int i= 0; i < children.length; i++) { - TextEdit child= children[i]; - // a deleted child remains deleted even if the temporary buffer - // gets modified. - if (child.isDeleted()) - continue; - RangeMarker marker= new RangeMarker(child.getOffset(), child.getLength()); - target.addChild(marker); - editMap.put(marker, child); - createEdit(child, marker, editMap); - } - } - - private void insertEdits(TextEdit root, List edits) { - while(edits.size() > 0) { - ReplaceEdit edit= (ReplaceEdit)edits.remove(0); - insert(root, edit, edits); - } - } - private static void insert(TextEdit parent, ReplaceEdit edit, List edits) { - if (!parent.hasChildren()) { - parent.addChild(edit); - return; - } - TextEdit[] children= parent.getChildren(); - // First dive down to find the right parent. - for (int i= 0; i < children.length; i++) { - TextEdit child= children[i]; - if (child.covers(edit)) { - insert(child, edit, edits); - return; - } else if (edit.covers(child)) { - parent.removeChild(i); - edit.addChild(child); - } else { - IRegion intersect= intersect(edit, child); - if (intersect != null) { - ReplaceEdit[] splits= splitEdit(edit, intersect); - insert(child, splits[0], edits); - edits.add(splits[1]); - } - } - } - parent.addChild(edit); - } - - public static IRegion intersect(TextEdit op1, TextEdit op2) { - int offset1= op1.getOffset(); - int length1= op1.getLength(); - int end1= offset1 + length1 - 1; - int offset2= op2.getOffset(); - if (end1 < offset2) - return null; - int length2= op2.getLength(); - int end2= offset2 + length2 - 1; - if (end2 < offset1) - return null; - if (offset1 < offset2) { - int end= Math.max(end1, end2); - return new Region(offset2, end - offset2 + 1); - } else { - int end= Math.max(end1, end2); - return new Region(offset1, end - offset1 + 1); - } - } - - private static ReplaceEdit[] splitEdit(ReplaceEdit edit, IRegion intersect) { - if (edit.getOffset() != intersect.getOffset()) { - return splitIntersectRight(edit, intersect); - } else { - return splitIntersectLeft(edit, intersect); - } - } - - private static ReplaceEdit[] splitIntersectRight(ReplaceEdit edit, IRegion intersect) { - ReplaceEdit[] result= new ReplaceEdit[2]; - // this is the actual delete. We use replace to only deal with one type - result[0]= new ReplaceEdit(intersect.getOffset(), intersect.getLength(), ""); //$NON-NLS-1$ - result[1]= new ReplaceEdit( - edit.getOffset(), - intersect.getOffset() - edit.getOffset(), - edit.getText()); - return result; - } - - private static ReplaceEdit[] splitIntersectLeft(ReplaceEdit edit, IRegion intersect) { - ReplaceEdit[] result= new ReplaceEdit[2]; - result[0]= new ReplaceEdit(intersect.getOffset(), intersect.getLength(), edit.getText()); - result[1]= new ReplaceEdit( // this is the actual delete. We use replace to only deal with one type - intersect.getOffset() + intersect.getLength(), - edit.getLength() - intersect.getLength(), - ""); //$NON-NLS-1$ - return result; - } - - private static void restorePositions(Map editMap) { - for (Iterator iter= editMap.keySet().iterator(); iter.hasNext();) { - TextEdit marker= (TextEdit)iter.next(); - TextEdit edit= (TextEdit)editMap.get(marker); - if (marker.isDeleted()) { - edit.markAsDeleted(); - } else { - edit.adjustOffset(marker.getOffset() - edit.getOffset()); - edit.adjustLength(marker.getLength() - edit.getLength()); - } - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java deleted file mode 100644 index f8fa6fe6ab3..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A move target edit denotes the target of a move operation. Move - * target edits are only valid inside an edit tree if they have a - * corresponding source edit. Furthermore a target edit can't - * can't be a direct or indirect child of its associated source edit. - * Violating one of two requirements will result in a <code> - * MalformedTreeException</code> when executing the edit tree. - * <p> - * Move target edits can't be used as a parent for other edits. - * Trying to add an edit to a move target edit results in a <code> - * MalformedTreeException</code> as well. - * - * @see org.eclipse.text.edits.MoveSourceEdit - * @see org.eclipse.text.edits.CopyTargetEdit - * - * @since 3.0 - */ -public final class MoveTargetEdit extends TextEdit { - - private MoveSourceEdit fSource; - - /** - * Constructs a new move target edit - * - * @param offset the edit's offset - */ - public MoveTargetEdit(int offset) { - super(offset, 0); - } - - /** - * Constructs an new move target edit - * - * @param offset the edit's offset - * @param source the corresponding source edit - */ - public MoveTargetEdit(int offset, MoveSourceEdit source) { - this(offset); - setSourceEdit(source); - } - - /* - * Copy constructor - */ - private MoveTargetEdit(MoveTargetEdit other) { - super(other); - } - - /** - * Returns the associated source edit or <code>null</code> - * if no source edit is associated yet. - * - * @return the source edit or <code>null</code> - */ - public MoveSourceEdit getSourceEdit() { - return fSource; - } - - /** - * Sets the source edit. - * - * @param edit the source edit - * - * @exception MalformedTreeException is thrown if the target edit - * is a direct or indirect child of the source edit - */ - public void setSourceEdit(MoveSourceEdit edit) { - if (fSource != edit) { - fSource= edit; - fSource.setTargetEdit(this); - TextEdit parent= getParent(); - while (parent != null) { - if (parent == fSource) - throw new MalformedTreeException(parent, this, TextEditMessages.getString("MoveTargetEdit.wrong_parent")); //$NON-NLS-1$ - parent= parent.getParent(); - } - } - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new MoveTargetEdit(this); - } - - /* non Java-doc - * @see TextEdit#postProcessCopy - */ - protected void postProcessCopy(TextEditCopier copier) { - if (fSource != null) { - MoveTargetEdit target= (MoveTargetEdit)copier.getCopy(this); - MoveSourceEdit source= (MoveSourceEdit)copier.getCopy(fSource); - if (target != null && source != null) - target.setSourceEdit(source); - } - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - //---- consistency check ---------------------------------------------------------- - - /* non Java-doc - * @see TextEdit#traverseConsistencyCheck - */ - /* package */ int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { - return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; - } - - /* non Java-doc - * @see TextEdit#performConsistencyCheck - */ - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { - if (fSource == null) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.no_source")); //$NON-NLS-1$ - if (fSource.getTargetEdit() != this) - throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.different_target")); //$NON-NLS-1$ - } - - //---- document updating ---------------------------------------------------------------- - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - String source= fSource.getContent(); - document.replace(getOffset(), getLength(), source); - fDelta= source.length() - getLength(); - - MultiTextEdit sourceRoot= fSource.getRoot(); - if (sourceRoot != null) { - sourceRoot.moveTree(getOffset()); - TextEdit[] sourceChildren= sourceRoot.removeChildren(); - List children= new ArrayList(sourceChildren.length); - for (int i= 0; i < sourceChildren.length; i++) { - TextEdit child= sourceChildren[i]; - child.internalSetParent(this); - children.add(child); - } - internalSetChildren(children); - } - fSource.clearContent(); - return fDelta; - } - - //---- region updating -------------------------------------------------------------- - - /* (non-Javadoc) - * @see org.eclipse.text.edits.TextEdit#traversePassThree - */ - /* package */ int traverseRegionUpdating(TextEditProcessor processor, IDocument document, int accumulatedDelta, boolean delete) { - // the children got already updated / normalized while they got removed - // from the source edit. So we only have to adjust the offset computed to - // far. - if (delete) { - deleteTree(); - } else { - moveTree(accumulatedDelta); - } - return accumulatedDelta + fDelta; - } - - /* package */ boolean deleteChildren() { - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java deleted file mode 100644 index 3e250cf8d0b..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; - -/** - * A multi-text edit can be used to aggregate several edits into - * one edit. The edit itself doesn't modify a document. - * <p> - * Clients are allowed to implement subclasses of a multi-text - * edit.Subclasses must implement <code>doCopy()</code> to ensure - * the a copy of the right type is created. Not implementing - * <code>doCopy()</code> in subclasses will result in an assertion - * failure during copying. - * - * @since 3.0 - */ -public class MultiTextEdit extends TextEdit { - - private boolean fDefined; - - /** - * Creates a new <code>MultiTextEdit</code>. The range - * of the edit is determined by the range of its children. - * - * Adding this edit to a parent edit sets its range to the - * range covered by its children. If the edit doesn't have - * any children its offset is set to the parent's offset - * and its length is set to 0. - */ - public MultiTextEdit() { - super(0, Integer.MAX_VALUE); - fDefined= false; - } - - /** - * Creates a new </code>MultiTextEdit</code> for the given - * range. Adding a child to this edit which isn't covered - * by the given range will result in an exception. - * - * @param offset the edit's offset - * @param length the edit's length. - * @see TextEdit#addChild(TextEdit) - * @see TextEdit#addChildren(TextEdit[]) - */ - public MultiTextEdit(int offset, int length) { - super(offset, length); - fDefined= true; - } - - /* - * Copy constructor. - */ - protected MultiTextEdit(MultiTextEdit other) { - super(other); - } - - /** - * Checks the edit's integrity. - * <p> - * Note that this method <b>should only be called</b> by the edit - * framework and not by normal clients.</p> - *<p> - * This default implementation does nothing. Subclasses may override - * if needed.</p> - * - * @exception MalformedTreeException if the edit isn't in a valid state - * and can therefore not be executed - */ - protected void checkIntegrity() throws MalformedTreeException { - // does nothing - } - - /* - * @see org.eclipse.text.edits.TextEdit#canZeroLengthCover() - */ - protected boolean canZeroLengthCover() { - return true; - } - - /* - * @see TextEdit#copy - */ - protected TextEdit doCopy() { - Assert.isTrue(MultiTextEdit.class == getClass(), "Subclasses must reimplement copy0"); //$NON-NLS-1$ - return new MultiTextEdit(this); - } - - /* - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* - * @see TextEdit#performConsistencyCheck - */ - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { - checkIntegrity(); - } - - /* - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - fDelta= 0; - return fDelta; - } - - /* - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } - - /* package */ void aboutToBeAdded(TextEdit parent) { - defineRegion(parent.getOffset()); - } - - /* package */ void defineRegion(int parentOffset) { - if (fDefined) - return; - if (hasChildren()) { - IRegion region= getCoverage(getChildren()); - internalSetOffset(region.getOffset()); - internalSetLength(region.getLength()); - } else { - internalSetOffset(parentOffset); - internalSetLength(0); - } - fDefined= true; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/RangeMarker.java b/org.eclipse.text/src/org/eclipse/text/edits/RangeMarker.java deleted file mode 100644 index a90e5200b82..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/RangeMarker.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A range marker can be used to track positions when executing - * text edits. - * - * @since 3.0 - */ -public final class RangeMarker extends TextEdit { - - /** - * Creates a new range marker for the given offset and length. - * - * @param offset the marker's offset - * @param length the marker's length - */ - public RangeMarker(int offset, int length) { - super(offset, length); - } - - /* - * Copy constructor - */ - private RangeMarker(RangeMarker other) { - super(other); - } - - /* non Java-doc - * @see TextEdit#copy - */ - protected TextEdit doCopy() { - return new RangeMarker(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - fDelta= 0; - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return false; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/ReplaceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/ReplaceEdit.java deleted file mode 100644 index 63f387f4957..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/ReplaceEdit.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * Text edit to replace a range in a document with a different - * string. - * - * @since 3.0 - */ -public final class ReplaceEdit extends TextEdit { - - private String fText; - - /** - * Constructs a new replace edit. - * - * @param offset the offset of the range to replace - * @param length the length of the range to replace - * @param text the new text - */ - public ReplaceEdit(int offset, int length, String text) { - super(offset, length); - Assert.isNotNull(text); - fText= text; - } - - /* - * Copy constructor - * - * @param other the edit to copy from - */ - private ReplaceEdit(ReplaceEdit other) { - super(other); - fText= other.fText; - } - - /** - * Returns the new text replacing the text denoted - * by the edit. - * - * @return the edit's text. - */ - public String getText() { - return fText; - } - - /* non Java-doc - * @see TextEdit#doCopy - */ - protected TextEdit doCopy() { - return new ReplaceEdit(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* non Java-doc - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - document.replace(getOffset(), getLength(), fText); - fDelta= fText.length() - getLength(); - return fDelta; - } - - /* non Java-doc - * @see TextEdit#deleteChildren - */ - /* package */ boolean deleteChildren() { - return true; - } - - /* non Java-doc - * @see java.lang.Object#toString() - */ - public String toString() { - return super.toString() + " <<" + fText; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java deleted file mode 100644 index a330e72336d..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java +++ /dev/null @@ -1,849 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; - -/** - * A text edit describes an elementary text manipulation operation. Edits are - * executed by applying them to a document (e.g. an instance of <code>IDocument - * </code>). - * <p> - * Text edits form a tree. Clients can navigate the tree upwards, from child to - * parent, as well as downwards. Newly created edits are unparented. New edits - * are added to the tree by calling one of the <code>add</code> methods on a parent - * edit. - * </p> - * <p> - * An edit tree is well formed in the following sense: - * <ul> - * <li>a parent edit covers all its children</li> - * <li>children don't overlap</li> - * <li>an edit with length 0 can't have any children</li> - * </ul> - * Any manipulation of the tree that violates one of the above requirements results - * in a <code>MalformedTreeException</code>. - * </p> - * <p> - * Insert edits are represented by an edit of length 0. If more than one insert - * edit exists at the same offset then the edits are executed in the order in which - * they have been added to a parent. The following code example: - * <pre> - * IDocument document= new Document("org"); - * MultiEdit edit= new MultiEdit(); - * edit.add(new InsertEdit(0, "www."); - * edit.add(new InsertEdit(0, "eclipse."); - * edit.apply(document); - * </pre> - * therefore results in string: "www.eclipse.org". - * </p> - * <p> - * Text edits can be executed in a mode where the edit's region is updated to - * reflect the edit's position in the changed document. Region updating is enabled - * by default or can be requested by passing <code>UPDATE_REGIONS</code> to the - * {@link #apply(IDocument, int) apply(IDocument, int)} method. In the above example - * the region of the <code>InsertEdit(0, "eclipse.")</code> edit after executing - * the root edit is <code>[3, 8]</code>. If the region of an edit got deleted during - * change execution the region is set to <code>[-1, -1]</code> and the method {@link - * #isDeleted() isDeleted} returns <code>true</code>. - * </p> - * This class isn't intended to be subclassed outside of the edit framework. Clients - * are only allowed to subclass <code>MultiTextEdit</code>. - * - * @since 3.0 - */ -public abstract class TextEdit { - - /** - * Flags indicating that either <code>CREATE_UNDO</code> nor - * <code>UPDATE_REGIONS</code> is set. - */ - public static final int NONE= 0; - - /** - * Flags indicating that applying an edit tree to a document - * is supposed to create a corresponding undo edit. If not - * specified <code>null</code> is returned from method <code> - * apply</code>. - */ - public static final int CREATE_UNDO= 1 << 0; - - /** - * Flag indicating that the edit's region will be updated to - * reflect its position in the changed document. If not specified - * when applying an edit tree to a document the edit's region will - * be arbitrary. It is even not guaranteed that the tree is still - * well formed. - */ - public static final int UPDATE_REGIONS= 1 << 1; - - private static class InsertionComparator implements Comparator { - public int compare(Object o1, Object o2) { - TextEdit edit1 = (TextEdit) o1; - TextEdit edit2 = (TextEdit) o2; - - int offset1 = edit1.getOffset(); - int length1 = edit1.getLength(); - - int offset2 = edit2.getOffset(); - int length2 = edit2.getLength(); - - // make sure that a duplicate insertion point at the same offet is - // inserted last. Have to double check with the spec. It says the - // with identical values there is no guarantee which one will be - // found. - if (offset1 == offset2 && length1 == 0 && length2 == 0) { - return -1; - } - if (offset1 + length1 - 1 < offset2) { - return -1; - } - if (offset2 + length2 - 1 < offset1) { - return 1; - } - throw new MalformedTreeException( - null, edit1, - TextEditMessages.getString("TextEdit.overlapping")); //$NON-NLS-1$ - } - } - - private static final TextEdit[] EMPTY_ARRAY= new TextEdit[0]; - private static final InsertionComparator INSERTION_COMPARATOR= new InsertionComparator(); - - private static final int DELETED_VALUE= -1; - - private int fOffset; - private int fLength; - - /* package */ TextEdit fParent; - /* package */ List fChildren; - - /* package */ int fDelta; - - /** - * Create a new text edit. Parent is initialized to <code> - * null<code> and the edit doesn't have any children. - * - * @param offset the edit's offset - * @param length the edit's length - */ - protected TextEdit(int offset, int length) { - Assert.isTrue(offset >= 0 && length >= 0); - fOffset= offset; - fLength= length; - fDelta= 0; - } - - /** - * Copy constructor - * - * @param source the source to copy form - */ - protected TextEdit(TextEdit source) { - fOffset= source.fOffset; - fLength= source.fLength; - fDelta= 0; - } - - //---- Region management ----------------------------------------------- - - /** - * Returns the range that this edit is manipulating. The returned - * <code>IRegion</code> contains the edit's offset and length at - * the point in time when this call is made. Any subsequent changes - * to the edit's offset and length aren't reflected in the returned - * region object. - * <p> - * Creating a region for a deleted edit will result in an assertion - * failure. - * - * @return the manipulated region - */ - public final IRegion getRegion() { - return new Region(fOffset, fLength); - } - - /** - * Returns the offset of the edit. An offset is a 0-based - * character index. Returns <code>-1</code> if the edit - * is marked as deleted - * - * @return the offset of the edit - */ - public final int getOffset() { - return fOffset; - } - - /** - * Returns the length of the edit. Returns <code>-1</code> - * if the edit is marked as deleted. - * - * @return the length of the edit - */ - public final int getLength() { - return fLength; - } - - /** - * Returns the inclusive end position of this edit. The inclusive end - * position denotes the last character of the region manipulated by - * this edit. The returned value is the result of the following - * calculation: - * <pre> - * getOffset() + getLength() - 1; - * <pre> - * - * @return the inclusive end position - */ - public final int getInclusiveEnd() { - return fOffset + fLength - 1; - } - - /** - * Returns the exclusive end position of this edit. The exclusive end - * position denotes the next character of the region manipulated by - * this edit. The returned value is the result of the following - * calculation: - * <pre> - * getOffset() + getLength(); - * </pre> - * - * @return the exclusive end position - */ - public final int getExclusiveEnd() { - return fOffset + fLength; - } - - /** - * Returns whether this edit has been deleted or not. - * - * @return <code>true</code> if the edit has been - * deleted; otherwise <code>false</code> is returned. - */ - public final boolean isDeleted() { - return fOffset == DELETED_VALUE && fLength == DELETED_VALUE; - } - - /** - * Returns <code>true</code> if the edit covers the given edit - * <code>other</code>. It is up to the concrete text edit to - * decide if a edit of length zero can cover another edit. - * - * @param other the other edit - * @return <code>true<code> if the edit covers the other edit; - * otherwise <code>false</code> is returned. - */ - public final boolean covers(TextEdit other) { - if (fLength == 0 && !canZeroLengthCover()) { - return false; - } else { - int otherOffset= other.fOffset; - return fOffset <= otherOffset && otherOffset + other.fLength <= fOffset + fLength; - } - } - - /** - * Returns <code>true</code> if an edit with length zero can cover - * another edit. Returns <code>false</code> otherwise. - * - * @return whether an edit of length zero can cover another edit - */ - protected boolean canZeroLengthCover() { - return false; - } - - //---- parent and children management ----------------------------- - - /** - * Returns the edit's parent. The method returns <code>null</code> - * if this edit hasn't been add to another edit. - * - * @return the edit's parent - */ - public final TextEdit getParent() { - return fParent; - } - - /** - * Adds the given edit <code>child</code> to this edit. - * - * @param child the child edit to add - * @exception MalformedTreeException is thrown if the child - * edit can't be added to this edit. This is the case if the child - * overlaps with one of its siblings or if the child edit's region - * isn't fully covered by this edit. - */ - public final void addChild(TextEdit child) throws MalformedTreeException { - internalAdd(child); - } - - /** - * Adds all edits in <code>edits</code> to this edit. - * - * @param edits the text edits to add - * @exception MalformedTreeException is thrown if one of - * the given edits can't be added to this edit. - * - * @see #addChild(TextEdit) - */ - public final void addChildren(TextEdit[] edits) throws MalformedTreeException { - for (int i= 0; i < edits.length; i++) { - internalAdd(edits[i]); - } - } - - /** - * Removes the edit specified by the given index from the list - * of children. Returns the child edit that was removed from - * the list of children. The parent of the returned edit is - * set to <code>null</code>. - * - * @param index the index of the edit to remove - * @return the removed edit - * @exception IndexOutOfBoundsException if the index - * is out of range - */ - public final TextEdit removeChild(int index) { - if (fChildren == null) - throw new IndexOutOfBoundsException("Index: " + index + " Size: 0"); //$NON-NLS-1$//$NON-NLS-2$ - TextEdit result= (TextEdit)fChildren.remove(index); - result.internalSetParent(null); - if (fChildren.isEmpty()) - fChildren= null; - return result; - } - - /** - * Removes the first occurrence of the given child from the list - * of children. - * - * @param child the child to be removed - * @return <code>true</code> if the edit contained the given - * child; otherwise <code>false</code> is returned - */ - public final boolean removeChild(TextEdit child) { - Assert.isNotNull(child); - if (fChildren == null) - return false; - boolean result= fChildren.remove(child); - if (result) { - child.internalSetParent(null); - if (fChildren.isEmpty()) - fChildren= null; - } - return result; - } - - /** - * Removes all child edits from and returns them. The parent - * of the removed edits is set to <code>null</code>. - * - * @return an array of the removed edits - */ - public final TextEdit[] removeChildren() { - if (fChildren == null) - return EMPTY_ARRAY; - int size= fChildren.size(); - TextEdit[] result= new TextEdit[size]; - for (int i= 0; i < size; i++) { - result[i]= (TextEdit)fChildren.get(i); - result[i].internalSetParent(null); - } - fChildren= null; - return result; - } - - /** - * Returns <code>true</code> if this edit has children. Otherwise - * <code>false</code> is returned. - * - * @return <code>true</code> if this edit has children; otherwise - * <code>false</code> is returned - */ - public final boolean hasChildren() { - return fChildren != null && ! fChildren.isEmpty(); - } - - /** - * Returns the edit's children. If the edit doesn't have any - * children an empty array is returned. - * - * @return the edit's children - */ - public final TextEdit[] getChildren() { - if (fChildren == null) - return EMPTY_ARRAY; - return (TextEdit[])fChildren.toArray(new TextEdit[fChildren.size()]); - } - - /** - * Returns the size of the managed children. - * - * @return the size of the children - */ - public final int getChildrenSize() { - if (fChildren == null) - return 0; - return fChildren.size(); - } - - /** - * Returns the text range spawned by the given array of text edits. - * The method requires that the given array contains at least one - * edit. If all edits passed are deleted the method returns <code> - * null</code>. - * - * @param edits an array of edits - * @return the text range spawned by the given array of edits or - * <code>null</code> if all edits are marked as deleted - */ - public static IRegion getCoverage(TextEdit[] edits) { - Assert.isTrue(edits != null && edits.length > 0); - - int offset= Integer.MAX_VALUE; - int end= Integer.MIN_VALUE; - int deleted= 0; - for (int i= 0; i < edits.length; i++) { - TextEdit edit= edits[i]; - if (edit.isDeleted()) { - deleted++; - } else { - offset= Math.min(offset, edit.getOffset()); - end= Math.max(end, edit.getExclusiveEnd()); - } - } - if (edits.length == deleted) { - return null; - } else { - return new Region(offset, end - offset); - } - } - - /* - * Hook called before this edit gets added to the passed - * parent. - */ - /* package */ void aboutToBeAdded(TextEdit parent) { - } - - //---- Object methods ------------------------------------------------------ - - /** - * The <code>Edit</code> implementation of this <code>Object</code> - * method uses object identity (==). - * - * @param obj the other object - * @return <code>true</code> iff <code>this == obj</code>; otherwise - * <code>false</code> is returned - * - * @see Object#equals(java.lang.Object) - */ - public final boolean equals(Object obj) { - return this == obj; // equivalent to Object.equals - } - - /** - * The <code>Edit</code> implementation of this <code>Object</code> - * method calls uses <code>Object#hashCode()</code> to compute its - * hash code. - * - * @return the object's hash code value - * - * @see Object#hashCode() - */ - public final int hashCode() { - return super.hashCode(); - } - - /* non Java-doc - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer= new StringBuffer("{"); //$NON-NLS-1$ - String name= getClass().getName(); - int index= name.lastIndexOf('.'); - if (index != -1) { - buffer.append(name.substring(index + 1)); - } else { - buffer.append(name); - } - buffer.append(" } "); //$NON-NLS-1$ - if (isDeleted()) { - buffer.append("[deleted]"); //$NON-NLS-1$ - } else { - buffer.append("["); //$NON-NLS-1$ - buffer.append(fOffset); - buffer.append(","); //$NON-NLS-1$ - buffer.append(fLength); - buffer.append("]"); //$NON-NLS-1$ - } - return buffer.toString(); - } - - //---- Copying ------------------------------------------------------------- - - /** - * Creates a deep copy of the edit tree rooted at this - * edit. - * - * @return a deep copy of the edit tree - * @see #doCopy() - */ - public final TextEdit copy() { - TextEditCopier copier= new TextEditCopier(this); - return copier.perform(); - } - - /** - * Creates and returns a copy of this edit. The copy method should be - * implemented in a way so that the copy can executed without causing - * any harm to the original edit. Implementors of this method are - * responsible for creating deep or shallow copies of referenced - * object to fullfil this requirement. - * <p> - * Implementers of this method should use the copy constructor <code> - * Edit#Edit(Edit source) to initialize the edit part of the copy. - * Implementors aren't responsible to actually copy the children or - * to set the right parent. - * <p> - * This method <b>should not be called</b> from outside the framework. - * Please use <code>copy</code> to create a copy of a edit tree. - * - * @return a copy of this edit. - * @see #copy() - * @see #postProcessCopy(TextEditCopier) - * @see TextEditCopier - */ - protected abstract TextEdit doCopy(); - - /** - * This method is called on every edit of the copied tree to do some - * post-processing like connected an edit to a different edit in the tree. - * <p> - * This default implementation does nothing - * - * @param copier the copier that manages a map between original and - * copied edit. - * @see TextEditCopier - */ - protected void postProcessCopy(TextEditCopier copier) { - } - - //---- Visitor support ------------------------------------------------- - - /** - * Accepts the given visitor on a visit of the current edit. - * - * @param visitor the visitor object - * @exception IllegalArgumentException if the visitor is null - */ - public final void accept(TextEditVisitor visitor) { - Assert.isNotNull(visitor); - // begin with the generic pre-visit - visitor.preVisit(this); - // dynamic dispatch to internal method for type-specific visit/endVisit - accept0(visitor); - // end with the generic post-visit - visitor.postVisit(this); - } - - /** - * Accepts the given visitor on a type-specific visit of the current edit. - * This method must be implemented in all concrete text edits. - * <p> - * General template for implementation on each concrete TextEdit class: - * <pre> - * <code> - * boolean visitChildren = visitor.visit(this); - * if (visitChildren) { - * acceptChildren(visitor); - * } - * </code> - * </pre> - * Note that the caller (<code>accept</code>) takes care of invoking - * <code>visitor.preVisit(this)</code> and <code>visitor.postVisit(this)</code>. - * </p> - * - * @param visitor the visitor object - */ - protected abstract void accept0(TextEditVisitor visitor); - - - /** - * Accepts the given visitor on the edits children. - * <p> - * This method must be used by the concrete implementations of - * <code>accept</code> to traverse list-values properties; it - * encapsulates the proper handling of on-the-fly changes to the list. - * </p> - * - * @param visitor the visitor object - */ - protected final void acceptChildren(TextEditVisitor visitor) { - if (fChildren == null) - return; - Iterator iterator= fChildren.iterator(); - while (iterator.hasNext()) { - TextEdit curr= (TextEdit) iterator.next(); - curr.accept(visitor); - } - } - - //---- Execution ------------------------------------------------------- - - /** - * Applies the edit tree rooted by this edit to the given document. To check - * if the edit tree can be applied to the document either catch <code> - * MalformedTreeException</code> or use <code>TextEditProcessor</code> to - * execute an edit tree. - * - * @param document the document to be manipulated - * @param style flags controlling the execution of the edit tree. Valid - * flags are: <code>CREATE_UNDO</code> and </code>UPDATE_REGIONS</code>. - * @return a undo edit, if <code>CREATE_UNDO</code> is specified. Otherwise - * <code>null</code> is returned. - * - * @exception MalformedTreeException is thrown if the tree isn't - * in a valid state. This exception is thrown before any edit - * is executed. So the document is still in its original state. - * @exception BadLocationException is thrown if one of the edits - * in the tree can't be executed. The state of the document is - * undefined if this exception is thrown. - * - * @see TextEditProcessor#performEdits() - */ - public final UndoEdit apply(IDocument document, int style) throws MalformedTreeException, BadLocationException { - try { - TextEditProcessor processor= new TextEditProcessor(document, this, style); - return processor.performEdits(); - } finally { - // unconnect from text edit processor - fParent= null; - } - } - - /** - * Applies the edit tree rooted by this edit to the given document. This - * method is a convenience method for <code>apply(document, CREATE_UNDO | UPDATE_REGIONS) - * </code> - * - * @param document the document to which to apply this edit - * @return a undo edit, if <code>CREATE_UNDO</code> is specified. Otherwise - * <code>null</code> is returned. - * @exception MalformedTreeException is thrown if the tree isn't - * in a valid state. This exception is thrown before any edit - * is executed. So the document is still in its original state. - * @exception BadLocationException is thrown if one of the edits - * in the tree can't be executed. The state of the document is - * undefined if this exception is thrown. - * @see #apply(IDocument, int) - */ - public final UndoEdit apply(IDocument document) throws MalformedTreeException, BadLocationException { - return apply(document, CREATE_UNDO | UPDATE_REGIONS); - } - - /* package */ UndoEdit dispatchPerformEdits(TextEditProcessor processor) throws BadLocationException { - return processor.executeDo(); - } - - /* package */ void dispatchCheckIntegrity(TextEditProcessor processor) throws MalformedTreeException { - processor.checkIntegrityDo(); - } - - //---- internal state accessors ---------------------------------------------------------- - - /* package */ void internalSetParent(TextEdit parent) { - if (parent != null) - Assert.isTrue(fParent == null); - fParent= parent; - } - - /* package */ void internalSetOffset(int offset) { - Assert.isTrue(offset >= 0); - fOffset= offset; - } - - /* package */ void internalSetLength(int length) { - Assert.isTrue(length >= 0); - fLength= length; - } - - /* package */ List internalGetChildren() { - return fChildren; - } - - /* package */ void internalSetChildren(List children) { - fChildren= children; - } - - /* package */ void internalAdd(TextEdit child) throws MalformedTreeException { - child.aboutToBeAdded(this); - if (child.isDeleted()) - throw new MalformedTreeException(this, child, TextEditMessages.getString("TextEdit.deleted_edit")); //$NON-NLS-1$ - if (!covers(child)) - throw new MalformedTreeException(this, child, TextEditMessages.getString("TextEdit.range_outside")); //$NON-NLS-1$ - if (fChildren == null) { - fChildren= new ArrayList(2); - } - int index= computeInsertionIndex(child); - fChildren.add(index, child); - child.internalSetParent(this); - } - - private int computeInsertionIndex(TextEdit edit) { - int size= fChildren.size(); - if (size == 0) - return 0; - TextEdit last= (TextEdit)fChildren.get(size - 1); - if (last.getExclusiveEnd() <= edit.getOffset()) - return size; - try { - return -Collections.binarySearch(fChildren, edit,INSERTION_COMPARATOR) -1; - } catch(MalformedTreeException e) { - e.setParent(this); - throw e; - } - } - - //---- Offset & Length updating ------------------------------------------------- - - /** - * Adjusts the edits offset according to the given - * delta. This method doesn't update any children. - * - * @param delta the delta of the text replace operation - */ - /* package */ void adjustOffset(int delta) { - if (isDeleted()) - return; - fOffset+= delta; - Assert.isTrue(fOffset >= 0); - } - - /** - * Adjusts the edits length according to the given - * delta. This method doesn't update any children. - * - * @param delta the delta of the text replace operation - */ - /* package */ void adjustLength(int delta) { - if (isDeleted()) - return; - fLength+= delta; - Assert.isTrue(fLength >= 0); - } - - /** - * Marks the edit as deleted. This method doesn't update - * any children. - */ - /* package */ void markAsDeleted() { - fOffset= DELETED_VALUE; - fLength= DELETED_VALUE; - } - - //---- Edit processing ---------------------------------------------- - - /* package */ int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { - int result= 0; - if (fChildren != null) { - for (int i= fChildren.size() - 1; i >= 0; i--) { - TextEdit child= (TextEdit)fChildren.get(i); - result= Math.max(result, child.traverseConsistencyCheck(processor, document, sourceEdits)); - } - } - if (processor.considerEdit(this)) { - performConsistencyCheck(processor, document); - } - return result; - } - - /* package */ void performConsistencyCheck(TextEditProcessor processor, IDocument document) { - } - - /* package */ void traverseSourceComputation(TextEditProcessor processor, IDocument document) { - } - - /* package */ void performSourceComputation(TextEditProcessor processor, IDocument document) { - } - - /* package */ int traverseDocumentUpdating(TextEditProcessor processor, IDocument document) throws BadLocationException { - int delta= 0; - if (fChildren != null) { - for (int i= fChildren.size() - 1; i >= 0; i--) { - TextEdit child= (TextEdit)fChildren.get(i); - delta+= child.traverseDocumentUpdating(processor, document); - } - } - if (processor.considerEdit(this)) { - if (delta != 0) - adjustLength(delta); - int r= performDocumentUpdating(document); - if (r != 0) - adjustLength(r); - delta+= r; - } - return delta; - } - - /* package */ abstract int performDocumentUpdating(IDocument document) throws BadLocationException; - - /* package */ int traverseRegionUpdating(TextEditProcessor processor, IDocument document, int accumulatedDelta, boolean delete) { - performRegionUpdating(accumulatedDelta, delete); - if (fChildren != null) { - boolean childDelete= delete || deleteChildren(); - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - TextEdit child= (TextEdit)iter.next(); - accumulatedDelta= child.traverseRegionUpdating(processor, document, accumulatedDelta, childDelete); - } - } - return accumulatedDelta + fDelta; - } - - /* package */ void performRegionUpdating(int accumulatedDelta, boolean delete) { - if (delete) - markAsDeleted(); - else - adjustOffset(accumulatedDelta); - } - - /* package */ abstract boolean deleteChildren(); - - /* package */ void moveTree(int delta) { - adjustOffset(delta); - if (fChildren != null) { - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - ((TextEdit)iter.next()).moveTree(delta); - } - } - } - - /* package */ void deleteTree() { - markAsDeleted(); - if (fChildren != null) { - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - TextEdit child= (TextEdit)iter.next(); - child.deleteTree(); - } - } - } -} - diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java deleted file mode 100644 index 49dc471ef1b..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.text.Assert; - -/** - * Copies a tree of text edits. A text edit copier keeps a map - * between original and new text edits. It can be used to map - * a copy back to its original edit. - * - * @since 3.0 - */ -public final class TextEditCopier { - - private TextEdit fEdit; - private Map fCopies; - - /** - * Constructs a new <code>TextEditCopier</code> for the - * given edit. The actual copy is done by calling <code> - * perform</code>. - * - * @param edit the edit to copy - * - * @see #perform() - */ - public TextEditCopier(TextEdit edit) { - super(); - Assert.isNotNull(edit); - fEdit= edit; - fCopies= new HashMap(); - } - - /** - * Performs the actual copying. - * - * @return the copy - */ - public TextEdit perform() { - TextEdit result= doCopy(fEdit); - if (result != null) { - for (Iterator iter= fCopies.keySet().iterator(); iter.hasNext();) { - TextEdit edit= (TextEdit)iter.next(); - edit.postProcessCopy(this); - } - } - return result; - } - - /** - * Returns the copy for the original text edit. - * - * @param original the original for which the copy - * is requested - * @return the copy of the original edit or <code>null</code> - * if the original isn't managed by this copier - */ - public TextEdit getCopy(TextEdit original) { - Assert.isNotNull(original); - return (TextEdit)fCopies.get(original); - } - - //---- helper methods -------------------------------------------- - - private TextEdit doCopy(TextEdit edit) { - TextEdit result= edit.doCopy(); - List children= edit.internalGetChildren(); - if (children != null) { - List newChildren= new ArrayList(children.size()); - for (Iterator iter= children.iterator(); iter.hasNext();) { - TextEdit childCopy= doCopy((TextEdit)iter.next()); - childCopy.internalSetParent(result); - newChildren.add(childCopy); - } - result.internalSetChildren(newChildren); - } - addCopy(edit, result); - return result; - } - - private void addCopy(TextEdit original, TextEdit copy) { - fCopies.put(original, copy); - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java deleted file mode 100644 index cc7be5181d4..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.IRegion; - - -/** - * A text edit group combines a list of {@link TextEdit}s - * and a name into a single object. The name must be a human - * readable string use to present the text edit group in the - * user interface. - * - * @since 3.0 - */ -public class TextEditGroup { - - private String fDescription; - private List fEdits; - - /** - * Creates a new text edit group with the given name. - * - * @param name the name of the text edit group. Must be - * a human readable string - */ - public TextEditGroup(String name) { - super(); - Assert.isNotNull(name); - fDescription= name; - fEdits= new ArrayList(3); - } - - /** - * Creates a new text edit group with a name and a single - * {@link TextEdit}. - * - * @param name the name of the text edit group. Must be - * a human readable string - * @param edit the edit to manage - */ - public TextEditGroup(String name, TextEdit edit) { - Assert.isNotNull(name); - Assert.isNotNull(edit); - fDescription= name; - fEdits= new ArrayList(1); - fEdits.add(edit); - } - - /** - * Creates a new text edit group with the given name and - * array of edits. - * - * @param name the name of the text edit group. Must be - * a human readable string - * @param edits the array of edits - */ - public TextEditGroup(String name, TextEdit[] edits) { - super(); - Assert.isNotNull(name); - Assert.isNotNull(edits); - fDescription= name; - fEdits= new ArrayList(Arrays.asList(edits)); - } - - /** - * Returns the edit group's name. - * - * @return the edit group's name - */ - public String getName() { - return fDescription; - } - - /** - * Adds the given {@link TextEdit} to this group. - * - * @param edit the edit to add - */ - public void addTextEdit(TextEdit edit) { - fEdits.add(edit); - } - - /** - * Returns <code>true</code> if the list of managed - * {@link TextEdit}s is empty; otherwise <code>false - * </code> is returned. - * - * @return whether the list of managed text edits is - * empty or not - */ - public boolean isEmpty() { - return fEdits.isEmpty(); - } - - /** - * Returns an array of {@link TextEdit}s containing - * the edits managed by this group. - * - * @return the managed text edits - */ - public TextEdit[] getTextEdits() { - return (TextEdit[]) fEdits.toArray(new TextEdit[fEdits.size()]); - } - - /** - * Returns the text region covered by the edits managed via this - * edit group. If the group doesn't manage any edits <code>null - * </code> is returned. - * - * @return the text region covered by this edit group or <code> - * null</code> if no edits are managed - */ - public IRegion getRegion() { - int size= fEdits.size(); - if (size == 0) { - return null; - } else if (size == 1) { - return ((TextEdit)fEdits.get(0)).getRegion(); - } else { - return TextEdit.getCoverage((TextEdit[])fEdits.toArray(new TextEdit[fEdits.size()])); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditMessages.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditMessages.java deleted file mode 100644 index 02e4d816153..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditMessages.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/* package */ class TextEditMessages { - - private static final String BUNDLE_NAME= "org.eclipse.text.edits.Messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE= ResourceBundle.getBundle(BUNDLE_NAME); - - private TextEditMessages() { - } - - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - public static String getFormattedString(String key, Object arg) { - return getFormattedString(key, new Object[] { arg }); - } - - public static String getFormattedString(String key, Object[] args) { - return MessageFormat.format(getString(key), args); - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java deleted file mode 100644 index 7e187a30b03..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A <code>TextEditProcessor</code> manages a set of edits and applies - * them as a whole to an <code>IDocument</code>. - * <p> - * This class isn't intended to be subclassed. - * - * @see org.eclipse.text.edits.TextEdit#apply(IDocument) - * - * @since 3.0 - */ -public class TextEditProcessor { - - private IDocument fDocument; - private TextEdit fRoot; - private int fStyle; - - private boolean fChecked; - private MalformedTreeException fException; - - private List fSourceEdits; - - /** - * Constructs a new edit processor for the given - * document. - * - * @param document the document to manipulate - * @param root the root of the text edit tree describing - * the modifications. By passing a text edit a a text edit - * processor the ownership of the edit is transfered to the - * text edit processors. Clients must not modify the edit - * (e.g adding new children) any longer. - * @param style {@link TextEdit#NONE}, {@link TextEdit#CREATE_UNDO} or {@link TextEdit#UPDATE_REGIONS}) - */ - public TextEditProcessor(IDocument document, TextEdit root, int style) { - Assert.isNotNull(document); - Assert.isNotNull(root); - fDocument= document; - fRoot= root; - if (fRoot instanceof MultiTextEdit) - ((MultiTextEdit)fRoot).defineRegion(0); - fStyle= style; - } - - /** - * Returns the document to be manipulated. - * - * @return the document - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * Returns the edit processor's root edit. - * - * @return the processor's root edit - */ - public TextEdit getRoot() { - return fRoot; - } - - /** - * Returns the style bits of the text edit processor - * - * @return the style bits - * @see TextEdit#CREATE_UNDO - * @see TextEdit#UPDATE_REGIONS - */ - public int getStyle() { - return fStyle; - } - - /** - * Checks if the processor can execute all its edits. - * - * @return <code>true</code> if the edits can be executed. Return <code>false - * </code>otherwise. One major reason why edits cannot be executed are wrong - * offset or length values of edits. Calling perform in this case will very - * likely end in a <code>BadLocationException</code>. - */ - public boolean canPerformEdits() { - try { - fRoot.dispatchCheckIntegrity(this); - fChecked= true; - } catch (MalformedTreeException e) { - fException= e; - return false; - } - return true; - } - - /** - * Executes the text edits. - * - * @return an object representing the undo of the executed edits - * @exception MalformedTreeException is thrown if the edit tree isn't - * in a valid state. This exception is thrown before any edit is executed. - * So the document is still in its original state. - * @exception BadLocationException is thrown if one of the edits in the - * tree can't be executed. The state of the document is undefined if this - * exception is thrown. - */ - public UndoEdit performEdits() throws MalformedTreeException, BadLocationException { - if (!fChecked) { - fRoot.dispatchCheckIntegrity(this); - } else { - if (fException != null) - throw fException; - } - return fRoot.dispatchPerformEdits(this); - } - - /* non Java-doc - * Class isn't intended to be sublcassed - */ - protected boolean considerEdit(TextEdit edit) { - return true; - } - - //---- checking -------------------------------------------------------------------- - - /* package */ void checkIntegrityDo() throws MalformedTreeException { - fSourceEdits= new ArrayList(); - fRoot.traverseConsistencyCheck(this, fDocument, fSourceEdits); - if (fRoot.getExclusiveEnd() > fDocument.getLength()) - throw new MalformedTreeException(null, fRoot, TextEditMessages.getString("TextEditProcessor.invalid_length")); //$NON-NLS-1$ - } - - /* package */ void checkIntegrityUndo() { - if (fRoot.getExclusiveEnd() > fDocument.getLength()) - throw new MalformedTreeException(null, fRoot, TextEditMessages.getString("TextEditProcessor.invalid_length")); //$NON-NLS-1$ - } - - //---- execution -------------------------------------------------------------------- - - /* package */ UndoEdit executeDo() throws BadLocationException { - UndoCollector collector= new UndoCollector(fRoot); - try { - if (createUndo()) - collector.connect(fDocument); - computeSources(); - fRoot.traverseDocumentUpdating(this, fDocument); - if (updateRegions()) { - fRoot.traverseRegionUpdating(this, fDocument, 0, false); - } - } finally { - collector.disconnect(fDocument); - } - return collector.undo; - } - - private void computeSources() { - for (Iterator iter= fSourceEdits.iterator(); iter.hasNext();) { - List list= (List)iter.next(); - if (list != null) { - for (Iterator edits= list.iterator(); edits.hasNext();) { - TextEdit edit= (TextEdit)edits.next(); - edit.traverseSourceComputation(this, fDocument); - } - } - } - } - - /* package */ UndoEdit executeUndo() throws BadLocationException { - UndoCollector collector= new UndoCollector(fRoot); - try { - if (createUndo()) - collector.connect(fDocument); - TextEdit[] edits= fRoot.getChildren(); - for (int i= edits.length - 1; i >= 0; i--) { - edits[i].performDocumentUpdating(fDocument); - } - } finally { - collector.disconnect(fDocument); - } - return collector.undo; - } - - private boolean createUndo() { - return (fStyle & TextEdit.CREATE_UNDO) != 0; - } - - private boolean updateRegions() { - return (fStyle & TextEdit.UPDATE_REGIONS) != 0; - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditVisitor.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditVisitor.java deleted file mode 100644 index 005a21523fa..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditVisitor.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -/** - * A visitor for text edits. - * <p> - * For each different concrete text edit type <it>T</it> there is a method: - * <ul> - * <li><code>public boolean visit(<it>T</it> node)</code> - Visits the given edit to - * perform some arbitrary operation. If <code>true </code> is returned, the given edit's - * child edits will be visited next; however, if <code>false</code> is returned, the - * given edit's child edits will not be visited. The default implementation provided by - * this class calls a generic method <code>visitNode(<it>Testedit</it> node)</code>. - * Subclasses may reimplement these method as needed.</li> - * </ul> - * </p> - * <p> - * In addition, there are methods for visiting text edits in the - * abstract, regardless of node type: - * <ul> - * <li><code>public void preVisit(TextEdit edit)</code> - Visits - * the given edit to perform some arbitrary operation. - * This method is invoked prior to the appropriate type-specific - * <code>visit</code> method. - * The default implementation of this method does nothing. - * Subclasses may reimplement this method as needed.</li> - * - * <li><code>public void postVisit(TextEdit edit)</code> - Visits - * the given edit to perform some arbitrary operation. - * This method is invoked after the appropriate type-specific - * <code>endVisit</code> method. - * The default implementation of this method does nothing. - * Subclasses may reimplement this method as needed.</li> - * </ul> - * </p> - * <p> - * For edits with chldren, the child nodes are visited in increasing order. - * </p> - * - * @see TextEdit#accept(TextEditVisitor) - * @since 3.0 - */ -public class TextEditVisitor { - - /** - * Visits the given text edit prior to the type-specific visit. - * (before <code>visit</code>). - * <p> - * The default implementation does nothing. Subclasses may reimplement. - * </p> - * - * @param edit the node to visit - */ - public void preVisit(TextEdit edit) { - // default implementation: do nothing - } - - /** - * Visits the given text edit following the type-specific visit - * (after <code>endVisit</code>). - * <p> - * The default implementation does nothing. Subclasses may reimplement. - * </p> - * - * @param edit the node to visit - */ - public void postVisit(TextEdit edit) { - // default implementation: do nothing - } - - /** - * Visits the given text edit. This method is called by default from - * type-specific visits. It is not called by a edit's accept method. - * The default implementation returns <code>true</code>. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visitNode(TextEdit edit) { - return true; - } - - /** - * Visits a <code>CopySourceEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(CopySourceEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>CopyTargetEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(CopyTargetEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>MoveSourceEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(MoveSourceEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>MoveTargetEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(MoveTargetEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>RangeMarker</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(RangeMarker edit) { - return visitNode(edit); - } - - /** - * Visits a <code>CopyingRangeMarker</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(CopyingRangeMarker edit) { - return visitNode(edit); - } - - /** - * Visits a <code>DeleteEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(DeleteEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>InsertEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(InsertEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>ReplaceEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(ReplaceEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>UndoEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(UndoEdit edit) { - return visitNode(edit); - } - - /** - * Visits a <code>MultiTextEdit</code> instance. - * - * @param edit the node to visit - * @return If <code>true</code> is returned, the given node's child - * nodes will be visited next; however, if <code>false</code> is - * returned, the given node's child nodes will not be visited. - */ - public boolean visit(MultiTextEdit edit) { - return visitNode(edit); - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TreeIterationInfo.java b/org.eclipse.text/src/org/eclipse/text/edits/TreeIterationInfo.java deleted file mode 100644 index 1194cd51339..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/TreeIterationInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.Assert; - - -/* package */ class TreeIterationInfo { - - public static interface Visitor { - public void visit(TextEdit edit); - } - - private int fMark= -1; - private TextEdit[][] fEditStack= new TextEdit[10][]; - private int[] fIndexStack= new int[10]; - - public int getSize() { - return fMark + 1; - } - public void push(TextEdit[] edits) { - if (++fMark == fEditStack.length) { - TextEdit[][] t1= new TextEdit[fEditStack.length * 2][]; - System.arraycopy(fEditStack, 0, t1, 0, fEditStack.length); - fEditStack= t1; - int[] t2= new int[fEditStack.length]; - System.arraycopy(fIndexStack, 0, t2, 0, fIndexStack.length); - fIndexStack= t2; - } - fEditStack[fMark]= edits; - fIndexStack[fMark]= -1; - } - public void setIndex(int index) { - fIndexStack[fMark]= index; - } - public void pop() { - fEditStack[fMark]= null; - fIndexStack[fMark]= -1; - fMark--; - } - public void accept(Visitor visitor) { - for (int i= fMark; i >= 0; i--) { - Assert.isTrue(fIndexStack[i] >= 0); - int start= fIndexStack[i] + 1; - TextEdit[] edits= fEditStack[i]; - for (int s= start; s < edits.length; s++) { - visitor.visit(edits[s]); - } - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/UndoCollector.java b/org.eclipse.text/src/org/eclipse/text/edits/UndoCollector.java deleted file mode 100644 index 69d3c57ff1a..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/UndoCollector.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; - - -/* package */ class UndoCollector implements IDocumentListener { - - protected UndoEdit undo; - private int fOffset; - private int fLength; - - public UndoCollector(TextEdit root) { - fOffset= root.getOffset(); - fLength= root.getLength(); - } - - public void connect(IDocument document) { - document.addDocumentListener(this); - undo= new UndoEdit(); - } - - public void disconnect(IDocument document) { - if (undo != null) { - document.removeDocumentListener(this); - undo.defineRegion(fOffset, fLength); - } - } - - public void documentChanged(DocumentEvent event) { - fLength+= getDelta(event); - } - - private static int getDelta(DocumentEvent event) { - String text= event.getText(); - return text == null ? -event.getLength() : (text.length() - event.getLength()); - } - - public void documentAboutToBeChanged(DocumentEvent event) { - int offset= event.getOffset(); - int currentLength= event.getLength(); - String currentText= null; - try { - currentText= event.getDocument().get(offset, currentLength); - } catch (BadLocationException cannotHappen) { - Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$ - } - - String newText = event.getText(); - undo.add(new ReplaceEdit(offset, newText != null ? newText.length() : 0, currentText)); - } -} diff --git a/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java deleted file mode 100644 index d8bdbf3dca6..00000000000 --- a/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.text.edits; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * This class encapsulates the reverse changes of an executed text - * edit tree. To apply an undo memento to a document use method - * <code>apply(IDocument)</code>. - * <p> - * Clients can add additional children to an undo edit nor can they - * add an undo edit as a child to another edit. Doing so results in - * both cases in a <code>MalformedTreeException<code>. - * - * @since 3.0 - */ -public final class UndoEdit extends TextEdit { - - /* package */ UndoEdit() { - super(0, Integer.MAX_VALUE); - } - - private UndoEdit(UndoEdit other) { - super(other); - } - - /* (non-Javadoc) - * @see org.eclipse.text.edits.TextEdit#internalAdd(org.eclipse.text.edits.TextEdit) - */ - /* package */ void internalAdd(TextEdit child) throws MalformedTreeException { - throw new MalformedTreeException(null, this, TextEditMessages.getString("UndoEdit.no_children")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.text.edits.MultiTextEdit#aboutToBeAdded(org.eclipse.text.edits.TextEdit) - */ - /* package */ void aboutToBeAdded(TextEdit parent) { - throw new MalformedTreeException(parent, this, TextEditMessages.getString("UndoEdit.can_not_be_added")); //$NON-NLS-1$ - } - - /* package */ UndoEdit dispatchPerformEdits(TextEditProcessor processor) throws BadLocationException { - return processor.executeUndo(); - } - - /* package */ void dispatchCheckIntegrity(TextEditProcessor processor) throws MalformedTreeException { - processor.checkIntegrityUndo(); - } - - /* (non-Javadoc) - * @see org.eclipse.text.edits.TextEdit#doCopy() - */ - protected TextEdit doCopy() { - return new UndoEdit(this); - } - - /* (non-Javadoc) - * @see TextEdit#accept0 - */ - protected void accept0(TextEditVisitor visitor) { - boolean visitChildren = visitor.visit(this); - if (visitChildren) { - acceptChildren(visitor); - } - } - - /* (non-Javadoc) - * @see TextEdit#performDocumentUpdating - */ - /* package */ int performDocumentUpdating(IDocument document) throws BadLocationException { - fDelta= 0; - return fDelta; - } - - /* package */ void add(ReplaceEdit edit) { - List children= internalGetChildren(); - if (children == null) { - children= new ArrayList(2); - internalSetChildren(children); - } - children.add(edit); - } - - /* package */ void defineRegion(int offset, int length) { - internalSetOffset(offset); - internalSetLength(length); - } - - /* package */ boolean deleteChildren() { - return false; - } -} - |