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

pmd / pmd / 43

20 Jun 2025 06:39PM UTC coverage: 78.375% (-0.002%) from 78.377%
43

push

github

adangel
Fix #1639 #5832: Use filtered comment text for UnnecessaryImport (#5833)

Merged pull request #5833 from adangel:java/issue-5832-unnecessaryimport

17714 of 23438 branches covered (75.58%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

109 existing lines in 17 files now uncovered.

38908 of 48807 relevant lines covered (79.72%)

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
        @NonNull
42
        default ASTExpression getLeftOperand() {
43
            return (ASTExpression) getChild(0);
1✔
44
        }
45

46

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

53

54
        /** Returns the operator. */
55
        @NonNull
56
        OperatorLike getOperator();
57
    }
58

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

65

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

74

75
        /** Returns the last child of this node, never null. */
76
        @Override
77
        @NonNull
78
        default JavaNode getLastChild() {
UNCOV
79
            assert getNumChildren() > 0;
×
80
            return getChild(getNumChildren() - 1);
×
81
        }
82
    }
83

84
    interface AllChildrenAreOfType<T extends JavaNode> extends JavaNode {
85

86
        @Override
87
        @Nullable
88
        default T getFirstChild() {
89
            if (getNumChildren() == 0) {
1✔
90
                return null;
1✔
91
            }
92
            return (T) getChild(0);
1✔
93
        }
94

95

96
        @Override
97
        @Nullable
98
        default T getLastChild() {
99
            if (getNumChildren() == 0) {
1✔
100
                return null;
1✔
101
            }
102
            return (T) getChild(getNumChildren() - 1);
1✔
103
        }
104
    }
105

106
    /**
107
     * Tags a node that has at least one child, then some methods never
108
     * return null.
109
     */
110
    interface AtLeastOneChildOfType<T extends JavaNode> extends AllChildrenAreOfType<T> {
111

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

120

121
        /** Returns the last child of this node, never null. */
122
        @Override
123
        @NonNull
124
        default T getLastChild() {
125
            assert getNumChildren() > 0 : "No children for node implementing AtLeastOneChild " + this;
1!
126
            return (T) getChild(getNumChildren() - 1);
1✔
127
        }
128
    }
129

130
    interface VariableIdOwner extends JavaNode {
131

132
        /** Returns the id of the declared variable. */
133
        ASTVariableId getVarId();
134
    }
135

136
    interface MultiVariableIdOwner extends Iterable<ASTVariableId>, ModifierOwner {
137

138
        /**
139
         * Returns a stream of the variable ids declared
140
         * by this node.
141
         */
142
        default NodeStream<ASTVariableId> getVarIds() {
143
            return children(ASTVariableDeclarator.class).children(ASTVariableId.class);
1✔
144
        }
145

146

147
        @Override
148
        default Iterator<ASTVariableId> iterator() {
149
            return getVarIds().iterator();
1✔
150
        }
151

152
        ASTType getTypeNode();
153
    }
154

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