• 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

56.67
/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AbstractNcssCountRule.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.apex.rule.design;
6

7
import net.sourceforge.pmd.lang.apex.ast.ASTBreakStatement;
8
import net.sourceforge.pmd.lang.apex.ast.ASTContinueStatement;
9
import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement;
10
import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration;
11
import net.sourceforge.pmd.lang.apex.ast.ASTForEachStatement;
12
import net.sourceforge.pmd.lang.apex.ast.ASTForLoopStatement;
13
import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement;
14
import net.sourceforge.pmd.lang.apex.ast.ASTIfElseBlockStatement;
15
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
16
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
17
import net.sourceforge.pmd.lang.apex.ast.ASTReturnStatement;
18
import net.sourceforge.pmd.lang.apex.ast.ASTThrowStatement;
19
import net.sourceforge.pmd.lang.apex.ast.ASTTryCatchFinallyBlockStatement;
20
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
21
import net.sourceforge.pmd.lang.apex.ast.ASTUserEnum;
22
import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface;
23
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
24
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
25
import net.sourceforge.pmd.lang.apex.ast.ApexVisitorBase;
26
import net.sourceforge.pmd.lang.apex.rule.internal.AbstractCounterCheckRule;
27
import net.sourceforge.pmd.lang.ast.Node;
28

29
/**
30
 * Abstract superclass for NCSS counting methods. Counts tokens according to
31
 * <a href="http://www.kclee.de/clemens/java/javancss/">JavaNCSS rules</a>.
32
 *
33
 * @author ported from Java original of Jason Bennett
34
 * @deprecated Since 7.19.0.
35
 */
36
@Deprecated
37
abstract class AbstractNcssCountRule<T extends ApexNode<?>> extends AbstractCounterCheckRule<T> {
38

39

40
    /**
41
     * Count the nodes of the given type using NCSS rules.
42
     *
43
     * @param nodeClass class of node to count
44
     */
45
    protected AbstractNcssCountRule(Class<T> nodeClass) {
46
        super(nodeClass);
1✔
47
    }
1✔
48

49

50
    @Override
51
    protected int getMetric(T node) {
52
        return node.acceptVisitor(NcssVisitor.INSTANCE, null) + 1;
1✔
53
    }
54

55
    private static final class NcssVisitor extends ApexVisitorBase<Void, Integer> {
56
        // todo this would be better with a <MutableInt, Void> signature
57

58
        static final NcssVisitor INSTANCE = new NcssVisitor();
1✔
59

60
        @Override
61
        public Integer visitApexNode(ApexNode<?> node, Void data) {
62
            return countNodeChildren(node, data);
1✔
63
        }
64

65
        @Override
66
        protected Integer visitChildren(Node node, Void data) {
67
            int v = 0;
1✔
68
            for (Node child : node.children()) {
1✔
69
                v += child.acceptVisitor(this, data);
1✔
70
            }
1✔
71
            return v;
1✔
72
        }
73

74
        /**
75
         * Count the number of children of the given node. Adds one to count the
76
         * node itself.
77
         *
78
         * @param node node having children counted
79
         * @param data node data
80
         *
81
         * @return count of the number of children of the node, plus one
82
         */
83
        protected Integer countNodeChildren(ApexNode<?> node, Void data) {
84
            return visitChildren(node, data);
1✔
85
        }
86

87
        @Override
88
        public Integer visit(ASTForLoopStatement node, Void data) {
89
            return countNodeChildren(node, data) + 1;
×
90
        }
91

92
        @Override
93
        public Integer visit(ASTForEachStatement node, Void data) {
94
            return countNodeChildren(node, data) + 1;
×
95
        }
96

97
        @Override
98
        public Integer visit(ASTDoLoopStatement node, Void data) {
99
            return countNodeChildren(node, data) + 1;
×
100
        }
101

102
        @Override
103
        public Integer visit(ASTIfBlockStatement node, Void data) {
104
            return countNodeChildren(node, data) + 1;
×
105
        }
106

107
        @Override
108
        public Integer visit(ASTIfElseBlockStatement node, Void data) {
109
            return countNodeChildren(node, data) + 2;
×
110
        }
111

112
        @Override
113
        public Integer visit(ASTWhileLoopStatement node, Void data) {
114
            return countNodeChildren(node, data) + 1;
×
115
        }
116

117
        @Override
118
        public Integer visit(ASTBreakStatement node, Void data) {
119
            return 1;
×
120
        }
121

122
        @Override
123
        public Integer visit(ASTTryCatchFinallyBlockStatement node, Void data) {
124
            return countNodeChildren(node, data) + 1;
×
125
        }
126

127
        @Override
128
        public Integer visit(ASTContinueStatement node, Void data) {
129
            return 1;
×
130
        }
131

132
        @Override
133
        public Integer visit(ASTReturnStatement node, Void data) {
134
            return countNodeChildren(node, data) + 1;
×
135
        }
136

137
        @Override
138
        public Integer visit(ASTThrowStatement node, Void data) {
139
            return countNodeChildren(node, data) + 1;
×
140
        }
141

142
        @Override
143
        public Integer visit(ASTMethodCallExpression node, Void data) {
144
            return 1;
1✔
145
        }
146

147
        @Override
148
        public Integer visit(ASTMethod node, Void data) {
149
            return countNodeChildren(node, data);
1✔
150
        }
151

152
        @Override
153
        public Integer visit(ASTUserClass node, Void data) {
154
            return countNodeChildren(node, data) + 1;
1✔
155
        }
156

157
        @Override
158
        public Integer visit(ASTUserEnum node, Void data) {
159
            return countNodeChildren(node, data) + 1;
×
160
        }
161

162
        @Override
163
        public Integer visit(ASTUserInterface node, Void data) {
164
            return countNodeChildren(node, data) + 1;
×
165
        }
166

167
        @Override
168
        public Integer visit(ASTFieldDeclaration node, Void data) {
169
            return 1;
1✔
170
        }
171
    }
172
}
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