Package org.eclipse.jface.text.projection

## Class ProjectionDocument

- java.lang.Object
- - org.eclipse.jface.text.AbstractDocument
  - - org.eclipse.jface.text.projection.ProjectionDocument

All Implemented Interfaces:
  `IDocument`, `IDocumentExtension`, `IDocumentExtension2`, `IDocumentExtension3`, `IDocumentExtension4`, `IRepairableDocument`, `IRepairableDocumentExtension`

Direct Known Subclasses:
  `ChildDocument`

    public class ProjectionDocument
    extends AbstractDocument

A `ProjectionDocument` represents a projection of its master document. The contents of a projection document is a sequence of fragments of the master document, i.e. the projection document can be thought as being constructed from the master document by not copying the whole master document but omitting several ranges of the master document.

The projection document indirectly utilizes its master document as `ITextStore` by means of a `ProjectionTextStore`.

The content of a projection document can be changed in two ways. Either by a text replace applied to the master document or the projection document. Or by changing the projection between the master document and the projection document. For the latter the two methods `addMasterDocumentRange` and `removeMasterDocumentRange` are provided. For any manipulation, the projection document sends out a `ProjectionDocumentEvent` describing the change.

Clients are not supposed to directly instantiate this class. In order to obtain a projection document, a `ProjectionDocumentManager`should be used. This class is not intended to be subclassed outside of its origin package.

Since:
  3.0
Restriction:
  This class is not intended to be subclassed by clients.
Restriction:
  This class is not intended to be instantiated by clients.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.eclipse.jface.text.IDocumentExtension

`IDocumentExtension.IReplace`

### Field Summary

### Fields inherited from interface org.eclipse.jface.text.IDocument

`DEFAULT_CATEGORY, DEFAULT_CONTENT_TYPE`

### Fields inherited from interface org.eclipse.jface.text.IDocumentExtension3

`DEFAULT_PARTITIONING`

### Fields inherited from interface org.eclipse.jface.text.IDocumentExtension4

`UNKNOWN_MODIFICATION_STAMP`

### Constructor Summary

Constructors
`ProjectionDocument​(IDocument masterDocument)` Creates a projection document for the given master document.

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`protected boolean` `adaptProjectionToMasterChange​(DocumentEvent masterEvent)` Ensures that when the master event affects this projection document, that the whole region described by the event is part of this projection document.
`void` `addMasterDocumentRange​(int offsetInMaster, int lengthInMaster)` Ensures that the given range of the master document is part of this projection document.
`IRegion[]` `computeProjectedMasterRegions​(int offsetInMaster, int lengthInMaster)` Returns the sequence of all master document regions with are contained in the given master document range and which are part of this projection document.
`IRegion[]` `computeUnprojectedMasterRegions​(int offsetInMaster, int lengthInMaster)` Returns the sequence of all master document regions which are contained in the given master document range and which are not yet part of this projection document.
`void` `dispose()` Disposes this projection document.
`protected void` `fireDocumentAboutToBeChanged​(DocumentEvent event)` Fires the given document event to all registers document listeners informing them about the forthcoming document manipulation.
`protected void` `fireDocumentChanged​(DocumentEvent event)` Ignores the given event and sends the semantically equal slave document event instead.
`String` `getDefaultLineDelimiter()` Returns this document's default line delimiter.
`IDocumentInformationMapping` `getDocumentInformationMapping()` Returns the projection mapping used by this document.
`protected Position[]` `getFragments()` Returns the fragments of the master documents.
`IDocument` `getMasterDocument()` Returns the master document of this projection document.
`ProjectionMapping` `getProjectionMapping()` Deprecated. As of 3.4, replaced by `getDocumentInformationMapping()`
`protected Position[]` `getSegments()` Returns the segments of this projection document.
`protected boolean` `isUpdating()` Returns whether this projection is being updated.
`void` `masterDocumentAboutToBeChanged​(DocumentEvent masterEvent)` When called, this projection document is informed about a forthcoming change of its master document.
`void` `masterDocumentChanged​(DocumentEvent masterEvent)` When called, this projection document is informed about a change of its master document.
`void` `registerPostNotificationReplace​(IDocumentListener owner, IDocumentExtension.IReplace replace)` Callback for document listeners to be used inside `documentChanged` to register a post notification replace operation on the document notifying them.
`void` `removeMasterDocumentRange​(int offsetInMaster, int lengthInMaster)` Ensures that the given range of the master document is not part of this projection document.
`void` `replace​(int offset, int length, String text)` Substitutes the given text for the specified document range.
`void` `replaceMasterDocumentRanges​(int offsetInMaster, int lengthInMaster)` Replaces all master document ranges with the given master document range.
`void` `set​(String text)` Replaces the content of the document with the given text.
`void` `setAutoExpandMode​(boolean autoExpandMode)` Sets the auto expand mode for this document.
`protected void` `updateDocumentStructures​(DocumentEvent event)` Updates document partitioning and document positions according to the specification given by the document event.

### Methods inherited from class org.eclipse.jface.text.AbstractDocument

`acceptPostNotificationReplaces, addDocumentListener, addDocumentPartitioningListener, addDocumentRewriteSessionListener, addPosition, addPosition, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, checkStateOfPartitioner, completeInitialization, computeIndexInCategory, computeIndexInPositionList, computeIndexInPositionList, computeNumberOfLines, computePartitioning, computePartitioning, containsPosition, containsPositionCategory, doFireDocumentChanged, doFireDocumentChanged, doFireDocumentChanged2, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireRewriteSessionChanged, get, get, getActiveRewriteSession, getChar, getContentType, getContentType, getDocumentListeners, getDocumentManagedPositions, getDocumentPartitioner, getDocumentPartitioner, getDocumentPartitioningListeners, getLegalContentTypes, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getModificationStamp, getNumberOfLines, getNumberOfLines, getPartition, getPartition, getPartitionings, getPositionCategories, getPositions, getPositions, getPositionUpdaters, getStore, getTracker, ignorePostNotificationReplaces, insertPositionUpdater, isLineInformationRepairNeeded, removeDocumentListener, removeDocumentPartitioningListener, removeDocumentRewriteSessionListener, removePosition, removePosition, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, repairLineInformation, replace, resumeListenerNotification, resumePostNotificationProcessing, search, set, setDocumentPartitioner, setDocumentPartitioner, setInitialLineDelimiter, setLineTracker, setTextStore, startRewriteSession, startRewriteSessionOnPartitioners, startSequentialRewrite, stopListenerNotification, stopPostNotificationProcessing, stopRewriteSession, stopRewriteSessionOnPartitioners, stopSequentialRewrite, updatePositions`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ProjectionDocument

    public ProjectionDocument​(IDocument masterDocument)

Creates a projection document for the given master document.

Parameters:
  `masterDocument` - the master document

### Method Detail

#### dispose

    public void dispose()

Disposes this projection document.

#### getFragments

    protected final Position[] getFragments()

Returns the fragments of the master documents.

Returns:
  the fragment of the master document

#### getSegments

    protected final Position[] getSegments()

Returns the segments of this projection document.

Returns:
  the segments of this projection document

#### getProjectionMapping

    @Deprecated
    public ProjectionMapping getProjectionMapping()

Deprecated.
As of 3.4, replaced by `getDocumentInformationMapping()`
Returns the projection mapping used by this document.

Returns:
  the projection mapping used by this document

#### getDocumentInformationMapping

    public IDocumentInformationMapping getDocumentInformationMapping()

Returns the projection mapping used by this document.

Returns:
  the projection mapping used by this document
Since:
  3.4

#### getMasterDocument

    public IDocument getMasterDocument()

Returns the master document of this projection document.

Returns:
  the master document of this projection document

#### getDefaultLineDelimiter

    public String getDefaultLineDelimiter()

Description copied from interface: `IDocumentExtension4`
Returns this document's default line delimiter.

This default line delimiter should be used by clients who want unique delimiters (e.g. 'CR's) in the document.

Specified by:
  `getDefaultLineDelimiter` in interface `IDocumentExtension4`
Overrides:
  `getDefaultLineDelimiter` in class `AbstractDocument`
Returns:
  the default line delimiter or `null` if none

#### computeUnprojectedMasterRegions

    public final IRegion[] computeUnprojectedMasterRegions​(int offsetInMaster,
                                                           int lengthInMaster)
                                                    throws BadLocationException

Returns the sequence of all master document regions which are contained in the given master document range and which are not yet part of this projection document.

Parameters:
  `offsetInMaster` - the range offset in the master document
  `lengthInMaster` - the range length in the master document
Returns:
  the sequence of regions which are not yet part of the projection document
Throws:
  `BadLocationException` - in case the given range is invalid in the master document

#### addMasterDocumentRange

    public void addMasterDocumentRange​(int offsetInMaster,
                                       int lengthInMaster)
                                throws BadLocationException

Ensures that the given range of the master document is part of this projection document.

Parameters:
  `offsetInMaster` - the offset of the master document range
  `lengthInMaster` - the length of the master document range
Throws:
  `BadLocationException` - in case the master event is not valid

#### removeMasterDocumentRange

    public void removeMasterDocumentRange​(int offsetInMaster,
                                          int lengthInMaster)
                                   throws BadLocationException

Ensures that the given range of the master document is not part of this projection document.

Parameters:
  `offsetInMaster` - the offset of the master document range
  `lengthInMaster` - the length of the master document range
Throws:
  `BadLocationException` - in case the master event is not valid

#### computeProjectedMasterRegions

    public final IRegion[] computeProjectedMasterRegions​(int offsetInMaster,
                                                         int lengthInMaster)
                                                  throws BadLocationException

Returns the sequence of all master document regions with are contained in the given master document range and which are part of this projection document. May return `null` if no such regions exist.

Parameters:
  `offsetInMaster` - the range offset in the master document
  `lengthInMaster` - the range length in the master document
Returns:
  the sequence of regions which are part of the projection document or `null`
Throws:
  `BadLocationException` - in case the given range is invalid in the master document

#### isUpdating

    protected boolean isUpdating()

Returns whether this projection is being updated.

Returns:
  `true` if the document is updating

#### replace

    public void replace​(int offset,
                        int length,
                        String text)
                 throws BadLocationException

Description copied from interface: `IDocument`
Substitutes the given text for the specified document range. Sends a `DocumentEvent` to all registered `IDocumentListener`.

Specified by:
  `replace` in interface `IDocument`
Overrides:
  `replace` in class `AbstractDocument`
Parameters:
  `offset` - the document offset
  `length` - the length of the specified range
  `text` - the substitution text
Throws:
  `BadLocationException` - if the offset is invalid in this document
See Also:
  `DocumentEvent`, `IDocumentListener`

#### set

    public void set​(String text)

Description copied from interface: `IDocument`
Replaces the content of the document with the given text. Sends a `DocumentEvent` to all registered `IDocumentListener`. This method is a convenience method for `replace(0, getLength(), text)`.

Specified by:
  `set` in interface `IDocument`
Overrides:
  `set` in class `AbstractDocument`
Parameters:
  `text` - the new content of the document
See Also:
  `DocumentEvent`, `IDocumentListener`

#### adaptProjectionToMasterChange

    protected final boolean adaptProjectionToMasterChange​(DocumentEvent masterEvent)
                                                   throws BadLocationException

Ensures that when the master event affects this projection document, that the whole region described by the event is part of this projection document.

Parameters:
  `masterEvent` - the master document event
Returns:
  `true` if masterEvent affects this projection document
Throws:
  `BadLocationException` - in case the master event is not valid

#### masterDocumentAboutToBeChanged

    public void masterDocumentAboutToBeChanged​(DocumentEvent masterEvent)

When called, this projection document is informed about a forthcoming change of its master document. This projection document checks whether the master document change affects it and if so informs all document listeners.

Parameters:
  `masterEvent` - the master document event

#### masterDocumentChanged

    public void masterDocumentChanged​(DocumentEvent masterEvent)

When called, this projection document is informed about a change of its master document. If this projection document is affected it informs all of its document listeners.

Parameters:
  `masterEvent` - the master document event

#### fireDocumentAboutToBeChanged

    protected void fireDocumentAboutToBeChanged​(DocumentEvent event)

Description copied from class: `AbstractDocument`
Fires the given document event to all registers document listeners informing them about the forthcoming document manipulation. Uses a robust iterator.

Overrides:
  `fireDocumentAboutToBeChanged` in class `AbstractDocument`
Parameters:
  `event` - the event to be sent out

#### fireDocumentChanged

    protected void fireDocumentChanged​(DocumentEvent event)

Ignores the given event and sends the semantically equal slave document event instead.

Overrides:
  `fireDocumentChanged` in class `AbstractDocument`
Parameters:
  `event` - the event to be ignored

#### updateDocumentStructures

    protected void updateDocumentStructures​(DocumentEvent event)

Description copied from class: `AbstractDocument`
Updates document partitioning and document positions according to the specification given by the document event.

Overrides:
  `updateDocumentStructures` in class `AbstractDocument`
Parameters:
  `event` - the document event describing the change to which structures must be adapted

#### registerPostNotificationReplace

    public void registerPostNotificationReplace​(IDocumentListener owner,
                                                IDocumentExtension.IReplace replace)

Description copied from interface: `IDocumentExtension`
Callback for document listeners to be used inside `documentChanged` to register a post notification replace operation on the document notifying them.

Specified by:
  `registerPostNotificationReplace` in interface `IDocumentExtension`
Overrides:
  `registerPostNotificationReplace` in class `AbstractDocument`
Parameters:
  `owner` - the owner of the replace operation
  `replace` - the replace operation to be executed

#### setAutoExpandMode

    public void setAutoExpandMode​(boolean autoExpandMode)

Sets the auto expand mode for this document.

Parameters:
  `autoExpandMode` - `true` if auto-expanding

#### replaceMasterDocumentRanges

    public void replaceMasterDocumentRanges​(int offsetInMaster,
                                            int lengthInMaster)
                                     throws BadLocationException

Replaces all master document ranges with the given master document range.

Parameters:
  `offsetInMaster` - the offset in the master document
  `lengthInMaster` - the length in the master document
Throws:
  `BadLocationException` - if the given range of the master document is not valid