Checks if the step will never yield results. @param seqType type of input nodes @return true if steps will never yield results
(final SeqType seqType)
| 363 | * @return {@code true} if steps will never yield results |
| 364 | */ |
| 365 | final boolean empty(final SeqType seqType) { |
| 366 | if(!(seqType.type instanceof final NodeType nt)) return false; |
| 367 | |
| 368 | // checks steps on document nodes |
| 369 | final Kind kind = test.kind, nk = nt.kind(); |
| 370 | if(nk == Kind.DOCUMENT && switch(axis) { |
| 371 | case SELF, ANCESTOR_OR_SELF, FOLLOWING_OR_SELF, FOLLOWING_SIBLING_OR_SELF, |
| 372 | PRECEDING_OR_SELF, PRECEDING_SIBLING_OR_SELF -> |
| 373 | !kind.oneOf(Kind.GNODE, Kind.NODE, Kind.DOCUMENT); |
| 374 | case CHILD, DESCENDANT -> |
| 375 | kind.oneOf(Kind.DOCUMENT, Kind.ATTRIBUTE); |
| 376 | case DESCENDANT_OR_SELF -> |
| 377 | kind == Kind.ATTRIBUTE; |
| 378 | default -> |
| 379 | true; |
| 380 | }) return true; |
| 381 | |
| 382 | // check step after any other expression |
| 383 | return switch(axis) { |
| 384 | // $element/self::text(), ... |
| 385 | case SELF -> |
| 386 | test.subsumes(nt) == Boolean.FALSE; |
| 387 | // $attribute/descendant::, $text/child::, $comment/attribute::, ... |
| 388 | case DESCENDANT, CHILD, ATTRIBUTE -> |
| 389 | isLeaf(nk); |
| 390 | // $text/descendant-or-self::text(), ... |
| 391 | case DESCENDANT_OR_SELF -> |
| 392 | isLeaf(nk) && !kind.oneOf(Kind.GNODE, Kind.NODE) && !kind.instanceOf(nk); |
| 393 | // $attribute/following-sibling::, $attribute/preceding-sibling:: |
| 394 | case FOLLOWING_SIBLING, PRECEDING_SIBLING -> |
| 395 | nk == Kind.ATTRIBUTE; |
| 396 | // $attribute/parent::document-node() |
| 397 | case PARENT -> |
| 398 | nk == Kind.ATTRIBUTE && kind == Kind.DOCUMENT; |
| 399 | default -> |
| 400 | false; |
| 401 | }; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Checks if the step is redundant. |
no test coverage detected