• 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

73.56
/pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java
1
/**
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.cpd;
6

7
import net.sourceforge.pmd.lang.document.FileId;
8

9
public class TokenEntry implements Comparable<TokenEntry> {
1✔
10

11
    private static final int EOF = 0;
12

13
    private final FileId fileId;
14
    private final int beginLine;
15
    private final int beginColumn;
16
    private final int endColumn;
17
    private final int endLine;
18
    private int index;
19
    private int identifier;
20
    private int hashCode;
21

22
    /** constructor for EOF entries. */
23
    TokenEntry(FileId fileId, int line, int column) {
1✔
24
        assert isOk(line) && isOk(column) : "Coordinates are 1-based";
1!
25
        this.identifier = EOF;
1✔
26
        this.fileId = fileId;
1✔
27
        this.beginLine = line;
1✔
28
        this.beginColumn = column;
1✔
29
        this.endLine = line;
1✔
30
        this.endColumn = column;
1✔
31
    }
1✔
32

33
    TokenEntry(int imageId, FileId fileId, int beginLine, int beginColumn, int endLine, int endColumn, int index) {
1✔
34
        assert isOk(beginLine) && isOk(beginColumn) && isOk(endLine) && isOk(endColumn) : "Coordinates are 1-based";
1!
35
        assert imageId != EOF;
1!
36
        this.fileId = fileId;
1✔
37
        this.beginLine = beginLine;
1✔
38
        this.beginColumn = beginColumn;
1✔
39
        this.endLine = endLine;
1✔
40
        this.endColumn = endColumn;
1✔
41
        this.identifier = imageId;
1✔
42
        this.index = index;
1✔
43
    }
1✔
44

45
    public boolean isEof() {
46
        return this.identifier == EOF;
1✔
47
    }
48

49
    private boolean isOk(int coord) {
50
        return coord >= 1;
1!
51
    }
52

53

54
    FileId getFileId() {
55
        return fileId;
1✔
56
    }
57

58

59
    /** The line number where this token starts. */
60
    public int getBeginLine() {
61
        return beginLine;
1✔
62
    }
63

64
    /** The line number where this token ends. */
65
    public int getEndLine() {
66
        return endLine;
1✔
67
    }
68

69
    /** The column number where this token starts, inclusive. */
70
    public int getBeginColumn() {
71
        return beginColumn;
1✔
72
    }
73

74
    /** The column number where this token ends, exclusive. */
75
    public int getEndColumn() {
76
        return endColumn;
1✔
77
    }
78

79
    int getIdentifier() {
80
        return this.identifier;
1✔
81
    }
82

83
    int getIndex() {
84
        return this.index;
1✔
85
    }
86

87
    @Override
88
    public int hashCode() {
89
        return hashCode;
1✔
90
    }
91

92
    void setHashCode(int hashCode) {
93
        this.hashCode = hashCode;
1✔
94
    }
1✔
95

96
    @Override
97
    public boolean equals(Object o) {
98
        if (this == o) {
1✔
99
            return true;
1✔
100
        } else if (!(o instanceof TokenEntry)) {
1!
UNCOV
101
            return false;
×
102
        }
103
        TokenEntry other = (TokenEntry) o;
1✔
104
        if (other.isEof() != this.isEof()) {
1!
UNCOV
105
            return false;
×
106
        } else if (this.isEof()) {
1!
UNCOV
107
            return other.getFileId().equals(this.getFileId());
×
108
        }
109
        return other.hashCode == hashCode;
1!
110
    }
111

112
    @Override
113
    public int compareTo(TokenEntry other) {
114
        return getIndex() - other.getIndex();
1✔
115
    }
116

117
    final void setImageIdentifier(int identifier) {
UNCOV
118
        this.identifier = identifier;
×
119
    }
×
120

121
    public String getImage(Tokens tokens) {
122
        if (this.isEof()) {
1✔
123
            return "EOF";
1✔
124
        }
125
        String image = tokens.imageFromId(this.identifier);
1✔
126
        return image == null ? "--unknown--" : image;
1!
127
    }
128

129
    @Override
130
    public String toString() {
UNCOV
131
        if (this.isEof()) {
×
132
            return "EOF";
×
133
        }
UNCOV
134
        return Integer.toString(identifier);
×
135
    }
136

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