From 99ca901fbbf23af2f8a02f7db8c1bb505db91252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 15 Nov 2020 18:08:04 +0100 Subject: [PATCH] Update dummy module --- .../net/sourceforge/pmd/lang/ast/AstInfo.java | 16 +++++- .../net/sourceforge/pmd/AbstractRuleTest.java | 4 +- .../pmd/lang/DummyLanguageModule.java | 4 +- .../sourceforge/pmd/lang/ast/DummyNode.java | 6 -- .../sourceforge/pmd/lang/ast/DummyRoot.java | 56 +++++++++---------- .../renderers/SummaryHTMLRendererTest.java | 2 +- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AstInfo.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AstInfo.java index eb844e8f09..977e353984 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AstInfo.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AstInfo.java @@ -23,7 +23,9 @@ public final class AstInfo { private final Map suppressionComments; - public AstInfo(ParserTask task, T rootNode, Map suppressionComments) { + public AstInfo(ParserTask task, + T rootNode, + Map suppressionComments) { this.filename = task.getFileDisplayName(); this.sourceText = task.getSourceText(); this.languageVersion = task.getLanguageVersion(); @@ -31,6 +33,18 @@ public final class AstInfo { this.suppressionComments = suppressionComments; } + public AstInfo(String filename, + LanguageVersion languageVersion, + String sourceText, + T rootNode, + Map 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()); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java index 7c2233590d..b3f3377907 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java @@ -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 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); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index d5c435aa14..933f52771a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -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; }; } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java index ce9ea36efa..3594f8822e 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java @@ -15,7 +15,6 @@ public class DummyNode extends AbstractNodeWithTextCoordinates 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, RootNode { - private final Map suppressMap; + private Map suppressMap; + private String filename = "sample.dummy"; private LanguageVersion languageVersion; + private String sourceText; - public DummyRoot(Map suppressMap, LanguageVersion languageVersion) { - super(); - this.suppressMap = suppressMap; - this.languageVersion = languageVersion; - } - - public DummyRoot(Map 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 suppressMap) { + this.suppressMap = suppressMap; + return this; + } + + + public DummyRoot withFileName(String filename) { + this.filename = filename; + return this; + } + + @Override - public Map getNoPmdComments() { - return suppressMap; + public AstInfo getAstInfo() { + return new AstInfo<>( + filename, + languageVersion, + sourceText, + this, + suppressMap + ); } @Override diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java index 8e3858ea98..9b9dee24c7 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java @@ -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() {