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

pmd / pmd / #3788

pending completion
#3788

push

github actions

web-flow
Merge pull request #4387 from adangel/pmd7-language-versions

137 of 137 new or added lines in 32 files covered. (100.0%)

67152 of 127777 relevant lines covered (52.55%)

0.53 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/PlainTextLanguage.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang;
6

7
import net.sourceforge.pmd.annotation.Experimental;
8
import net.sourceforge.pmd.lang.ast.AstInfo;
9
import net.sourceforge.pmd.lang.ast.Parser;
10
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
11
import net.sourceforge.pmd.lang.ast.RootNode;
12
import net.sourceforge.pmd.lang.ast.impl.AbstractNode;
13
import net.sourceforge.pmd.lang.document.TextRegion;
14
import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
15

16
/**
17
 * A dummy language implementation whose parser produces a single node.
18
 * This is provided for cases where a non-null language is required, but
19
 * the parser is not useful. This is useful eg to mock rules when no other
20
 * language is on the classpath. This language is not exposed by {@link LanguageRegistry}
21
 * and can only be used explicitly with {@link #getInstance()}.
22
 *
23
 * @author Clément Fournier
24
 * @since 6.48.0
25
 */
26
@Experimental
27
public final class PlainTextLanguage extends SimpleLanguageModuleBase {
28

29
    private static final Language INSTANCE = new PlainTextLanguage();
×
30

31
    static final String TERSE_NAME = "text";
32

33
    private PlainTextLanguage() {
34
        super(LanguageMetadata.withId(TERSE_NAME).name("Plain text")
×
35
                              .extensions("plain-text-file-goo-extension")
×
36
                              .addDefaultVersion("default"),
×
37
              new TextLvh());
38
    }
×
39

40
    /**
41
     * Returns the singleton instance of this language.
42
     */
43
    public static Language getInstance() {
44
        return INSTANCE;
×
45
    }
46

47
    private static final class TextLvh implements LanguageVersionHandler {
48
        @Override
49
        public Parser getParser() {
50
            return PlainTextFile::new;
×
51
        }
52
    }
53

54
    /**
55
     * The only node produced by the parser of {@link PlainTextLanguage}.
56
     */
57
    public static class PlainTextFile extends AbstractNode<PlainTextFile, PlainTextFile> implements RootNode {
58

59
        private final AstInfo<PlainTextFile> astInfo;
60

61

62
        PlainTextFile(ParserTask task) {
×
63
            this.astInfo = new AstInfo<>(task, this);
×
64
        }
×
65

66
        @Override
67
        public TextRegion getTextRegion() {
68
            return getTextDocument().getEntireRegion();
×
69
        }
70

71
        @Override
72
        public String getXPathNodeName() {
73
            return "TextFile";
×
74
        }
75

76
        @Override
77
        public String getImage() {
78
            return null;
×
79
        }
80

81
        @Override
82
        public String toString() {
83
            return "Plain text file (" + getEndLine() + " lines)";
×
84
        }
85

86
        @Override
87
        public AstInfo<? extends RootNode> getAstInfo() {
88
            return astInfo;
×
89
        }
90
    }
91

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