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

pmd / pmd / 175

25 Sep 2025 09:57AM UTC coverage: 78.654% (-0.006%) from 78.66%
175

push

github

adangel
[java] Reactivate deactivated test in LocalVariableCouldBeFinal (#6043)

18176 of 23959 branches covered (75.86%)

Branch coverage included in aggregate %.

39693 of 49615 relevant lines covered (80.0%)

0.81 hits per line

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

29.17
/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/LanguageMetricsProvider.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.metrics;
6

7
import java.util.HashMap;
8
import java.util.Map;
9
import java.util.Set;
10

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

13
import net.sourceforge.pmd.lang.LanguageVersionHandler;
14
import net.sourceforge.pmd.lang.ast.Node;
15

16

17
/**
18
 * Language-specific provider for metrics. Knows about all the metrics
19
 * defined for a language. Can be used e.g. to build GUI applications
20
 * like the designer, in a language independent way. Accessible through
21
 * {@link LanguageVersionHandler#getLanguageMetricsProvider()}.
22
 *
23
 *
24
 * @author Clément Fournier
25
 * @since 6.11.0
26
 */
27
public interface LanguageMetricsProvider {
28

29
    /** Returns the set of all metrics supported by the language. */
30
    Set<Metric<?, ?>> getMetrics();
31

32

33
    /** Fetch a metric using its name. */
34
    default @Nullable Metric<?, ?> getMetricWithName(String nameIgnoringCase) {
35
        for (Metric<?, ?> metric : getMetrics()) {
1!
36
            for (String nameAlias : metric.nameAliases()) {
1!
37
                if (nameAlias.equalsIgnoreCase(nameIgnoringCase)) {
1!
38
                    return metric;
1✔
39
                }
40
            }
×
41
        }
×
42
        return null;
×
43
    }
44

45
    /**
46
     * Computes all metrics available on the given node.
47
     * The returned results may contain Double.NaN as a value.
48
     *
49
     * @param node Node to inspect
50
     *
51
     * @return A map of metric key to their result, possibly empty, but with no null value
52
     */
53
    default Map<Metric<?, ?>, Number> computeAllMetricsFor(Node node) {
54
        Map<Metric<?, ?>, Number> results = new HashMap<>();
×
55
        for (Metric<?, ?> metric : getMetrics()) {
×
56
            @Nullable Number result = Metric.compute(metric, node, MetricOptions.emptyOptions());
×
57
            if (result != null) {
×
58
                results.put(metric, result);
×
59
            }
60
        }
×
61
        return results;
×
62
    }
63
}
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

© 2025 Coveralls, Inc