Coverage Report - com.puppycrawl.tools.checkstyle.xpath.AbstractNode
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractNode
100%
38/38
100%
6/6
1.706
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2017 the original author or authors.
 4  
 //
 5  
 // This library is free software; you can redistribute it and/or
 6  
 // modify it under the terms of the GNU Lesser General Public
 7  
 // License as published by the Free Software Foundation; either
 8  
 // version 2.1 of the License, or (at your option) any later version.
 9  
 //
 10  
 // This library is distributed in the hope that it will be useful,
 11  
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // Lesser General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU Lesser General Public
 16  
 // License along with this library; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 ////////////////////////////////////////////////////////////////////////////////
 19  
 
 20  
 package com.puppycrawl.tools.checkstyle.xpath;
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Collections;
 24  
 import java.util.List;
 25  
 
 26  
 import com.puppycrawl.tools.checkstyle.api.DetailAST;
 27  
 import net.sf.saxon.Configuration;
 28  
 import net.sf.saxon.event.Receiver;
 29  
 import net.sf.saxon.expr.parser.Location;
 30  
 import net.sf.saxon.om.AtomicSequence;
 31  
 import net.sf.saxon.om.Item;
 32  
 import net.sf.saxon.om.NamespaceBinding;
 33  
 import net.sf.saxon.om.NodeInfo;
 34  
 import net.sf.saxon.om.SequenceIterator;
 35  
 import net.sf.saxon.om.TreeInfo;
 36  
 import net.sf.saxon.pattern.NodeTest;
 37  
 import net.sf.saxon.tree.iter.AxisIterator;
 38  
 import net.sf.saxon.tree.util.FastStringBuffer;
 39  
 import net.sf.saxon.tree.util.Navigator;
 40  
 import net.sf.saxon.type.SchemaType;
 41  
 
 42  
 /**
 43  
  * Represents general class for {@code ElementNode}, {@code RootNode} and {@code AttributeNode}.
 44  
  *
 45  
  * @author Timur Tibeyev
 46  
  */
 47  7809
 public abstract class AbstractNode implements NodeInfo {
 48  
 
 49  
     /** The children. */
 50  7809
     private final List<AbstractNode> children = new ArrayList<>();
 51  
 
 52  
     /**
 53  
      * Getter method for token type.
 54  
      * @return token type
 55  
      */
 56  
     public abstract int getTokenType();
 57  
 
 58  
     /**
 59  
      * Returns underlying node.
 60  
      * @return underlying node
 61  
      */
 62  
     public abstract DetailAST getUnderlyingNode();
 63  
 
 64  
     /**
 65  
      * Getter method for children.
 66  
      * @return children list
 67  
      */
 68  
     protected List<AbstractNode> getChildren() {
 69  2318
         return Collections.unmodifiableList(children);
 70  
     }
 71  
 
 72  
     /**
 73  
      * Add new child node to children list.
 74  
      * @param node child node
 75  
      */
 76  
     protected void addChild(AbstractNode node) {
 77  6336
         children.add(node);
 78  6336
     }
 79  
 
 80  
     /**
 81  
      * Returns true if nodes are same, false otherwise.
 82  
      * @param nodeInfo other node
 83  
      * @return {@code TreeInfo}
 84  
      */
 85  
     @Override
 86  
     public boolean isSameNodeInfo(NodeInfo nodeInfo) {
 87  9
         return this == nodeInfo;
 88  
     }
 89  
 
 90  
     /**
 91  
      * Returns if implementation provides fingerprints.
 92  
      * @return {@code boolean}
 93  
      */
 94  
     @Override
 95  
     public boolean hasFingerprint() {
 96  2502
         return false;
 97  
     }
 98  
 
 99  
     /**
 100  
      * Returns uri of the namespace for the current node.
 101  
      * @return uri
 102  
      */
 103  
     @Override
 104  
     public String getURI() {
 105  133
         return "";
 106  
     }
 107  
 
 108  
     /**
 109  
      * Returns if current node has children.
 110  
      * @return if current node has children
 111  
      */
 112  
     @Override
 113  
     public boolean hasChildNodes() {
 114  4746
         return !children.isEmpty();
 115  
     }
 116  
 
 117  
     /**
 118  
      * Determines axis iteration algorithm.
 119  
      * @param axisNumber element from {@code AxisInfo}
 120  
      * @param nodeTest filter for iterator
 121  
      * @return {@code AxisIterator} object
 122  
      */
 123  
     @Override
 124  
     public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
 125  195
         AxisIterator axisIterator = iterateAxis(axisNumber);
 126  193
         if (nodeTest != null) {
 127  192
             axisIterator = new Navigator.AxisFilter(axisIterator, nodeTest);
 128  
         }
 129  193
         return axisIterator;
 130  
     }
 131  
 
 132  
     /**
 133  
      * Compares current object with specified for order.
 134  
      * @param nodeInfo another {@code NodeInfo} object
 135  
      * @return number representing order of current object to specified one
 136  
      */
 137  
     @Override
 138  
     public int compareOrder(NodeInfo nodeInfo) {
 139  7
         return getLocalPart().compareTo(nodeInfo.getLocalPart());
 140  
     }
 141  
 
 142  
     /**
 143  
      * Returns namespace array. Throws {@code UnsupportedOperationException}, because no child
 144  
      * class implements it and this method is not used for querying.
 145  
      * @param namespaceBindings namespace array
 146  
      * @return namespace array
 147  
      */
 148  
     @Override
 149  
     public final NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] namespaceBindings) {
 150  1
         throw throwUnsupportedOperationException();
 151  
     }
 152  
 
 153  
     /**
 154  
      * Returns tree info. Throws {@code UnsupportedOperationException}, because no child
 155  
      * class implements it and this method is not used for querying.
 156  
      * @return tree info
 157  
      */
 158  
     @Override
 159  
     public final TreeInfo getTreeInfo() {
 160  1
         throw throwUnsupportedOperationException();
 161  
     }
 162  
 
 163  
     /**
 164  
      * Returns boolean. Throws {@code UnsupportedOperationException}, because no child
 165  
      * class implements it and this method is not used for querying.
 166  
      * @return boolean
 167  
      */
 168  
     @Override
 169  
     public final boolean isId() {
 170  1
         throw throwUnsupportedOperationException();
 171  
     }
 172  
 
 173  
     /**
 174  
      * Returns boolean. Throws {@code UnsupportedOperationException}, because no child
 175  
      * class implements it and this method is not used for querying.
 176  
      * @return boolean
 177  
      */
 178  
     @Override
 179  
     public final boolean isIdref() {
 180  1
         throw throwUnsupportedOperationException();
 181  
     }
 182  
 
 183  
     /**
 184  
      * Returns boolean. Throws {@code UnsupportedOperationException}, because no child
 185  
      * class implements it and this method is not used for querying.
 186  
      * @return boolean
 187  
      */
 188  
     @Override
 189  
     public final boolean isNilled() {
 190  1
         throw throwUnsupportedOperationException();
 191  
     }
 192  
 
 193  
     /**
 194  
      * Returns boolean. Throws {@code UnsupportedOperationException}, because no child
 195  
      * class implements it and this method is not used for querying.
 196  
      * @return boolean
 197  
      */
 198  
     @Override
 199  
     public final boolean isStreamed() {
 200  1
         throw throwUnsupportedOperationException();
 201  
     }
 202  
 
 203  
     /**
 204  
      * Returns configuration. Throws {@code UnsupportedOperationException}, because no child
 205  
      * class implements it and this method is not used for querying.
 206  
      * @return configuration
 207  
      */
 208  
     @Override
 209  
     public final Configuration getConfiguration() {
 210  1
         throw throwUnsupportedOperationException();
 211  
     }
 212  
 
 213  
     /**
 214  
      * Sets system id. Throws {@code UnsupportedOperationException}, because no child
 215  
      * class implements it and this method is not used for querying.
 216  
      * @param systemId system id
 217  
      */
 218  
     @Override
 219  
     public final void setSystemId(String systemId) {
 220  1
         throw throwUnsupportedOperationException();
 221  
     }
 222  
 
 223  
     /**
 224  
      * Returns system id. Throws {@code UnsupportedOperationException}, because no child
 225  
      * class implements it and this method is not used for querying.
 226  
      * @return system id
 227  
      */
 228  
     @Override
 229  
     public final String getSystemId() {
 230  1
         throw throwUnsupportedOperationException();
 231  
     }
 232  
 
 233  
     /**
 234  
      * Returns public id. Throws {@code UnsupportedOperationException}, because no child
 235  
      * class implements it and this method is not used for querying.
 236  
      * @return public id
 237  
      */
 238  
     @Override
 239  
     public final String getPublicId() {
 240  1
         throw throwUnsupportedOperationException();
 241  
     }
 242  
 
 243  
     /**
 244  
      * Returns base uri. Throws {@code UnsupportedOperationException}, because no child
 245  
      * class implements it and this method is not used for querying.
 246  
      * @return base uri
 247  
      */
 248  
     @Override
 249  
     public final String getBaseURI() {
 250  1
         throw throwUnsupportedOperationException();
 251  
     }
 252  
 
 253  
     /**
 254  
      * Returns location. Throws {@code UnsupportedOperationException}, because no child
 255  
      * class implements it and this method is not used for querying.
 256  
      * @return location
 257  
      */
 258  
     @Override
 259  
     public final Location saveLocation() {
 260  1
         throw throwUnsupportedOperationException();
 261  
     }
 262  
 
 263  
     /**
 264  
      * Compares current object with specified for position. Throws
 265  
      * {@code UnsupportedOperationException}, because no child
 266  
      * class implements it and this method is not used for querying.
 267  
      * @param nodeInfo another {@code NodeInfo} object
 268  
      * @return constant from {@code AxisInfo} representing order of
 269  
      *      current object to specified one
 270  
      */
 271  
     @Override
 272  
     public final int comparePosition(NodeInfo nodeInfo) {
 273  1
         throw throwUnsupportedOperationException();
 274  
     }
 275  
 
 276  
     /**
 277  
      * Returns head. Throws {@code UnsupportedOperationException}, because no child
 278  
      * class implements it and this method is not used for querying.
 279  
      * @return head
 280  
      */
 281  
     @Override
 282  
     public final Item head() {
 283  1
         throw throwUnsupportedOperationException();
 284  
     }
 285  
 
 286  
     /**
 287  
      * Returns iterator. Throws {@code UnsupportedOperationException}, because no child
 288  
      * class implements it and this method is not used for querying.
 289  
      * @return iterator
 290  
      */
 291  
     @Override
 292  
     public final SequenceIterator iterate() {
 293  1
         throw throwUnsupportedOperationException();
 294  
     }
 295  
 
 296  
     /**
 297  
      * Returns CharSequence string value. Throws {@code UnsupportedOperationException},
 298  
      * because no child class implements it and this method is not used for querying.
 299  
      * @return CharSequence string value
 300  
      */
 301  
     @Override
 302  
     public final CharSequence getStringValueCS() {
 303  1
         throw throwUnsupportedOperationException();
 304  
     }
 305  
 
 306  
     /**
 307  
      * Returns fingerprint. Throws {@code UnsupportedOperationException}, because no child
 308  
      * class implements it and this method is not used for querying.
 309  
      * @return fingerprint
 310  
      */
 311  
     @Override
 312  
     public final int getFingerprint() {
 313  1
         throw throwUnsupportedOperationException();
 314  
     }
 315  
 
 316  
     /**
 317  
      * Returns display name. Throws {@code UnsupportedOperationException}, because no child
 318  
      * class implements it and this method is not used for querying.
 319  
      * @return display name
 320  
      */
 321  
     @Override
 322  
     public final String getDisplayName() {
 323  1
         throw throwUnsupportedOperationException();
 324  
     }
 325  
 
 326  
     /**
 327  
      * Returns prefix. Throws {@code UnsupportedOperationException}, because no child
 328  
      * class implements it and this method is not used for querying.
 329  
      * @return prefix
 330  
      */
 331  
     @Override
 332  
     public final String getPrefix() {
 333  1
         throw throwUnsupportedOperationException();
 334  
     }
 335  
 
 336  
     /**
 337  
      * Returns type of the schema. Throws {@code UnsupportedOperationException}, because no child
 338  
      * class implements it and this method is not used for querying.
 339  
      * @return type of the schema
 340  
      */
 341  
     @Override
 342  
     public final SchemaType getSchemaType() {
 343  1
         throw throwUnsupportedOperationException();
 344  
     }
 345  
 
 346  
     /**
 347  
      * Returns AtomicSequence. Throws {@code UnsupportedOperationException}, because no child
 348  
      * class implements it and this method is not used for querying.
 349  
      * @return AtomicSequence
 350  
      */
 351  
     @Override
 352  
     public final AtomicSequence atomize() {
 353  1
         throw throwUnsupportedOperationException();
 354  
     }
 355  
 
 356  
     /**
 357  
      * Generate id method. Throws {@code UnsupportedOperationException}, because no child
 358  
      * class implements it and this method is not used for querying.
 359  
      * @param fastStringBuffer fastStringBuffer
 360  
      */
 361  
     @Override
 362  
     public final void generateId(FastStringBuffer fastStringBuffer) {
 363  1
         throw throwUnsupportedOperationException();
 364  
     }
 365  
 
 366  
     /**
 367  
      * Copy method. Throws {@code UnsupportedOperationException}, because no child
 368  
      * class implements it and this method is not used for querying.
 369  
      * @param receiver receiver
 370  
      * @param index index
 371  
      * @param location location
 372  
      */
 373  
     @Override
 374  
     public final void copy(Receiver receiver, int index, Location location) {
 375  1
         throw throwUnsupportedOperationException();
 376  
     }
 377  
 
 378  
     /**
 379  
      * Returns UnsupportedOperationException exception. Methods which throws this exception are
 380  
      * not supported for all nodes.
 381  
      * @return UnsupportedOperationException exception
 382  
      */
 383  
     private static UnsupportedOperationException throwUnsupportedOperationException() {
 384  23
         return new UnsupportedOperationException("Operation is not supported");
 385  
     }
 386  
 }