|
Eclipse Platform Release 3.6 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.compare.structuremergeviewer.DocumentRangeNode
public class DocumentRangeNode
A document range node represents a structural element
when performing a structure compare of documents.
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.
Differencer| Field Summary |
|---|
| Fields inherited from interface org.eclipse.compare.contentmergeviewer.IDocumentRange |
|---|
RANGE_CATEGORY |
| Constructor Summary | |
|---|---|
DocumentRangeNode(DocumentRangeNode parent,
int typeCode,
java.lang.String id,
IDocument document,
int start,
int length)
Creates a new DocumentRangeNode for the given range within the specified
document. |
|
DocumentRangeNode(int typeCode,
java.lang.String id,
IDocument document,
int start,
int length)
Creates a new DocumentRangeNode for the given range within the specified
document. |
|
| Method Summary | |
|---|---|
void |
addChild(DocumentRangeNode node)
Adds the given node as a child. |
boolean |
equals(java.lang.Object other)
Implementation based on getID. |
java.lang.Object |
getAdapter(java.lang.Class adapter)
Implement IAdaptable.getAdapter(Class) in order to provide
an ISharedDocumentAdapter that provides the proper look up key based
on the input from which this structure node was created. |
Position |
getAppendPosition()
Returns the position that has been set with setAppendPosition. |
java.lang.String |
getCharset()
Returns the name of a charset encoding to be used when decoding this stream accessor's contents into characters. |
java.lang.Object[] |
getChildren()
Returns an iterator for all children of this object or null
if there are no children. |
java.io.InputStream |
getContents()
Returns an open InputStream for this object which can be used to retrieve the object's content. |
IDocument |
getDocument()
Returns the underlying document. |
java.lang.String |
getId()
Returns this node's id. |
java.lang.Object |
getParentNode()
Return the parent of this node or null
if the node doesn't have a parent or the parent is not known. |
Position |
getRange()
Returns a position that specifies a subrange in the underlying document, or null if this document range spans the whole underlying document. |
int |
getTypeCode()
Returns the type code of this node. |
int |
hashCode()
Implementation based on getID. |
protected void |
internalSetContents(byte[] content)
Method that is invoked from setContent(byte[]). |
boolean |
isEditable()
If this node has a parent, return the editability of the parent. |
boolean |
isReadOnly()
Return 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 void |
nodeChanged(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. |
ITypedElement |
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. |
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. |
void |
setContent(byte[] content)
Default implementation that calls internalSetContents(byte[])
and then nodeChanged(DocumentRangeNode). |
void |
setId(java.lang.String id)
Sets this node's id. |
void |
setLength(int length)
Sets the length of the range of this node. |
IStatus |
validateEdit(Shell shell)
If the element is read-only, this method should be called to attempt to make it writable. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DocumentRangeNode(int typeCode,
java.lang.String id,
IDocument document,
int start,
int length)
DocumentRangeNode for the given range within the specified
document. The typeCode is 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.
typeCode - a type code for this nodeid - an identifier for this nodedocument - document on which this node is based onstart - start position of range within documentlength - length of range
public DocumentRangeNode(DocumentRangeNode parent,
int typeCode,
java.lang.String id,
IDocument document,
int start,
int length)
DocumentRangeNode for the given range within the specified
document. The typeCode is 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.
parent - the parent nodetypeCode - a type code for this nodeid - an identifier for this nodedocument - document on which this node is based onstart - start position of range within documentlength - length of range| Method Detail |
|---|
public IDocument getDocument()
IDocumentRange
getDocument in interface IDocumentRangepublic Position getRange()
IDocumentRangenull if this document range spans the whole underlying document.
getRange in interface IDocumentRangenullpublic int getTypeCode()
public java.lang.String getId()
equals and hashcode.
public void setId(java.lang.String id)
equals and hashcode.
id - the new id for this nodepublic void addChild(DocumentRangeNode node)
node - the node to add as a childpublic java.lang.Object[] getChildren()
IStructureComparatornull
if there are no children.
getChildren in interface IStructureComparatorpublic void setLength(int length)
length - the length of the rangepublic void setAppendPosition(int pos)
E.g. when parsing a Java document the "append position" of a DocumentRangeNode
representing 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.
pos - the character position within the underlying document where text can be legally insertedpublic Position getAppendPosition()
setAppendPosition.
If setAppendPosition hasn't been called, the position after the last character
of this range is returned. This method will return null if the position
could not be registered with the document.
public boolean equals(java.lang.Object other)
getID.
equals in interface IStructureComparatorequals in class java.lang.Objectother - the object to compare this DocumentRangeNode against.
true if the DocumentRangeNodesare equal; false otherwise.Object.equals(java.lang.Object)public int hashCode()
getID.
hashCode in class java.lang.Objectpublic java.io.InputStream getContents()
IStreamContentAccessorInputStream for this object which can be used to retrieve the object's content.
The client is responsible for closing the stream when finished.
Returns null if this object has no streamable contents.
getContents in interface IStreamContentAccessorpublic boolean isEditable()
true. Subclasses may override.
isEditable in interface IEditableContenttrue if this object can be modifiedIEditableContent.isEditable()
public ITypedElement replace(ITypedElement child,
ITypedElement other)
IEditableContent| add: | dest == null | src != null |
| remove: | dest != null | src == null |
| copy: | dest != null | src != null |
replace in interface IEditableContentchild - the existing child of this object to be replaced; if null a new child can be added.other - the new child to be added or replaced; if null an existing child can be removed.
destpublic void setContent(byte[] content)
internalSetContents(byte[])
and then nodeChanged(DocumentRangeNode). Subclasses
may override but should then call nodeChanged(DocumentRangeNode)
after the contents have been set.
setContent in interface IEditableContentcontent - this new contents replaces the old contentsIEditableContent.setContent(byte[])protected void internalSetContents(byte[] content)
setContent(byte[]). By default,
this method does nothing. Subclasses may override.
content - the new contentpublic java.lang.String getCharset()
IEncodedStreamContentAccessornull if 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
UnsupportedEncodingException where this charset is used.
getCharset in interface IEncodedStreamContentAccessornullIStreamContentAccessor.getContents()protected void nodeChanged(DocumentRangeNode node)
node - the node that has changed.public java.lang.Object getAdapter(java.lang.Class adapter)
IAdaptable.getAdapter(Class) in order to provide
an ISharedDocumentAdapter that 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 calling getAdapter(Class)
on this node's parent if there is one.
getAdapter in interface IAdaptableadapter - the adapter class to look up
nullIAdaptable.getAdapter(Class)public boolean isReadOnly()
IEditableContentExtension
isReadOnly in interface IEditableContentExtensionpublic IStatus validateEdit(Shell shell)
IEditableContentExtension
validateEdit in interface IEditableContentExtensionshell - a shell used to prompt the user if required.
OK if things are fine,
otherwise a status describing reasons why modifying the given files is not
reasonable. A status with a severity of CANCEL is returned
if the validation was canceled, indicating the edit should not proceed.public java.lang.Object getParentNode()
null
if the node doesn't have a parent or the parent is not known.
null
|
Eclipse Platform Release 3.6 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2010. All rights reserved.