forked from phoedos/pmd
code review fixes:
re-enable javadocs ScalaTokenizer keeps nodes in scala for performance gain Change AST{name}Node designation to {name}
This commit is contained in:
@ -35,22 +35,6 @@
|
||||
<suppressionsLocation>pmd-scala-checkstyle-suppressions.xml</suppressionsLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Disabling the default javadoc plugin - we use scala-maven-plugin
|
||||
instead -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -16,10 +14,11 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.scala.ScalaLanguageHandler;
|
||||
import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
||||
|
||||
import scala.collection.JavaConverters;
|
||||
import scala.collection.Iterator;
|
||||
import scala.meta.Dialect;
|
||||
import scala.meta.inputs.Input;
|
||||
import scala.meta.internal.tokenizers.ScalametaTokenizer;
|
||||
import scala.meta.tokens.Token;
|
||||
|
||||
/**
|
||||
* Scala Tokenizer class. Uses the Scala Meta Tokenizer.
|
||||
@ -69,11 +68,9 @@ public class ScalaTokenizer implements Tokenizer {
|
||||
|
||||
// tokenize with a filter
|
||||
scala.meta.tokens.Tokens tokens = tokenizer.tokenize();
|
||||
List<scala.meta.tokens.Token> tokenList = JavaConverters.asJava(tokens.toList());
|
||||
ScalaTokenFilter filter = new ScalaTokenFilter(tokens.iterator());
|
||||
|
||||
ScalaTokenFilter filter = new ScalaTokenFilter(tokenList);
|
||||
|
||||
scala.meta.tokens.Token token;
|
||||
Token token;
|
||||
while ((token = filter.getNextToken()) != null) {
|
||||
String tokenText = token.text() != null ? token.text() : token.name();
|
||||
TokenEntry cpdToken = new TokenEntry(tokenText, filename, token.pos().startLine());
|
||||
@ -86,32 +83,32 @@ public class ScalaTokenizer implements Tokenizer {
|
||||
* and patterns.
|
||||
*/
|
||||
private static class ScalaTokenFilter {
|
||||
Iterator<scala.meta.tokens.Token> tokenListIter;
|
||||
Iterator<Token> tokenIter;
|
||||
|
||||
ScalaTokenFilter(List<scala.meta.tokens.Token> tokenList) {
|
||||
this.tokenListIter = tokenList.iterator();
|
||||
ScalaTokenFilter(Iterator<Token> iterator) {
|
||||
this.tokenIter = iterator.iterator();
|
||||
}
|
||||
|
||||
scala.meta.tokens.Token getNextToken() {
|
||||
if (!tokenListIter.hasNext()) {
|
||||
Token getNextToken() {
|
||||
if (!tokenIter.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
scala.meta.tokens.Token token;
|
||||
Token token;
|
||||
do {
|
||||
token = tokenListIter.next();
|
||||
} while (token != null && skipToken(token) && tokenListIter.hasNext());
|
||||
token = tokenIter.next();
|
||||
} while (token != null && skipToken(token) && tokenIter.hasNext());
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
private boolean skipToken(scala.meta.tokens.Token token) {
|
||||
private boolean skipToken(Token token) {
|
||||
boolean skip = false;
|
||||
if (token.text() != null) {
|
||||
// skip any token that is whitespaces
|
||||
skip |= token instanceof scala.meta.tokens.Token.Space || token instanceof scala.meta.tokens.Token.Tab
|
||||
|| token instanceof scala.meta.tokens.Token.CR || token instanceof scala.meta.tokens.Token.LF
|
||||
|| token instanceof scala.meta.tokens.Token.FF || token instanceof scala.meta.tokens.Token.LFLF;
|
||||
skip |= token instanceof Token.Space || token instanceof Token.Tab
|
||||
|| token instanceof Token.CR || token instanceof Token.LF
|
||||
|| token instanceof Token.FF || token instanceof Token.LFLF;
|
||||
}
|
||||
return skip;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class ScalaWrapperNode extends AbstractNode implements ScalaNode {
|
||||
|
||||
@Override
|
||||
public String getXPathNodeName() {
|
||||
return "AST" + node.productPrefix().replace(".", "") + "Node";
|
||||
return node.productPrefix().replace(".", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,9 +32,9 @@ public class ScalaParserTest {
|
||||
new StringReader(IOUtils.toString(getClass().getResourceAsStream(SCALA_TEST), "UTF-8")));
|
||||
|
||||
final List<NodeLineMatcher> nodeLineTargets = new ArrayList<NodeLineMatcher>();
|
||||
nodeLineTargets.add(new NodeLineMatcher("ASTTermNameNode", "Main", 1));
|
||||
nodeLineTargets.add(new NodeLineMatcher("ASTTypeNameNode", "App", 1));
|
||||
nodeLineTargets.add(new NodeLineMatcher("ASTTermNameNode", "println", 2));
|
||||
nodeLineTargets.add(new NodeLineMatcher("TermName", "Main", 1));
|
||||
nodeLineTargets.add(new NodeLineMatcher("TypeName", "App", 1));
|
||||
nodeLineTargets.add(new NodeLineMatcher("TermName", "println", 2));
|
||||
|
||||
ScalaParserVisitorAdapter visitor = new ScalaParserVisitorAdapter() {
|
||||
public Object visit(ScalaNode node, Object data) {
|
||||
|
@ -41,7 +41,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testPrintHelloWorld() throws Exception {
|
||||
String xpath = "//ASTTermApplyNode/ASTTermNameNode[@Image=\"println\"]";
|
||||
String xpath = "//TermApply/TermName[@Image=\"println\"]";
|
||||
rule.setXPath(xpath);
|
||||
rule.setVersion(XPathRuleQuery.XPATH_2_0);
|
||||
Report report = getReportForTestString(rule,
|
||||
|
Reference in New Issue
Block a user