• 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

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

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

7
import java.io.Reader;
8
import java.nio.charset.Charset;
9
import java.nio.file.Path;
10

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

13
import net.sourceforge.pmd.lang.LanguageVersion;
14
import net.sourceforge.pmd.util.AssertionUtil;
15

16
/**
17
 * A builder for a new text file.
18
 * See static methods on {@link TextFile}.
19
 */
20
public abstract class TextFileBuilder {
21

22
    protected final LanguageVersion languageVersion;
23
    protected FileId parentFsId;
24

25
    TextFileBuilder(LanguageVersion languageVersion) {
1✔
26
        this.languageVersion = AssertionUtil.requireParamNotNull("language version", languageVersion);
1✔
27
    }
1✔
28

29
    /**
30
     * Specify that the built file is read only. Some text files are
31
     * always read-only.
32
     *
33
     * @return This builder
34
     */
35
    public TextFileBuilder asReadOnly() {
36
        // default is appropriate if the file type is always read-only
UNCOV
37
        return this;
×
38
    }
39

40
    public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
41
        parentFsId = fileId;
1✔
42
        return this;
1✔
43
    }
44

45

46
    /**
47
     * Creates and returns the new text file.
48
     */
49
    public abstract TextFile build();
50

51
    static class ForNio extends TextFileBuilder {
52

53
        private final Path path;
54
        private final Charset charset;
55
        private boolean readOnly = false;
1✔
56

57
        ForNio(LanguageVersion languageVersion, Path path, Charset charset) {
58
            super(languageVersion);
1✔
59
            this.path = AssertionUtil.requireParamNotNull("path", path);
1✔
60
            this.charset = AssertionUtil.requireParamNotNull("charset", charset);
1✔
61
        }
1✔
62

63
        @Override
64
        public TextFileBuilder asReadOnly() {
65
            readOnly = true;
1✔
66
            return this;
1✔
67
        }
68

69
        @Override
70
        public TextFile build() {
71
            return new NioTextFile(path, parentFsId, charset, languageVersion, readOnly);
1✔
72
        }
73
    }
74

75
    static class ForCharSeq extends TextFileBuilder {
76

77
        private final CharSequence charSequence;
78
        private FileId fileId;
79

80
        ForCharSeq(CharSequence charSequence, FileId fileId, LanguageVersion languageVersion) {
81
            super(languageVersion);
1✔
82
            this.charSequence = AssertionUtil.requireParamNotNull("charseq", charSequence);
1✔
83
            this.fileId = AssertionUtil.requireParamNotNull("path ID", fileId);
1✔
84
        }
1✔
85

86
        @Override
87
        public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
88
            this.fileId = FileId.asChildOf(this.fileId, fileId);
1✔
89
            return super.setParentFsPath(fileId);
1✔
90
        }
91

92
        @Override
93
        public TextFile build() {
94
            return new StringTextFile(charSequence, fileId, languageVersion);
1✔
95
        }
96
    }
97

98
    static class ForReader extends TextFileBuilder {
99

100
        private final Reader reader;
101
        private FileId fileId;
102

103
        ForReader(LanguageVersion languageVersion, Reader reader, FileId fileId) {
104
            super(languageVersion);
1✔
105
            this.reader = AssertionUtil.requireParamNotNull("reader", reader);
1✔
106
            this.fileId = AssertionUtil.requireParamNotNull("path ID", fileId);
1✔
107
        }
1✔
108

109
        @Override
110
        public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
UNCOV
111
            this.fileId = FileId.asChildOf(this.fileId, fileId);
×
112
            return super.setParentFsPath(fileId);
×
113
        }
114

115

116
        @Override
117
        public TextFile build() {
118
            return new ReaderTextFile(reader, fileId, languageVersion);
1✔
119
        }
120
    }
121

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