forked from phoedos/pmd
[scala] Small improvements
* The system property to select the language version for the tokenizer used by CPD is called now "net.sourceforge.pmd.scala.version" * The node ASTSource is marked as RootNode * Removed (deprecated) DumpFacade solution * Removed old rulesets.properties
This commit is contained in:
@ -29,7 +29,7 @@ public class ScalaTokenizer implements Tokenizer {
|
||||
* Denotes the version of the scala dialect to use. Based on the values in
|
||||
* {@linkplain ScalaLanguageModule#getVersions()}
|
||||
*/
|
||||
public static final String SCALA_VERSION_PROPERTY = "scala_version";
|
||||
public static final String SCALA_VERSION_PROPERTY = "net.sourceforge.pmd.scala.version";
|
||||
private final Dialect dialect;
|
||||
|
||||
/**
|
||||
|
@ -4,15 +4,9 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.scala;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.VisitorStarter;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.scala.ast.DumpFacade;
|
||||
import net.sourceforge.pmd.lang.scala.ast.ScalaNode;
|
||||
import net.sourceforge.pmd.lang.scala.rule.ScalaRuleViolationFactory;
|
||||
|
||||
import scala.meta.Dialect;
|
||||
@ -52,15 +46,4 @@ public class ScalaLanguageHandler extends AbstractLanguageVersionHandler {
|
||||
public ScalaParser getParser(ParserOptions parserOptions) {
|
||||
return new ScalaParser(dialect, parserOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
|
||||
return new VisitorStarter() {
|
||||
@Override
|
||||
public void start(Node rootNode) {
|
||||
new DumpFacade().dump(writer, prefix, recurse, (ScalaNode<?>) rootNode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,80 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.scala.ast;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
|
||||
|
||||
/**
|
||||
* A Dump Facade for Scala for testing purposes.
|
||||
*/
|
||||
public class DumpFacade extends ScalaParserVisitorAdapter<String, String> {
|
||||
private PrintWriter writer;
|
||||
private boolean recurse;
|
||||
|
||||
/**
|
||||
* Write the nodes of the tree to the given writer recursively.
|
||||
*
|
||||
* @param outWriter
|
||||
* the writer to write the tree data to
|
||||
* @param prefix
|
||||
* a string prefix to use before each line in the writer
|
||||
* @param shouldRecurse
|
||||
* should this recurse below the root node?
|
||||
* @param node
|
||||
* the node to start with. Not necessarily a tree root.
|
||||
*/
|
||||
public void dump(Writer outWriter, String prefix, boolean shouldRecurse, ScalaNode<?> node) {
|
||||
this.writer = outWriter instanceof PrintWriter ? (PrintWriter) outWriter : new PrintWriter(outWriter);
|
||||
this.recurse = shouldRecurse;
|
||||
this.visit(node, prefix);
|
||||
this.writer.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ScalaNode<?> node, String data) {
|
||||
dump(node, (String) data);
|
||||
if (recurse) {
|
||||
return super.visit(node, data + " ");
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
private void dump(ScalaNode<?> node, String prefix) {
|
||||
writer.print(prefix);
|
||||
writer.print(node.getXPathNodeName());
|
||||
|
||||
String image = node.getImage();
|
||||
|
||||
String attrs = null;
|
||||
Iterator<Attribute> attributeIter = node.getXPathAttributesIterator();
|
||||
if (attributeIter.hasNext()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (attributeIter.hasNext()) {
|
||||
Attribute attr = attributeIter.next();
|
||||
sb.append(attr.getName()).append("=").append(attr.getStringValue()).append(", ");
|
||||
}
|
||||
if (sb.length() != 0) {
|
||||
attrs = sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
writer.print(":" + image);
|
||||
}
|
||||
|
||||
if (attrs != null) {
|
||||
writer.print("[");
|
||||
writer.print(attrs);
|
||||
writer.print("]");
|
||||
}
|
||||
|
||||
writer.println();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.scala.ast.nodes;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.scala.ast.ScalaParserVisitor;
|
||||
|
||||
import scala.meta.Source;
|
||||
@ -11,7 +12,7 @@ import scala.meta.Source;
|
||||
/**
|
||||
* The ASTSource node implementation.
|
||||
*/
|
||||
public class ASTSource extends AbstractScalaNode<Source> {
|
||||
public class ASTSource extends AbstractScalaNode<Source> implements RootNode {
|
||||
|
||||
/**
|
||||
* Create the AST node for this Scala node.
|
||||
|
@ -1,18 +0,0 @@
|
||||
#
|
||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
#
|
||||
|
||||
rulesets.filenames=
|
||||
|
||||
#
|
||||
# categories without rules
|
||||
#
|
||||
# category/scala/bestpractices.xml
|
||||
# category/scala/codestyle.xml
|
||||
# category/scala/design.xml
|
||||
# category/scala/documentation.xml
|
||||
# category/scala/errorprone.xml
|
||||
# category/scala/multithreading.xml
|
||||
# category/scala/performance.xml
|
||||
# category/scala/security.xml
|
||||
|
Reference in New Issue
Block a user