Class DocumentRangeNode
- All Implemented Interfaces:
- IDocumentRange,- IEditableContent,- IEditableContentExtension,- IEncodedStreamContentAccessor,- IStreamContentAccessor,- IStructureComparator,- IAdaptable
- Direct Known Subclasses:
- StructureRootNode
DocumentRangeNodes are created while parsing the document and represent
 a semantic entity (e.g. a Java class or method).
 As a consequence of the parsing a DocumentRangeNode maps to a range
 of characters in the document.
 
 Since a DocumentRangeNode implements the IStructureComparator
 and IStreamContentAccessor interfaces it can be used as input to the
 differencing engine. This makes it possible to perform
 a structural diff on a document and have the nodes and leaves of the compare easily map
 to character ranges within the document.
 
 Clients need to be aware that this node registers position updaters with the document
 using IDocument.addPosition(String, Position) with the category set to
 IDocumentRange.RANGE_CATEGORY. The StructureDiffViewer will
 remove the category when the nodes are no longer being used. Other clients
 must do the same.
 
Subclasses may add additional state collected while parsing the document.
- See Also:
- 
Field SummaryFields inherited from interface org.eclipse.compare.contentmergeviewer.IDocumentRangeRANGE_CATEGORY
- 
Constructor SummaryConstructorsConstructorDescriptionDocumentRangeNode(int typeCode, String id, IDocument document, int start, int length) Creates a newDocumentRangeNodefor the given range within the specified document.DocumentRangeNode(DocumentRangeNode parent, int typeCode, String id, IDocument document, int start, int length) Creates a newDocumentRangeNodefor the given range within the specified document.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddChild(DocumentRangeNode node) Adds the given node as a child.booleanImplementation based ongetID.<T> TgetAdapter(Class<T> adapter) ImplementIAdaptable.getAdapter(Class)in order to provide anISharedDocumentAdapterthat provides the proper look up key based on the input from which this structure node was created.Returns the position that has been set withsetAppendPosition.Returns the name of a charset encoding to be used when decoding this stream accessor's contents into characters.Object[]Returns an iterator for all children of this object ornullif there are no children.Returns an openInputStreamfor this object which can be used to retrieve the object's content.Returns the underlying document.getId()Returns this node's id.Return the parent of this node ornullif the node doesn't have a parent or the parent is not known.getRange()Returns a position that specifies a subrange in the underlying document, ornullif this document range spans the whole underlying document.intReturns the type code of this node.inthashCode()Implementation based ongetID.protected voidinternalSetContents(byte[] content) Method that is invoked fromsetContent(byte[]).booleanIf this node has a parent, return the editability of the parent.booleanReturn whether the typed element being displayed is read-only. a read-only element will require a call to validateEdit before the element can be modified on disk.protected voidnodeChanged(DocumentRangeNode node) Method that should be invoked whenever the contents of this node are changed. the change is propagated to the parent if there is one.replace(ITypedElement child, ITypedElement other) This method is called on a parent to add or remove a child, or to copy the contents of a child.voidsetAppendPosition(int pos) Sets a position within the document range that can be used to (legally) insert text without breaking the syntax of the document.voidsetContent(byte[] content) Default implementation that callsinternalSetContents(byte[])and thennodeChanged(DocumentRangeNode).voidSets this node's id.voidsetLength(int length) Sets the length of the range of this node.validateEdit(Shell shell) If the element is read-only, this method should be called to attempt to make it writable.
- 
Constructor Details- 
DocumentRangeNodeCreates a newDocumentRangeNodefor the given range within the specified document. ThetypeCodeis uninterpreted client data. The ID is used when comparing two nodes with each other: i.e. the differencing engine performs a content compare on two nodes if their IDs are equal.- Parameters:
- typeCode- a type code for this node
- id- an identifier for this node
- document- document on which this node is based on
- start- start position of range within document
- length- length of range
 
- 
DocumentRangeNodepublic DocumentRangeNode(DocumentRangeNode parent, int typeCode, String id, IDocument document, int start, int length) Creates a newDocumentRangeNodefor the given range within the specified document. ThetypeCodeis uninterpreted client data. The ID is used when comparing two nodes with each other: i.e. the differencing engine performs a content compare on two nodes if their IDs are equal.- Parameters:
- parent- the parent node
- typeCode- a type code for this node
- id- an identifier for this node
- document- document on which this node is based on
- start- start position of range within document
- length- length of range
- Since:
- 3.3
 
 
- 
- 
Method Details- 
getDocumentDescription copied from interface:IDocumentRangeReturns the underlying document.- Specified by:
- getDocumentin interface- IDocumentRange
- Returns:
- the underlying document
 
- 
getRangeDescription copied from interface:IDocumentRangeReturns a position that specifies a subrange in the underlying document, ornullif this document range spans the whole underlying document.- Specified by:
- getRangein interface- IDocumentRange
- Returns:
- a position that specifies a subrange in the underlying document, or null
 
- 
getTypeCodepublic int getTypeCode()Returns the type code of this node. The type code is uninterpreted client data which can be set in the constructor.- Returns:
- the type code of this node
 
- 
getIdReturns this node's id. It is used inequalsandhashcode.- Returns:
- the node's id
 
- 
setIdSets this node's id. It is used inequalsandhashcode.- Parameters:
- id- the new id for this node
 
- 
addChildAdds the given node as a child.- Parameters:
- node- the node to add as a child
 
- 
getChildrenDescription copied from interface:IStructureComparatorReturns an iterator for all children of this object ornullif there are no children.- Specified by:
- getChildrenin interface- IStructureComparator
- Returns:
- an array with all children of this object, or an empty array if there are no children
 
- 
setLengthpublic void setLength(int length) Sets the length of the range of this node.- Parameters:
- length- the length of the range
 
- 
setAppendPositionpublic void setAppendPosition(int pos) Sets a position within the document range that can be used to (legally) insert text without breaking the syntax of the document.E.g. when parsing a Java document the "append position" of a DocumentRangeNoderepresenting a Java class could be the character position just before the closing bracket. Inserting the text of a new method there would not disturb the syntax of the class.- Parameters:
- pos- the character position within the underlying document where text can be legally inserted
 
- 
getAppendPositionReturns the position that has been set withsetAppendPosition. IfsetAppendPositionhasn't been called, the position after the last character of this range is returned. This method will returnnullif the position could not be registered with the document.- Returns:
- a position where text can be legally inserted
 
- 
equalsImplementation based ongetID.- Specified by:
- equalsin interface- IStructureComparator
- Overrides:
- equalsin class- Object
- Parameters:
- other- the object to compare this- DocumentRangeNodeagainst.
- Returns:
- trueif the- DocumentRangeNodesare equal;- falseotherwise.
- See Also:
 
- 
hashCodepublic int hashCode()Implementation based ongetID.
- 
getContentsDescription copied from interface:IStreamContentAccessorReturns an openInputStreamfor this object which can be used to retrieve the object's content. The client is responsible for closing the stream when finished. Returnsnullif this object has no streamable contents.- Specified by:
- getContentsin interface- IStreamContentAccessor
- Returns:
- an input stream containing the contents of this object
 
- 
isEditablepublic boolean isEditable()If this node has a parent, return the editability of the parent. Otherwise returntrue. Subclasses may override.- Specified by:
- isEditablein interface- IEditableContent
- Returns:
- trueif this object can be modified
- See Also:
 
- 
replaceDescription copied from interface:IEditableContentThis method is called on a parent to add or remove a child, or to copy the contents of a child. What to do is encoded in the two arguments as follows:add: dest == null src != null remove: dest != null src == null copy: dest != null src != null - Specified by:
- replacein interface- IEditableContent
- Parameters:
- child- the existing child of this object to be replaced; if- nulla new child can be added.
- other- the new child to be added or replaced; if- nullan existing child can be removed.
- Returns:
- the argument dest
 
- 
setContentpublic void setContent(byte[] content) Default implementation that callsinternalSetContents(byte[])and thennodeChanged(DocumentRangeNode). Subclasses may override but should then callnodeChanged(DocumentRangeNode)after the contents have been set.- Specified by:
- setContentin interface- IEditableContent
- Parameters:
- content- this new contents replaces the old contents
- See Also:
 
- 
internalSetContentsprotected void internalSetContents(byte[] content) Method that is invoked fromsetContent(byte[]). By default, this method does nothing. Subclasses may override.- Parameters:
- content- the new content
- Since:
- 3.3
 
- 
getCharsetDescription copied from interface:IEncodedStreamContentAccessorReturns the name of a charset encoding to be used when decoding this stream accessor's contents into characters. Returnsnullif a proper encoding cannot be determined.Note: this method does not check whether the result is a supported charset name. Callers should be prepared to handle UnsupportedEncodingExceptionwhere this charset is used.- Specified by:
- getCharsetin interface- IEncodedStreamContentAccessor
- Returns:
- the name of a charset, or null
- See Also:
 
- 
nodeChangedMethod that should be invoked whenever the contents of this node are changed. the change is propagated to the parent if there is one.- Parameters:
- node- the node that has changed.
- Since:
- 3.3
 
- 
getAdapterImplementIAdaptable.getAdapter(Class)in order to provide anISharedDocumentAdapterthat provides the proper look up key based on the input from which this structure node was created. The proper shared document adapter is obtained by callinggetAdapter(Class)on this node's parent if there is one.- Specified by:
- getAdapterin interface- IAdaptable
- Type Parameters:
- T- the class type
- Parameters:
- adapter- the adapter class to look up
- Returns:
- the object adapted to the given class or null
- Since:
- 3.3
- See Also:
 
- 
isReadOnlypublic boolean isReadOnly()Description copied from interface:IEditableContentExtensionReturn whether the typed element being displayed is read-only. a read-only element will require a call to validateEdit before the element can be modified on disk.- Specified by:
- isReadOnlyin interface- IEditableContentExtension
- Returns:
- whether the typed element is read-only
 
- 
validateEditDescription copied from interface:IEditableContentExtensionIf the element is read-only, this method should be called to attempt to make it writable.- Specified by:
- validateEditin interface- IEditableContentExtension
- Parameters:
- shell- a shell used to prompt the user if required.
- Returns:
- a status object that is OKif things are fine, otherwise a status describing reasons why modifying the given files is not reasonable. A status with a severity ofCANCELis returned if the validation was canceled, indicating the edit should not proceed.
 
- 
getParentNodeReturn the parent of this node ornullif the node doesn't have a parent or the parent is not known.- Returns:
- the parent of this node or null
 
 
-