Remove suppress map
This commit is contained in:
@ -5,7 +5,6 @@
|
||||
package net.sourceforge.pmd.lang.apex;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractParser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
@ -34,8 +33,4 @@ public class ApexParser extends AbstractParser {
|
||||
return apexParser.parse(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, String> getSuppressMap() {
|
||||
return apexParser.getSuppressMap();
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,7 @@ public class SourceCodeProcessor {
|
||||
|
||||
private Node parse(RuleContext ctx, Reader sourceCode, Parser parser) {
|
||||
try (TimedOperation to = TimeTracker.startOperation(TimedOperationCategory.PARSER)) {
|
||||
Node rootNode = parser.parse(String.valueOf(ctx.getSourceCodeFile()), sourceCode);
|
||||
ctx.getReport().suppress(parser.getSuppressMap());
|
||||
return rootNode;
|
||||
return parser.parse(String.valueOf(ctx.getSourceCodeFile()), sourceCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
|
||||
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
|
||||
|
||||
@ -61,7 +62,9 @@ public interface LanguageVersionHandler {
|
||||
/**
|
||||
* Get the RuleViolationFactory.
|
||||
*/
|
||||
RuleViolationFactory getRuleViolationFactory();
|
||||
default RuleViolationFactory getRuleViolationFactory() {
|
||||
return new AbstractRuleViolationFactory() {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -49,8 +49,4 @@ public interface Parser {
|
||||
Node parse(String fileName, Reader source) throws ParseException;
|
||||
|
||||
|
||||
// TODO Document
|
||||
default Map<Integer, String> getSuppressMap() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.TokenManager;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ecmascript.ast.ASTAstRoot;
|
||||
import net.sourceforge.pmd.lang.ecmascript5.Ecmascript5TokenManager;
|
||||
|
||||
/**
|
||||
@ -32,7 +33,7 @@ public class Ecmascript3Parser extends AbstractParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node parse(String fileName, Reader source) throws ParseException {
|
||||
public ASTAstRoot parse(String fileName, Reader source) throws ParseException {
|
||||
return ecmascriptParser.parse(source);
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,17 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ecmascript.ast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mozilla.javascript.ast.AstRoot;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
|
||||
public class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements RootNode {
|
||||
|
||||
private Map<Integer, String> noPmdComments = Collections.emptyMap();
|
||||
|
||||
public ASTAstRoot(AstRoot astRoot) {
|
||||
super(astRoot);
|
||||
}
|
||||
@ -25,6 +31,16 @@ public class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements RootN
|
||||
return node.getComments() != null ? node.getComments().size() : 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, String> getNoPmdComments() {
|
||||
return noPmdComments;
|
||||
}
|
||||
|
||||
void setNoPmdComments(Map<Integer, String> noPmdComments) {
|
||||
this.noPmdComments = noPmdComments;
|
||||
}
|
||||
|
||||
public ASTComment getComment(int index) {
|
||||
return (ASTComment) jjtGetChild(jjtGetNumChildren() - 1 - getNumComments() + index);
|
||||
}
|
||||
|
@ -58,13 +58,13 @@ public class EcmascriptParser {
|
||||
return astRoot;
|
||||
}
|
||||
|
||||
public EcmascriptNode<AstRoot> parse(final Reader reader) {
|
||||
public ASTAstRoot parse(final Reader reader) {
|
||||
try {
|
||||
final List<ParseProblem> parseProblems = new ArrayList<>();
|
||||
final String sourceCode = IOUtils.toString(reader);
|
||||
final AstRoot astRoot = parseEcmascript(sourceCode, parseProblems);
|
||||
final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(sourceCode, parseProblems);
|
||||
EcmascriptNode<AstRoot> tree = treeBuilder.build(astRoot);
|
||||
ASTAstRoot tree = (ASTAstRoot) treeBuilder.build(astRoot);
|
||||
|
||||
suppressMap = new HashMap<>();
|
||||
if (astRoot.getComments() != null) {
|
||||
@ -77,6 +77,7 @@ public class EcmascriptParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
tree.setNoPmdComments(suppressMap);
|
||||
return tree;
|
||||
} catch (IOException e) {
|
||||
throw new ParseException(e);
|
||||
|
@ -4,13 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ecmascript.rule;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptNode;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
|
||||
|
||||
public final class EcmascriptRuleViolationFactory extends AbstractRuleViolationFactory {
|
||||
|
||||
@ -18,16 +12,4 @@ public final class EcmascriptRuleViolationFactory extends AbstractRuleViolationF
|
||||
|
||||
private EcmascriptRuleViolationFactory() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) {
|
||||
return new ParametricRuleViolation<>(rule, ruleContext, (EcmascriptNode) node, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message,
|
||||
int beginLine, int endLine) {
|
||||
return null; // FIXME
|
||||
}
|
||||
}
|
||||
|
@ -141,21 +141,21 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase {
|
||||
* not implemented) with ECMAscript
|
||||
*/
|
||||
@Test
|
||||
public void testSuppresionComment() {
|
||||
public void testSuppressionComment() {
|
||||
Ecmascript3Parser parser = new Ecmascript3Parser(new EcmascriptParserOptions());
|
||||
Reader sourceCode = new StringReader("function(x) {\n" + "x = x; //NOPMD I know what I'm doing\n" + "}\n");
|
||||
parser.parse("foo", sourceCode);
|
||||
assertEquals(" I know what I'm doing", parser.getSuppressMap().get(2));
|
||||
assertEquals(1, parser.getSuppressMap().size());
|
||||
ASTAstRoot root = parser.parse("foo", sourceCode);
|
||||
assertEquals(" I know what I'm doing", root.getNoPmdComments().get(2));
|
||||
assertEquals(1, root.getNoPmdComments().size());
|
||||
|
||||
EcmascriptParserOptions parserOptions = new EcmascriptParserOptions();
|
||||
parserOptions.setSuppressMarker("FOOOO");
|
||||
parser = new Ecmascript3Parser(parserOptions);
|
||||
sourceCode = new StringReader(
|
||||
"function(x) {\n" + "y = y; //NOPMD xyz\n" + "x = x; //FOOOO I know what I'm doing\n" + "}\n");
|
||||
parser.parse("foo", sourceCode);
|
||||
assertEquals(" I know what I'm doing", parser.getSuppressMap().get(3));
|
||||
assertEquals(1, parser.getSuppressMap().size());
|
||||
root = parser.parse("foo", sourceCode);
|
||||
assertEquals(" I know what I'm doing", root.getNoPmdComments().get(3));
|
||||
assertEquals(1, root.getNoPmdComments().size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user