|
Eclipse JDT 2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Nodes represent structural fragments of a Java source file, also known as document fragments. Their implementation
is known as a DOM (Document Object Model) - in this case a JDOM (Java DOM). A root node (node
with no parent or siblings) represents the root of a document fragment (DF). A complete Java document is
represented by a compilation unit node (IDOMCompilationUnit
). In this way, a DF is
comprised of DFs, and a document itself (compilation unit) is also a DF.
A DF may be created empty and programmatically filled, or it may be created from
a source code string. The IDOMFactory
allows the creation of all kinds
of nodes from source code strings. Manipulations performed on a DF are immediately
reflected in the DF's contents.
Children fragments are represented as a linked list of nodes. Children are inserted via their parent node, and are automatically linked up with previous and next nodes.
The contents of any node (DF) may be retrieved at any time. In this way it is possible to retrieve source code representing fragments of the compilation unit (for example, a type or a method), since the contents of any node (not just the root node) may be obtained.
The following manipulations on DFs are distinct:
Wherever types are specified in DOM APIs, type names must be specified as they would appear
in source code. The DOM does not have a notion of type signatures, only raw text. Example type
names are "Object"
, "java.io.File"
, and "int[]"
.
This interface is not intended to be implemented by clients.
Field Summary | |
static int |
COMPILATION_UNIT
Node type constant indicating a compilation unit. |
static int |
FIELD
Node type constant indicating a field declaration. |
static int |
IMPORT
Node type constant indicating an import declaration. |
static int |
INITIALIZER
Node type constant indicating an initializer declaration. |
static int |
METHOD
Node type constant indicating a method (or constructor) declaration. |
static int |
PACKAGE
Node type constant indicating a package declaration. |
static int |
TYPE
Node type constant indicating a type declaration. |
Method Summary | |
void |
addChild(IDOMNode child)
Adds the given un-parented node (document fragment) as the last child of this node. |
boolean |
canHaveChildren()
Returns whether this node is allowed to have children. |
Object |
clone()
Returns a stand-alone copy of the document fragment represented by this node that is in no way dependent on the document this node is part of. |
char[] |
getCharacters()
Returns the current contents of this document fragment as a character array. |
IDOMNode |
getChild(String name)
Returns the first named child of this node with the given name. |
Enumeration |
getChildren()
Returns an enumeration of children of this node. |
String |
getContents()
Returns the current contents of this document fragment. |
IDOMNode |
getFirstChild()
Returns the first child of this node. |
IJavaElement |
getJavaElement(IJavaElement parent)
Returns a handle for the Java element associated with this document fragment, based on the parent Java element. |
String |
getName()
Returns the name of this node. |
IDOMNode |
getNextNode()
Returns the sibling node immediately following this node. |
int |
getNodeType()
Returns the type of this node. |
IDOMNode |
getParent()
Returns the parent of this node. |
IDOMNode |
getPreviousNode()
Returns the sibling node immediately preceding this node. |
void |
insertSibling(IDOMNode sibling)
Inserts the given un-parented node as a sibling of this node, immediately before this node. |
boolean |
isAllowableChild(IDOMNode node)
Returns whether the given node is an allowable child for this node. |
boolean |
isSignatureEqual(IDOMNode node)
Returns whether this node's signature is equivalent to the given node's signature. |
void |
remove()
Separates this node from its parent and siblings, maintaining any ties that this node has to the underlying document fragment. |
void |
setName(String name)
Sets the name of this node. |
Field Detail |
public static final int COMPILATION_UNIT
IDOMCompilationUnit
.getNodeType()
public static final int PACKAGE
IDOMPackage
.getNodeType()
public static final int IMPORT
IDOMImport
.getNodeType()
public static final int TYPE
IDOMType
.getNodeType()
public static final int FIELD
IDOMField
.getNodeType()
public static final int METHOD
IDOMMethod
.getNodeType()
public static final int INITIALIZER
IDOMInitializer
.getNodeType()
Method Detail |
public void addChild(IDOMNode child) throws DOMException, IllegalArgumentException
child
- the new child nodeDOMException
- if any of the following conditions hold:IllegalArgumentException
- if the child is null
insertSibling(org.eclipse.jdt.core.jdom.IDOMNode)
,
remove()
public boolean canHaveChildren()
true
if this node can have childrenpublic Object clone()
clone
in class Object
IDOMNode
addChild(org.eclipse.jdt.core.jdom.IDOMNode)
,
insertSibling(org.eclipse.jdt.core.jdom.IDOMNode)
,
remove()
public char[] getCharacters()
Note: To obtain complete source for the ".java" file, ask a compilation unit node for its contents.
null
if this node has no contentspublic IDOMNode getChild(String name)
name
- the namenull
if no such child existspublic Enumeration getChildren()
public String getContents()
Note: To obtain complete source for the ".java" file, ask a compilation unit node for its contents.
null
if this node has no contentspublic IDOMNode getFirstChild()
null
if this node has no childrengetChildren()
public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException
parent
- the parent Java elementIllegalArgumentException
- if the parent element is not
of a valid parent type for this nodepublic String getName()
null
if it has no namepublic IDOMNode getNextNode()
null
if there is no following nodepublic int getNodeType()
IDOMNode
public IDOMNode getParent()
null
if this node does not have a
parentpublic IDOMNode getPreviousNode()
null
if there is no preceding nodepublic void insertSibling(IDOMNode sibling) throws DOMException, IllegalArgumentException
sibling
- the new sibling nodeDOMException
- if any of the following conditions hold:IllegalArgumentException
- if the sibling is null
addChild(org.eclipse.jdt.core.jdom.IDOMNode)
,
clone()
,
remove()
public boolean isAllowableChild(IDOMNode node)
node
- the potential child nodetrue
if the given node is an allowable childpublic boolean isSignatureEqual(IDOMNode node)
node
- the other nodetrue
if the nodes have equivalent signaturespublic void remove()
addChild(org.eclipse.jdt.core.jdom.IDOMNode)
,
clone()
,
insertSibling(org.eclipse.jdt.core.jdom.IDOMNode)
public void setName(String name)
name
- the name, or null
to clear the name
|
Eclipse JDT 2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |