public class Xnode
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
LHS |
static int |
RHS |
static int |
UNDEF_DEPTH |
Constructor and Description |
---|
Xnode(org.w3c.dom.Element element)
Constructs an Xnode object from an element in the AST.
|
Modifier and Type | Method and Description |
---|---|
Xnode |
ancestor()
Get ancestor node if any.
|
void |
append(Xnode node)
Append an element ot the children of this element.
|
void |
append(Xnode node,
boolean clone)
Append an element ot the children of this element.
|
Xnode |
body()
Get the inner body element.
|
Xnode |
child(int pos)
Get child at position.
|
java.util.List<Xnode> |
children()
Get the list of child elements.
|
Xnode |
cloneNode()
Clone the current element with all its children.
|
org.w3c.dom.Node |
cloneRawNode()
Create an identical copy of the element and its children.
|
boolean |
compareFirstChildValues(Xnode other)
Compare the inner value of the first child of two nodes.
|
boolean |
compareOptionalValues(Xnode other)
Compare the inner values of two optional nodes.
|
boolean |
compareValues(Xnode other)
Compare the inner values of two nodes.
|
java.lang.String |
constructRepresentation(boolean withNamedValue)
Construct string representation of the node.
|
void |
copyAttribute(Xnode to,
Xattr attr)
Copy the attribute from the current node to the given node.
|
void |
copyEnhancedInfo(Xnode target)
Copy the enhanced information from the current node to a target node.
|
void |
delete()
Delete the stored root element and all its children.
|
void |
deleteWithSiblings()
Delete this nodes with all its siblings.
|
int |
depth()
Get the depth of the node in the AST.
|
org.w3c.dom.Element |
element()
Get the base element.
|
boolean |
equals(java.lang.Object o) |
java.lang.String |
filename()
Get the file attribute value.
|
FfunctionDefinition |
findParentFunction()
Find function definition in the ancestor of the current node.
|
FmoduleDefinition |
findParentModule()
Find module definition node in which the current node is nested if any.
|
Xnode |
firstChild()
Get the first child node.
|
java.lang.String |
getAttribute(Xattr attrCode)
Get the attribute's value.
|
boolean |
getBooleanAttribute(Xattr attrCode)
Get boolean value of an attribute.
|
java.lang.String |
getType()
Return type hash associated with this node if any.
|
boolean |
hasAttribute(Xattr attrCode)
Check whether the element has the corresponding attribute.
|
boolean |
hasBody()
Check whether the current element is an element with body element.
|
int |
hashCode() |
boolean |
hasSameParentBlock(Xnode n)
Check if the given node is direct children of the same parent node.
|
void |
insert(Xnode node)
Insert as first child.
|
void |
insert(Xnode node,
boolean clone)
Insert as first child.
|
void |
insertAfter(Xnode node)
Insert a node just after this node.
|
void |
insertBefore(Xnode node)
Insert a node just before this node.
|
boolean |
isDeleted()
Check whether the node has been deleted.
|
boolean |
isDirectSibling(Xnode end,
java.util.List<Xcode> skippedNodes)
Check whether the end node is a direct sibling of this node.
|
boolean |
isNestedIn(Xnode ancestor)
Check whether a node is nested into another one.
|
Xnode |
lastChild()
Get the last child node.
|
int |
lineNo()
Get the lineno attribute value.
|
java.util.List<Xnode> |
matchAll(Xcode opcode)
Match all nodes with the given opcode in the subtree.
|
java.util.List<Xnode> |
matchAllAncestor(Xcode opcode)
Find nodes with the given opcode in the ancestors of the current node.
|
java.util.List<Xnode> |
matchAllAncestor(Xcode opcode,
Xcode stopCode)
Find nodes with the given opcode in the ancestors of the current node.
|
Xnode |
matchAncestor(Xcode opcode)
Find node with the given opcode in the ancestors of the current node.
|
Xnode |
matchDescendant(Xcode opcode)
Find node with the given opcode in the descendants of the current node.
|
Xnode |
matchDirectDescendant(java.util.List<Xcode> opcodes)
Find node with one of the given opcodes in the direct descendants
the current node.
|
Xnode |
matchDirectDescendant(Xcode opcode)
Find node with the given opcode in the direct descendants the current node.
|
Xnode |
matchSeq(Xcode... opcodes)
Find node with the given path of opcodes from the current node.
|
Xnode |
matchSibling(Xcode opcode)
Find node with the given opcode in the siblings of the given node.
|
Xnode |
nextSibling()
Get next sibling node.
|
Xcode |
opcode()
Get the element opcode.
|
Xnode |
prevSibling()
Get previous sibling node.
|
void |
removeAttribute(Xattr attrCode)
Remove an attribute from the node.
|
void |
setAttribute(Xattr attrCode,
java.lang.String value)
Set attribute value.
|
void |
setBooleanAttribute(Xattr attrCode,
boolean value)
Set the value of a boolean attribute.
|
void |
setFilename(java.lang.String value)
Set the file attribute of the element.
|
void |
setLine(int lineno)
Set the lineno attribute in the element.
|
void |
setType(java.lang.String value)
Set the type of the current node.
|
void |
setValue(java.lang.String value)
Set the element value.
|
java.lang.String |
toString()
Return a brief description of the Xnode.
|
java.lang.String |
value()
Get raw node value.
|
public static final int LHS
public static final int RHS
public static final int UNDEF_DEPTH
public Xnode(org.w3c.dom.Element element)
element
- Base element for the Xnode object.public void deleteWithSiblings()
public Xcode opcode()
public boolean hasAttribute(Xattr attrCode)
attrCode
- Attribute code.public java.lang.String getAttribute(Xattr attrCode)
attrCode
- Attribute code.public boolean getBooleanAttribute(Xattr attrCode)
attrCode
- Attribute code.public java.lang.String value()
public void setValue(java.lang.String value)
value
- The element value.public void setBooleanAttribute(Xattr attrCode, boolean value)
attrCode
- Attribute code.value
- Boolean value to set.public void setAttribute(Xattr attrCode, java.lang.String value)
attrCode
- Attribute code.value
- Value of the attribute.public void removeAttribute(Xattr attrCode)
attrCode
- Attribute code.public boolean hasBody()
public Xnode body()
public Xnode child(int pos)
pos
- Position of the child.public java.util.List<Xnode> children()
public Xnode firstChild()
public Xnode lastChild()
public void delete()
public boolean isDeleted()
public org.w3c.dom.Element element()
public void append(Xnode node, boolean clone)
node
- The element to append.clone
- If true, the element is cloned before being appended. If
false, the element is directly appended.public void append(Xnode node)
node
- The element to append.public void insert(Xnode node, boolean clone)
node
- Node to be inserted.clone
- Clone or not the element before insertion.public void insert(Xnode node)
node
- Node to be inserted.public void setLine(int lineno)
lineno
- Line number.public int lineNo()
public java.lang.String filename()
public void setFilename(java.lang.String value)
value
- File path.public Xnode cloneNode()
public org.w3c.dom.Node cloneRawNode()
public Xnode nextSibling()
public Xnode ancestor()
public Xnode prevSibling()
public boolean isDirectSibling(Xnode end, java.util.List<Xcode> skippedNodes)
end
- Node to be check to be a direct sibling.skippedNodes
- List of opcode that are allowed between the two nodes.public Xnode matchAncestor(Xcode opcode)
opcode
- Opcode of the node to be matched.public Xnode matchSibling(Xcode opcode)
opcode
- Opcode of the node to be matched.public java.util.List<Xnode> matchAllAncestor(Xcode opcode)
opcode
- Opcode of the node to be matched.public java.util.List<Xnode> matchAllAncestor(Xcode opcode, Xcode stopCode)
opcode
- Opcode of the node to be matched.stopCode
- Stop searching if given opcode is reached. If null, search
until root node.public Xnode matchDescendant(Xcode opcode)
opcode
- Opcode of the node to be matched.public Xnode matchDirectDescendant(Xcode opcode)
opcode
- Opcode of the node to be matched.public Xnode matchDirectDescendant(java.util.List<Xcode> opcodes)
opcodes
- List of opcodes to be searched.public Xnode matchSeq(Xcode... opcodes)
opcodes
- Sequence of opcode to reach the node.public java.util.List<Xnode> matchAll(Xcode opcode)
opcode
- Opcode of the nodes to be matched.public int depth()
public void insertAfter(Xnode node)
node
- The node to be inserted after the current one.public boolean compareFirstChildValues(Xnode other)
other
- Node to compare withpublic boolean compareOptionalValues(Xnode other)
other
- Node to compare withpublic boolean compareValues(Xnode other)
other
- Node to compare withpublic void insertBefore(Xnode node)
node
- The node to be inserted before the current one.public FmoduleDefinition findParentModule()
public boolean isNestedIn(Xnode ancestor)
ancestor
- Node in which the current node is supposed to be nested.public java.lang.String getType()
public void setType(java.lang.String value)
value
- Type value.public java.lang.String constructRepresentation(boolean withNamedValue)
withNamedValue
- If true, keeps the named value, otherwise, just
constructs the argument.public void copyEnhancedInfo(Xnode target)
target
- Target node to copy information to.public boolean hasSameParentBlock(Xnode n)
n
- Node to be compared to.public FfunctionDefinition findParentFunction()
public void copyAttribute(Xnode to, Xattr attr)
to
- Xnode to copy to.attr
- Attribute code to be copied.public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object