Update dummy module
This commit is contained in:
pmd-core/src
main/java/net/sourceforge/pmd/lang/ast
test/java/net/sourceforge/pmd
@ -23,7 +23,9 @@ public final class AstInfo<T extends RootNode> {
|
||||
private final Map<Integer, String> suppressionComments;
|
||||
|
||||
|
||||
public AstInfo(ParserTask task, T rootNode, Map<Integer, String> suppressionComments) {
|
||||
public AstInfo(ParserTask task,
|
||||
T rootNode,
|
||||
Map<Integer, String> suppressionComments) {
|
||||
this.filename = task.getFileDisplayName();
|
||||
this.sourceText = task.getSourceText();
|
||||
this.languageVersion = task.getLanguageVersion();
|
||||
@ -31,6 +33,18 @@ public final class AstInfo<T extends RootNode> {
|
||||
this.suppressionComments = suppressionComments;
|
||||
}
|
||||
|
||||
public AstInfo(String filename,
|
||||
LanguageVersion languageVersion,
|
||||
String sourceText,
|
||||
T rootNode,
|
||||
Map<Integer, String> suppressionComments) {
|
||||
this.filename = filename;
|
||||
this.languageVersion = languageVersion;
|
||||
this.sourceText = sourceText;
|
||||
this.rootNode = rootNode;
|
||||
this.suppressionComments = suppressionComments;
|
||||
}
|
||||
|
||||
public AstInfo(ParserTask task, T rootNode) {
|
||||
this(task, rootNode, Collections.emptyMap());
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -114,8 +113,7 @@ public class AbstractRuleTest {
|
||||
|
||||
@Test
|
||||
public void testRuleSuppress() {
|
||||
Map<Integer, String> m = Collections.singletonMap(5, "");
|
||||
DummyRoot n = new DummyRoot(m);
|
||||
DummyRoot n = new DummyRoot().withNoPmdComments(Collections.singletonMap(5, ""));
|
||||
n.setCoords(5, 1, 6, 1);
|
||||
RuleViolation violation = DefaultRuleViolationFactory.defaultInstance().createViolation(new MyRule(), n, "file", "specificdescription");
|
||||
SuppressedViolation suppressed = DefaultRuleViolationFactory.defaultInstance().suppressOrNull(n, violation);
|
||||
|
@ -51,10 +51,12 @@ public class DummyLanguageModule extends BaseLanguageModule {
|
||||
@Override
|
||||
public Parser getParser(ParserOptions parserOptions) {
|
||||
return task -> {
|
||||
DummyRoot node = new DummyRoot(task.getLanguageVersion());
|
||||
DummyRoot node = new DummyRoot();
|
||||
node.setCoords(1, 1, 2, 10);
|
||||
node.setImage("Foo");
|
||||
node.withFileName(task.getFileDisplayName());
|
||||
node.withLanguage(task.getLanguageVersion());
|
||||
node.withSourceText(task.getSourceText());
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ public class DummyNode extends AbstractNodeWithTextCoordinates<DummyNode, DummyN
|
||||
private final String xpathName;
|
||||
private final Map<String, String> userData = new HashMap<>();
|
||||
private String image;
|
||||
private String fileName = "sample.dummy";
|
||||
|
||||
public DummyNode(String xpathName) {
|
||||
super();
|
||||
@ -52,11 +51,6 @@ public class DummyNode extends AbstractNodeWithTextCoordinates<DummyNode, DummyN
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public DummyNode withFileName(String fname) {
|
||||
this.fileName = fname;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
return image;
|
||||
|
@ -4,56 +4,50 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.impl.GenericNode;
|
||||
|
||||
public class DummyRoot extends DummyNode implements GenericNode<DummyNode>, RootNode {
|
||||
|
||||
private final Map<Integer, String> suppressMap;
|
||||
private Map<Integer, String> suppressMap;
|
||||
private String filename = "sample.dummy";
|
||||
private LanguageVersion languageVersion;
|
||||
private String sourceText;
|
||||
|
||||
public DummyRoot(Map<Integer, String> suppressMap, LanguageVersion languageVersion) {
|
||||
super();
|
||||
this.suppressMap = suppressMap;
|
||||
this.languageVersion = languageVersion;
|
||||
}
|
||||
|
||||
public DummyRoot(Map<Integer, String> suppressMap) {
|
||||
this(suppressMap, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
}
|
||||
|
||||
public DummyRoot() {
|
||||
this(Collections.emptyMap());
|
||||
}
|
||||
|
||||
public DummyRoot(LanguageVersion languageVersion) {
|
||||
this(Collections.emptyMap(), languageVersion);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return languageVersion;
|
||||
}
|
||||
|
||||
public DummyRoot withLanguage(LanguageVersion languageVersion) {
|
||||
this.languageVersion = languageVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DummyRoot withFileName(String filename) {
|
||||
super.withFileName(filename);
|
||||
public DummyRoot withSourceText(String sourceText) {
|
||||
this.sourceText = sourceText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DummyRoot withNoPmdComments(Map<Integer, String> suppressMap) {
|
||||
this.suppressMap = suppressMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public DummyRoot withFileName(String filename) {
|
||||
this.filename = filename;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, String> getNoPmdComments() {
|
||||
return suppressMap;
|
||||
public AstInfo<DummyRoot> getAstInfo() {
|
||||
return new AstInfo<>(
|
||||
filename,
|
||||
languageVersion,
|
||||
sourceText,
|
||||
this,
|
||||
suppressMap
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,7 +148,7 @@ public class SummaryHTMLRendererTest extends AbstractRendererTest {
|
||||
|
||||
private Report createEmptyReportWithSuppression() throws Exception {
|
||||
|
||||
DummyRoot root = new DummyRoot(Collections.singletonMap(1, "test"));
|
||||
DummyRoot root = new DummyRoot().withNoPmdComments(Collections.singletonMap(1, "test"));
|
||||
root.setCoords(1, 10, 4, 5);
|
||||
|
||||
return RuleContextTest.getReportForRuleApply(new FooRule() {
|
||||
|
Reference in New Issue
Block a user