Fix compil
This commit is contained in:
parent
99ca901fbb
commit
d4ad2f5011
@ -9,7 +9,6 @@ import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
@ -17,6 +16,7 @@ import net.sourceforge.pmd.lang.apex.ast.ApexParser;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.rule.internal.ApexRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.apex.ApexJorjeLogging;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.SourceCodePositioner;
|
||||
@ -23,7 +22,7 @@ public final class ApexParser implements Parser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AstInfo<ASTApexFile> parse(final ParserTask task) {
|
||||
public ASTApexFile parse(final ParserTask task) {
|
||||
try {
|
||||
String sourceCode = task.getSourceText();
|
||||
final Compilation astRoot = CompilerService.INSTANCE.parseApex(task.getFileDisplayName(), sourceCode);
|
||||
@ -35,8 +34,7 @@ public final class ApexParser implements Parser {
|
||||
SourceCodePositioner positioner = new SourceCodePositioner(sourceCode);
|
||||
final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode, task.getCommentMarker(), positioner);
|
||||
AbstractApexNode<Compilation> treeRoot = treeBuilder.build(astRoot);
|
||||
ASTApexFile fileNode = new ASTApexFile(positioner, task, treeRoot, treeBuilder.getSuppressMap());
|
||||
return fileNode.getAstInfo();
|
||||
return new ASTApexFile(positioner, task, treeRoot, treeBuilder.getSuppressMap());
|
||||
} catch (apex.jorje.services.exception.ParseException e) {
|
||||
throw new ParseException(e);
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ import net.sourceforge.pmd.lang.LanguageFilenameFilter;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.processor.AbstractPMDProcessor;
|
||||
import net.sourceforge.pmd.processor.MonoThreadProcessor;
|
||||
import net.sourceforge.pmd.processor.MultiThreadProcessor;
|
||||
|
@ -11,8 +11,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.Report.SuppressedViolation;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.internal.DeprecatedAttrLogger;
|
||||
@ -85,8 +85,8 @@ public interface ViolationSuppressor {
|
||||
/**
|
||||
* Suppressor for regular NOPMD comments.
|
||||
*
|
||||
* @implNote This requires special support from the language, namely
|
||||
* an implementation of {@link RootNode#getNoPmdComments()}.
|
||||
* @implNote This requires special support from the language, namely,
|
||||
* the parser must fill-in {@link AstInfo#getSuppressionComments()}.
|
||||
*/
|
||||
ViolationSuppressor NOPMD_COMMENT_SUPPRESSOR = new ViolationSuppressor() {
|
||||
@Override
|
||||
@ -96,7 +96,7 @@ public interface ViolationSuppressor {
|
||||
|
||||
@Override
|
||||
public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) {
|
||||
Map<Integer, String> noPmd = node.getRoot().getNoPmdComments();
|
||||
Map<Integer, String> noPmd = node.getAstInfo().getSuppressionComments();
|
||||
if (noPmd.containsKey(rv.getBeginLine())) {
|
||||
return new SuppressedViolation(rv, this, noPmd.get(rv.getBeginLine()));
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.ast;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.internal.util.AssertionUtil;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
|
||||
@ -16,6 +18,7 @@ import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
* @param <T> Type of root nodes
|
||||
*/
|
||||
public final class AstInfo<T extends RootNode> {
|
||||
|
||||
private final String filename;
|
||||
private final LanguageVersion languageVersion;
|
||||
private final String sourceText;
|
||||
@ -23,14 +26,16 @@ public final class AstInfo<T extends RootNode> {
|
||||
private final 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();
|
||||
this.rootNode = rootNode;
|
||||
this.suppressionComments = suppressionComments;
|
||||
public AstInfo(ParserTask task, T rootNode) {
|
||||
this(task, rootNode, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public AstInfo(ParserTask task, T rootNode, Map<Integer, String> suppressionComments) {
|
||||
this(task.getFileDisplayName(),
|
||||
task.getLanguageVersion(),
|
||||
task.getSourceText(),
|
||||
rootNode,
|
||||
suppressionComments);
|
||||
}
|
||||
|
||||
public AstInfo(String filename,
|
||||
@ -38,16 +43,13 @@ public final class AstInfo<T extends RootNode> {
|
||||
String sourceText,
|
||||
T rootNode,
|
||||
Map<Integer, String> suppressionComments) {
|
||||
this.filename = filename;
|
||||
this.languageVersion = languageVersion;
|
||||
this.sourceText = sourceText;
|
||||
this.rootNode = rootNode;
|
||||
this.suppressionComments = suppressionComments;
|
||||
this.filename = AssertionUtil.requireParamNotNull("file name", filename);
|
||||
this.languageVersion = AssertionUtil.requireParamNotNull("language version", languageVersion);
|
||||
this.sourceText = AssertionUtil.requireParamNotNull("text", sourceText);
|
||||
this.rootNode = AssertionUtil.requireParamNotNull("root node", rootNode);
|
||||
this.suppressionComments = AssertionUtil.requireParamNotNull("suppress map", suppressionComments);
|
||||
}
|
||||
|
||||
public AstInfo(ParserTask task, T rootNode) {
|
||||
this(task, rootNode, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public T getRootNode() {
|
||||
return rootNode;
|
||||
@ -61,11 +63,25 @@ public final class AstInfo<T extends RootNode> {
|
||||
return sourceText;
|
||||
}
|
||||
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return languageVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map of line numbers to suppression / review comments.
|
||||
* Only single line comments are considered, that start with the configured
|
||||
* "suppressMarker", which by default is "PMD". The text after the
|
||||
* suppressMarker is used as a "review comment" and included in this map.
|
||||
*
|
||||
* <p>
|
||||
* This map is later used to determine, if a violation is being suppressed.
|
||||
* It is suppressed, if the line of the violation is contained in this suppress map.
|
||||
*
|
||||
* @return map of the suppress lines with the corresponding review comments.
|
||||
*/
|
||||
@Experimental
|
||||
public Map<Integer, String> getSuppressionComments() {
|
||||
return suppressionComments;
|
||||
}
|
||||
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return languageVersion;
|
||||
}
|
||||
}
|
||||
|
@ -320,8 +320,10 @@ public interface Node {
|
||||
|
||||
/**
|
||||
* Returns the {@link AstInfo} for this root node.
|
||||
*
|
||||
* @implNote This default implementation can not work unless overridden in the root node.
|
||||
*/
|
||||
default AstInfo getAstInfo() {
|
||||
default AstInfo<? extends RootNode> getAstInfo() {
|
||||
return getRoot().getAstInfo();
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
|
||||
/**
|
||||
* This interface identifies the root node of an AST. Each language
|
||||
* implementation must ensure that every AST its parser produces has
|
||||
@ -19,24 +13,6 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
public interface RootNode extends Node {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the map of line numbers to suppression / review comments.
|
||||
* Only single line comments are considered, that start with the configured
|
||||
* "suppressMarker", which by default is "PMD". The text after the
|
||||
* suppressMarker is used as a "review comment" and included in this map.
|
||||
*
|
||||
* <p>
|
||||
* This map is later used to determine, if a violation is being suppressed.
|
||||
* It is suppressed, if the line of the violation is contained in this suppress map.
|
||||
*
|
||||
* @return map of the suppress lines with the corresponding review comments.
|
||||
*/
|
||||
@InternalApi
|
||||
@Experimental
|
||||
default Map<Integer, String> getNoPmdComments() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
AstInfo<? extends RootNode> getAstInfo();
|
||||
|
||||
|
@ -27,9 +27,9 @@ import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.AstAnalysisContext;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.AstAnalysisContext;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
|
||||
|
@ -20,12 +20,12 @@ import net.sourceforge.pmd.RuleSets;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.ast.DummyAstStages;
|
||||
import net.sourceforge.pmd.lang.ast.DummyNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
|
@ -4,17 +4,20 @@
|
||||
|
||||
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 Map<Integer, String> suppressMap;
|
||||
private Map<Integer, String> suppressMap = Collections.emptyMap();
|
||||
private String filename = "sample.dummy";
|
||||
private LanguageVersion languageVersion;
|
||||
private String sourceText;
|
||||
private LanguageVersion languageVersion = LanguageRegistry.findLanguageByTerseName(DummyLanguageModule.TERSE_NAME).getDefaultVersion();
|
||||
private String sourceText = "dummy text";
|
||||
|
||||
|
||||
public DummyRoot withLanguage(LanguageVersion languageVersion) {
|
||||
|
@ -8,8 +8,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParser;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.ecmascript;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser;
|
||||
|
||||
class EcmascriptHandler extends AbstractPmdLanguageVersionHandler {
|
||||
|
@ -4,33 +4,22 @@
|
||||
|
||||
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.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
|
||||
public final class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements RootNode {
|
||||
|
||||
private Map<Integer, String> noPmdComments = Collections.emptyMap();
|
||||
private LanguageVersion languageVersion;
|
||||
private String filename;
|
||||
private AstInfo<ASTAstRoot> astInfo;
|
||||
|
||||
public ASTAstRoot(AstRoot astRoot) {
|
||||
super(astRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return languageVersion;
|
||||
}
|
||||
|
||||
void addTaskInfo(ParserTask languageVersion) {
|
||||
this.languageVersion = languageVersion.getLanguageVersion();
|
||||
this.filename = languageVersion.getFileDisplayName();
|
||||
public AstInfo<ASTAstRoot> getAstInfo() {
|
||||
return astInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,16 +32,11 @@ public final class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, String> getNoPmdComments() {
|
||||
return noPmdComments;
|
||||
}
|
||||
|
||||
void setNoPmdComments(Map<Integer, String> noPmdComments) {
|
||||
this.noPmdComments = noPmdComments;
|
||||
}
|
||||
|
||||
public ASTComment getComment(int index) {
|
||||
return (ASTComment) getChild(getNumChildren() - 1 - getNumComments() + index);
|
||||
}
|
||||
|
||||
void setAstInfo(AstInfo<ASTAstRoot> astInfo) {
|
||||
this.astInfo = astInfo;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.mozilla.javascript.ast.ErrorCollector;
|
||||
import org.mozilla.javascript.ast.ParseProblem;
|
||||
|
||||
import net.sourceforge.pmd.internal.util.AssertionUtil;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
@ -71,7 +72,7 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars
|
||||
}
|
||||
}
|
||||
}
|
||||
tree.setNoPmdComments(suppressMap);
|
||||
tree.setAstInfo(new AstInfo<>(task, tree, suppressMap));
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
@ -147,14 +147,14 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase {
|
||||
ASTAstRoot root = js.parse("function(x) {\n"
|
||||
+ "x = x; //NOPMD I know what I'm doing\n"
|
||||
+ "}\n");
|
||||
assertEquals(" I know what I'm doing", root.getNoPmdComments().get(2));
|
||||
assertEquals(1, root.getNoPmdComments().size());
|
||||
assertEquals(" I know what I'm doing", root.getAstInfo().getSuppressionComments().get(2));
|
||||
assertEquals(1, root.getAstInfo().getSuppressionComments().size());
|
||||
|
||||
ParserOptions parserOptions = new ParserOptions();
|
||||
parserOptions.setSuppressMarker("FOOOO");
|
||||
root = js.withParserOptions(parserOptions).parse("function(x) {\n" + "y = y; //NOPMD xyz\n" + "x = x; //FOOOO I know what I'm doing\n" + "}\n");
|
||||
assertEquals(" I know what I'm doing", root.getNoPmdComments().get(3));
|
||||
assertEquals(1, root.getNoPmdComments().size());
|
||||
assertEquals(" I know what I'm doing", root.getAstInfo().getSuppressionComments().get(3));
|
||||
assertEquals(1, root.getAstInfo().getSuppressionComments().size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.jsp;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.jsp.ast.JspParser;
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.jsp.ast;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.modelica;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ModelicaParser;
|
||||
import net.sourceforge.pmd.lang.modelica.internal.ModelicaProcessingStage;
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.plsql;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.plsql.ast.PLSQLParser;
|
||||
|
||||
/**
|
||||
|
@ -21,9 +21,9 @@ public final class ASTInput extends AbstractPLSQLNode implements RootNode {
|
||||
return astInfo;
|
||||
}
|
||||
|
||||
AstInfo<ASTInput> addTaskInfo(ParserTask task) {
|
||||
ASTInput addTaskInfo(ParserTask task) {
|
||||
this.astInfo = new AstInfo<>(task, this);
|
||||
return astInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.plsql.ast;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;
|
||||
@ -25,7 +24,7 @@ public class PLSQLParser extends JjtreeParserAdapter<ASTInput> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AstInfo<ASTInput> parseImpl(CharStream cs, ParserTask task) throws ParseException {
|
||||
protected ASTInput parseImpl(CharStream cs, ParserTask task) throws ParseException {
|
||||
return new PLSQLParserImpl(cs).Input().addTaskInfo(task);
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,6 @@ public class ScalaLanguageHandler extends AbstractPmdLanguageVersionHandler {
|
||||
|
||||
@Override
|
||||
public ScalaParser getParser(ParserOptions parserOptions) {
|
||||
return new ScalaParser(dialect, parserOptions);
|
||||
return new ScalaParser(dialect);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.scala.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
|
||||
import scala.meta.Source;
|
||||
@ -13,10 +15,22 @@ import scala.meta.Source;
|
||||
*/
|
||||
public final class ASTSource extends AbstractScalaNode<Source> implements RootNode {
|
||||
|
||||
private AstInfo<ASTSource> astInfo;
|
||||
|
||||
ASTSource(Source scalaNode) {
|
||||
super(scalaNode);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AstInfo<ASTSource> getAstInfo() {
|
||||
return astInfo;
|
||||
}
|
||||
|
||||
void addTaskInfo(ParserTask task) {
|
||||
this.astInfo = new AstInfo<>(task, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <P, R> R acceptVisitor(ScalaParserVisitor<? super P, ? extends R> visitor, P data) {
|
||||
return visitor.visit(this, data);
|
||||
|
@ -4,14 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.scala.ast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractParser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
|
||||
import scala.meta.Dialect;
|
||||
import scala.meta.Source;
|
||||
@ -23,7 +17,7 @@ import scala.meta.internal.parsers.ScalametaParser;
|
||||
* Scalameta. This parser then wraps all of ScalaMeta's Nodes in Java versions
|
||||
* for compatibility.
|
||||
*/
|
||||
public final class ScalaParser extends AbstractParser {
|
||||
public final class ScalaParser implements Parser {
|
||||
private final Dialect dialect;
|
||||
|
||||
/**
|
||||
@ -31,25 +25,18 @@ public final class ScalaParser extends AbstractParser {
|
||||
*
|
||||
* @param scalaDialect
|
||||
* the Scala Dialect for this parser
|
||||
* @param parserOptions
|
||||
* any additional options for this parser
|
||||
*/
|
||||
public ScalaParser(Dialect scalaDialect, ParserOptions parserOptions) {
|
||||
super(parserOptions);
|
||||
public ScalaParser(Dialect scalaDialect) {
|
||||
this.dialect = scalaDialect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTSource parse(String fileName, Reader source) throws ParseException {
|
||||
Input.VirtualFile virtualFile;
|
||||
try {
|
||||
String sourceString = IOUtils.toString(source);
|
||||
virtualFile = new Input.VirtualFile(fileName, sourceString);
|
||||
} catch (IOException e) {
|
||||
throw new ParseException(e);
|
||||
}
|
||||
public ASTSource parse(ParserTask task) throws ParseException {
|
||||
Input.VirtualFile virtualFile = new Input.VirtualFile(task.getFileDisplayName(), task.getSourceText());
|
||||
Source src = new ScalametaParser(virtualFile, dialect).parseSource();
|
||||
return (ASTSource) new ScalaTreeBuilder().build(src);
|
||||
ASTSource root = (ASTSource) new ScalaTreeBuilder().build(src);
|
||||
root.addTaskInfo(task);
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,15 @@
|
||||
|
||||
package net.sourceforge.pmd.test.lang;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.BaseLanguageModule;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory;
|
||||
import net.sourceforge.pmd.test.lang.ast.DummyNode;
|
||||
@ -55,16 +59,21 @@ public class DummyLanguageModule extends BaseLanguageModule {
|
||||
public static class DummyRootNode extends DummyNode implements RootNode {
|
||||
|
||||
|
||||
private LanguageVersion languageVersion;
|
||||
private LanguageVersion languageVersion = LanguageRegistry.findLanguageByTerseName(DummyLanguageModule.TERSE_NAME).getDefaultVersion();
|
||||
|
||||
@Override
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return languageVersion;
|
||||
public void setLanguageVersion(LanguageVersion languageVersion) {
|
||||
this.languageVersion = languageVersion;
|
||||
}
|
||||
|
||||
public DummyRootNode setLanguageVersion(LanguageVersion languageVersion) {
|
||||
this.languageVersion = languageVersion;
|
||||
return this;
|
||||
@Override
|
||||
public AstInfo<DummyRootNode> getAstInfo() {
|
||||
return new AstInfo<>(
|
||||
"sample.dummy",
|
||||
languageVersion,
|
||||
"dummy text",
|
||||
this,
|
||||
Collections.emptyMap()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.vf;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfParser;
|
||||
|
||||
public class VfHandler extends AbstractPmdLanguageVersionHandler {
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.vm;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.vm.ast.VmParser;
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.vm.ast;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
|
||||
|
@ -5,8 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.xml;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
|
||||
/**
|
||||
* Implementation of LanguageVersionHandler for the XML.
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.xml;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.xml.ast.internal.XmlParserImpl;
|
||||
import net.sourceforge.pmd.lang.xml.ast.internal.XmlParserImpl.RootXmlNode;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user