• 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

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

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

7

8
import java.util.Iterator;
9

10
import org.checkerframework.checker.nullness.qual.NonNull;
11
import org.checkerframework.checker.nullness.qual.Nullable;
12

13
import net.sourceforge.pmd.lang.ast.NodeStream;
14

15
/**
16
 * Those are some interfaces that are not published, but are used to keep
17
 * uniform names on related concepts. Maybe it makes sense to publish some of
18
 * them at some point.
19
 */
20
final class InternalInterfaces {
21

22
    private InternalInterfaces() {
23
        // utility class
24
    }
25

26
    interface OperatorLike {
27

28

29
        /**
30
         * Returns the token used to represent the type in source
31
         * code, e.g. {@code "+"} or {@code "*"}.
32
         */
33
        String getToken();
34

35
    }
36

37
    /** Just to share the method names. */
38
    interface BinaryExpressionLike extends ASTExpression {
39

40
        /** Returns the left-hand-side operand. */
41
        default @NonNull ASTExpression getLeftOperand() {
42
            return (ASTExpression) getChild(0);
1✔
43
        }
44

45

46
        /** Returns the right-hand side operand. */
47
        default @NonNull ASTExpression getRightOperand() {
48
            return (ASTExpression) getChild(1);
1✔
49
        }
50

51

52
        /** Returns the operator. */
53
        @NonNull OperatorLike getOperator();
54
    }
55

56
    /**
57
     * Tags a node that has at least one child, then some methods never
58
     * return null.
59
     */
60
    interface AtLeastOneChild extends JavaNode {
1!
61

62

63
        /** Returns the first child of this node, never null. */
64
        @Override
65
        default @NonNull JavaNode getFirstChild() {
66
            assert getNumChildren() > 0;
1!
67
            return getChild(0);
1✔
68
        }
69

70

71
        /** Returns the last child of this node, never null. */
72
        @Override
73
        default @NonNull JavaNode getLastChild() {
74
            assert getNumChildren() > 0;
×
75
            return getChild(getNumChildren() - 1);
×
76
        }
77
    }
78

79
    interface AllChildrenAreOfType<T extends JavaNode> extends JavaNode {
80

81
        @Override
82
        default @Nullable T getFirstChild() {
83
            if (getNumChildren() == 0) {
1✔
84
                return null;
1✔
85
            }
86
            return (T) getChild(0);
1✔
87
        }
88

89

90
        @Override
91
        default @Nullable T getLastChild() {
92
            if (getNumChildren() == 0) {
1✔
93
                return null;
1✔
94
            }
95
            return (T) getChild(getNumChildren() - 1);
1✔
96
        }
97
    }
98

99
    /**
100
     * Tags a node that has at least one child, then some methods never
101
     * return null.
102
     */
103
    interface AtLeastOneChildOfType<T extends JavaNode> extends AllChildrenAreOfType<T> {
104

105
        /** Returns the first child of this node, never null. */
106
        @Override
107
        default @NonNull T getFirstChild() {
108
            assert getNumChildren() > 0 : "No children for node implementing AtLeastOneChild " + this;
1!
109
            return (T) getChild(0);
1✔
110
        }
111

112

113
        /** Returns the last child of this node, never null. */
114
        @Override
115
        default @NonNull T getLastChild() {
116
            assert getNumChildren() > 0 : "No children for node implementing AtLeastOneChild " + this;
1!
117
            return (T) getChild(getNumChildren() - 1);
1✔
118
        }
119
    }
120

121
    interface VariableIdOwner extends JavaNode {
122

123
        /** Returns the id of the declared variable. */
124
        ASTVariableId getVarId();
125
    }
126

127
    interface MultiVariableIdOwner extends Iterable<ASTVariableId>, ModifierOwner {
128

129
        /**
130
         * Returns a stream of the variable ids declared
131
         * by this node.
132
         */
133
        default NodeStream<ASTVariableId> getVarIds() {
134
            return children(ASTVariableDeclarator.class).children(ASTVariableId.class);
1✔
135
        }
136

137

138
        @Override
139
        default Iterator<ASTVariableId> iterator() {
140
            return getVarIds().iterator();
1✔
141
        }
142

143
        ASTType getTypeNode();
144
    }
145

146
}
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