Class ElementNode

java.lang.Object
com.puppycrawl.tools.checkstyle.xpath.AbstractNode
com.puppycrawl.tools.checkstyle.xpath.ElementNode
All Implemented Interfaces:
Source, SourceLocator, net.sf.saxon.om.GroundedValue, net.sf.saxon.om.Item, net.sf.saxon.om.NodeInfo, net.sf.saxon.om.Sequence, net.sf.saxon.s9api.Location, Locator

public class ElementNode extends AbstractNode
Represents element node of Xpath-tree.
  • Field Details

    • TEXT_ATTRIBUTE_NAME

      private static final String TEXT_ATTRIBUTE_NAME
      String literal for text attribute.
      See Also:
    • EMPTY_ABSTRACT_NODE_ARRAY

      private static final AbstractNode[] EMPTY_ABSTRACT_NODE_ARRAY
      Constant for optimization.
    • ATTRIBUTE_NODE_UNINITIALIZED

      private static final AttributeNode ATTRIBUTE_NODE_UNINITIALIZED
      Holder value for lazy creation of attribute node.
    • root

      private final AbstractNode root
      The root node.
    • parent

      private final AbstractNode parent
      The parent of the current node.
    • detailAst

      private final DetailAST detailAst
      The ast node.
    • depth

      private final int depth
      Depth of the node.
    • indexAmongSiblings

      private final int indexAmongSiblings
      Represents index among siblings.
    • attributeNode

      private AttributeNode attributeNode
      The text attribute node.
  • Constructor Details

    • ElementNode

      public ElementNode(AbstractNode root, AbstractNode parent, DetailAST detailAst, int depth, int indexAmongSiblings)
      Creates a new ElementNode instance.
      Parameters:
      root - Node root of the tree
      parent - Node parent of the current node
      detailAst - reference to DetailAST
      depth - the current node depth in the hierarchy
      indexAmongSiblings - the current node index among the parent children nodes
  • Method Details

    • compareOrder

      public int compareOrder(net.sf.saxon.om.NodeInfo other)
      Compares current object with specified for order.
      Parameters:
      other - another NodeInfo object
      Returns:
      number representing order of current object to specified one
    • compareCommonAncestorChildrenOrder

      private static int compareCommonAncestorChildrenOrder(net.sf.saxon.om.NodeInfo first, net.sf.saxon.om.NodeInfo second)
      Walks up the hierarchy until a common ancestor is found. Then compares topmost sibling nodes.
      Parameters:
      first - NodeInfo to compare
      second - NodeInfo to compare
      Returns:
      the value 0 if first == second; a value less than 0 if first should be first; a value greater than 0 if second should be first.
    • getDepth

      public int getDepth()
      Getter method for node depth.
      Specified by:
      getDepth in class AbstractNode
      Returns:
      depth
    • createChildren

      protected List<AbstractNode> createChildren()
      Iterates children of the current node and recursively creates new Xpath-nodes.
      Specified by:
      createChildren in class AbstractNode
      Returns:
      children list
    • hasChildNodes

      public boolean hasChildNodes()
      Determine whether the node has any children.
      Returns:
      true is the node has any children.
    • getAttributeValue

      public String getAttributeValue(String namespace, String localPart)
      Returns attribute value. Throws UnsupportedOperationException in case, when name of the attribute is not equal to 'text'.
      Parameters:
      namespace - namespace
      localPart - actual name of the attribute
      Returns:
      attribute value
    • getLocalPart

      public String getLocalPart()
      Returns local part.
      Returns:
      local part
    • getNodeKind

      public int getNodeKind()
      Returns type of the node.
      Returns:
      node kind
    • getParent

      public net.sf.saxon.om.NodeInfo getParent()
      Returns parent.
      Returns:
      parent
    • getRoot

      public net.sf.saxon.om.NodeInfo getRoot()
      Returns root.
      Returns:
      root
    • iterateAxis

      public net.sf.saxon.tree.iter.AxisIterator iterateAxis(int axisNumber)
      Determines axis iteration algorithm. Throws UnsupportedOperationException in case, when there is no axis iterator for given axisNumber.

      Reason of suppression for resource, IOResourceOpenedButNotSafelyClosed: AxisIterator implements Closeable interface, but none of the subclasses of the AxisIterator class has non-empty close() method.

      Parameters:
      axisNumber - element from AxisInfo
      Returns:
      AxisIterator object
    • getLineNumber

      public int getLineNumber()
      Returns line number.
      Returns:
      line number
    • getColumnNumber

      public int getColumnNumber()
      Returns column number.
      Returns:
      column number
    • getTokenType

      public int getTokenType()
      Getter method for token type.
      Specified by:
      getTokenType in class AbstractNode
      Returns:
      token type
    • getUnderlyingNode

      public DetailAST getUnderlyingNode()
      Returns underlying node.
      Specified by:
      getUnderlyingNode in class AbstractNode
      Returns:
      underlying node
    • getPrecedingSiblingsIterator

      private net.sf.saxon.tree.iter.AxisIterator getPrecedingSiblingsIterator()
      Returns preceding sibling axis iterator.

      Reason of suppression for resource, IOResourceOpenedButNotSafelyClosed: AxisIterator implements Closeable interface, but none of the subclasses of the AxisIterator class has non-empty close() method.

      Returns:
      iterator
    • getFollowingSiblingsIterator

      private net.sf.saxon.tree.iter.AxisIterator getFollowingSiblingsIterator()
      Returns following sibling axis iterator.

      Reason of suppression for resource, IOResourceOpenedButNotSafelyClosed: AxisIterator implements Closeable interface, but none of the subclasses of the AxisIterator class has non-empty close() method.

      Returns:
      iterator
    • getFollowingSiblings

      private List<AbstractNode> getFollowingSiblings()
      Returns following siblings of the current node.
      Returns:
      siblings
    • getPrecedingSiblings

      private List<AbstractNode> getPrecedingSiblings()
      Returns preceding siblings of the current node.
      Returns:
      siblings
    • getAttributeNode

      private AttributeNode getAttributeNode()
      Checks if token type supports @text attribute, extracts its value, creates AttributeNode object and returns it. Value can be accessed using @text attribute.
      Returns:
      attribute node if possible, otherwise the null value
    • throwUnsupportedOperationException

      private static UnsupportedOperationException throwUnsupportedOperationException()
      Returns UnsupportedOperationException exception.
      Returns:
      UnsupportedOperationException exception