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

pmd / pmd / 23

30 May 2025 04:25PM UTC coverage: 78.377% (-0.2%) from 78.601%
23

push

github

adangel
[core] Add rule to report unnecessary suppression comments/annotations (#5609)

Merge pull request #5609 from oowekyala:new-rule-UnnecessarySuppression

17712 of 23434 branches covered (75.58%)

Branch coverage included in aggregate %.

159 of 328 new or added lines in 22 files covered. (48.48%)

36 existing lines in 4 files now uncovered.

38902 of 48799 relevant lines covered (79.72%)

0.81 hits per line

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

0.0
/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractTokenManager.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.ast.impl.javacc;
6

7
import java.util.ArrayList;
8
import java.util.Collection;
9
import java.util.HashMap;
10
import java.util.List;
11
import java.util.Map;
12

13
import net.sourceforge.pmd.PMDConfiguration;
14
import net.sourceforge.pmd.lang.TokenManager;
15
import net.sourceforge.pmd.lang.ast.impl.SuppressionCommentImpl;
16
import net.sourceforge.pmd.reporting.ViolationSuppressor.SuppressionCommentWrapper;
17

18
/**
19
 * A base class for the token managers generated by JavaCC.
20
 */
21
public abstract class AbstractTokenManager implements TokenManager<JavaccToken> {
×
22

NEW
23
    private final List<SuppressionCommentWrapper> suppressionComments = new ArrayList<>();
×
24
    /**
25
     * @deprecated Since 7.14.0. Don't use this map directly anymore. Instead, use {@link #getSuppressionComments()}.
26
     */
NEW
27
    @Deprecated
×
28
    protected Map<Integer, String> suppressMap = new HashMap<>();
29
    protected String suppressMarker = PMDConfiguration.DEFAULT_SUPPRESS_MARKER;
×
30

31
    public void setSuppressMarker(String marker) {
32
        this.suppressMarker = marker;
×
33
    }
×
34

35
    /**
36
     * @deprecated since 7.14.0. Use {@link #getSuppressionComments()} instead.
37
     */
38
    @Deprecated
39
    public Map<Integer, String> getSuppressMap() {
40
        return suppressMap;
×
41
    }
42

43
    /**
44
     * @since 7.14.0
45
     */
46
    protected void processCommentForSuppression(JavaccToken token) {
NEW
47
        String suppressMarker = this.suppressMarker;
×
NEW
48
        int startOfNOPMD = token.getImageCs().indexOf(suppressMarker, 0);
×
NEW
49
        if (startOfNOPMD != -1) {
×
NEW
50
            String message = token.getImageCs().substring(startOfNOPMD + suppressMarker.length());
×
NEW
51
            suppressMap.put(token.getReportLocation().getStartLine(), message);
×
NEW
52
            suppressionComments.add(new SuppressionCommentImpl<>(token, message));
×
53
        }
NEW
54
    }
×
55

56
    /**
57
     * @since 7.14.0
58
     */
59
    public Collection<SuppressionCommentWrapper> getSuppressionComments() {
NEW
60
        return suppressionComments;
×
61
    }
62
}
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