• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 277

27 Nov 2025 01:37PM UTC coverage: 78.778% (+0.03%) from 78.749%
277

push

github

adangel
[java] UseArraysAsList: skip when if-statements (#6228)

18419 of 24233 branches covered (76.01%)

Branch coverage included in aggregate %.

40090 of 50038 relevant lines covered (80.12%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/GenericNode.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.ast.impl;
6

7

8
import org.checkerframework.checker.nullness.qual.Nullable;
9

10
import net.sourceforge.pmd.lang.ast.Node;
11
import net.sourceforge.pmd.lang.ast.NodeStream;
12
import net.sourceforge.pmd.lang.ast.NodeStream.DescendantNodeStream;
13
import net.sourceforge.pmd.lang.ast.internal.StreamImpl;
14

15
/**
16
 * Interface that binds the return type of some node methods to a type
17
 * parameter. This enforces that eg all children of such a node are from
18
 * the same hierarchy (eg Java nodes only have Java nodes as parent, or
19
 * as children).
20
 *
21
 * <p>Although subinterfaces like JavaNode profit from the added type
22
 * information, the Node interface and its usages in language-independent
23
 * code would suffer from adding a type parameter directly to {@link Node}.
24
 *
25
 * <p>Type safety of the unchecked casts here is the responsibility of
26
 * the implementation, it should check that methods like setParent or
27
 * addChild add an instance of {@code <N>}.
28
 *
29
 * @param <N> Self type (eg JavaNode)
30
 */
31
@SuppressWarnings("unchecked")
32
public interface GenericNode<N extends GenericNode<N>> extends Node {
33

34
    @Override
35
    N getChild(int index);
36

37
    @Override
38
    N getParent();
39

40
    @Override
41
    default @Nullable N getFirstChild() {
42
        return getNumChildren() > 0 ? getChild(0) : null;
1!
43
    }
44

45
    @Override
46
    default @Nullable N getLastChild() {
47
        return getNumChildren() > 0 ? getChild(getNumChildren() - 1) : null;
×
48
    }
49

50
    @Override
51
    default NodeStream<N> asStream() {
52
        return StreamImpl.singleton((N) this);
1✔
53
    }
54

55
    @Override
56
    default NodeStream<N> children() {
57
        return (NodeStream<N>) Node.super.children();
×
58
    }
59

60
    @Override
61
    default DescendantNodeStream<N> descendants() {
62
        return (DescendantNodeStream<N>) Node.super.descendants();
1✔
63
    }
64

65
    @Override
66
    default DescendantNodeStream<N> descendantsOrSelf() {
67
        return (DescendantNodeStream<N>) Node.super.descendantsOrSelf();
1✔
68
    }
69

70
    @Override
71
    default NodeStream<N> ancestorsOrSelf() {
72
        return (NodeStream<N>) Node.super.ancestorsOrSelf();
1✔
73
    }
74

75
    @Override
76
    default NodeStream<N> ancestors() {
77
        return (NodeStream<N>) Node.super.ancestors();
1✔
78
    }
79

80
    @Override
81
    default @Nullable N getPreviousSibling() {
82
        return (N) Node.super.getPreviousSibling();
1✔
83
    }
84

85
    @Override
86
    default @Nullable N getNextSibling() {
87
        return (N) Node.super.getNextSibling();
1✔
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc