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

pmd / pmd / 19

29 May 2025 04:22PM UTC coverage: 77.723% (-0.03%) from 77.757%
19

push

github

adangel
Fix #5621: [java] Fix FPs with UnusedPrivateMethod (#5727)

Merge pull request #5727 from oowekyala:issue5621-unusedprivatemethod

17705 of 23734 branches covered (74.6%)

Branch coverage included in aggregate %.

50 of 52 new or added lines in 9 files covered. (96.15%)

81 existing lines in 6 files now uncovered.

38845 of 49024 relevant lines covered (79.24%)

0.8 hits per line

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

91.3
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.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.rule.design;
6

7
import static net.sourceforge.pmd.properties.NumericConstraints.positive;
8

9
import net.sourceforge.pmd.lang.java.ast.ASTExecutableDeclaration;
10
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
11
import net.sourceforge.pmd.lang.java.ast.JavaNode;
12
import net.sourceforge.pmd.lang.java.ast.internal.PrettyPrintingUtil;
13
import net.sourceforge.pmd.lang.java.metrics.JavaMetrics;
14
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
15
import net.sourceforge.pmd.lang.metrics.MetricsUtil;
16
import net.sourceforge.pmd.properties.PropertyDescriptor;
17
import net.sourceforge.pmd.properties.PropertyFactory;
18
import net.sourceforge.pmd.reporting.RuleContext;
19

20

21
/**
22
 * Simple n-path complexity rule.
23
 *
24
 * @author Clément Fournier
25
 * @author Jason Bennett
26
 */
27
public class NPathComplexityRule extends AbstractJavaRulechainRule {
28

29
    private static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
1✔
30
        = PropertyFactory.intProperty("reportLevel").desc("N-Path Complexity reporting threshold")
1✔
31
                         .require(positive()).defaultValue(200).build();
1✔
32

33
    public NPathComplexityRule() {
34
        super(ASTExecutableDeclaration.class);
1✔
35
        definePropertyDescriptor(REPORT_LEVEL_DESCRIPTOR);
1✔
36
    }
1✔
37

38

39
    @Override
40
    public Object visitJavaNode(JavaNode node, Object data) {
41
        return visitMethod((ASTExecutableDeclaration) node, (RuleContext) data);
1✔
42
    }
43

44
    private Object visitMethod(ASTExecutableDeclaration node, RuleContext data) {
45
        int reportLevel = getProperty(REPORT_LEVEL_DESCRIPTOR);
1✔
46
        if (!JavaMetrics.NPATH_COMP.supports(node)) {
1!
UNCOV
47
            return data;
×
48
        }
49

50
        long npath = MetricsUtil.computeMetric(JavaMetrics.NPATH_COMP, node);
1✔
51
        if (npath >= reportLevel) {
1✔
52
            asCtx(data).addViolation(node, node instanceof ASTMethodDeclaration ? "method" : "constructor",
1✔
53
                                     PrettyPrintingUtil.displaySignature(node),
1✔
54
                                     String.valueOf(npath),
1✔
55
                                     String.valueOf(reportLevel));
1✔
56
        }
57

58
        return data;
1✔
59
    }
60
}
61

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