[scala] Fix compile errors and tests
This commit is contained in:
@@ -11,23 +11,23 @@ import scala.meta.tokens.Token;
|
|||||||
/**
|
/**
|
||||||
* Adapts the scala.meta.tokens.Token so that it can be used with the generic BaseTokenFilter
|
* Adapts the scala.meta.tokens.Token so that it can be used with the generic BaseTokenFilter
|
||||||
*/
|
*/
|
||||||
public class ScalaTokenAdapter implements GenericToken {
|
public class ScalaTokenAdapter implements GenericToken<ScalaTokenAdapter> {
|
||||||
|
|
||||||
private Token token;
|
private Token token;
|
||||||
private GenericToken previousComment;
|
private ScalaTokenAdapter previousComment;
|
||||||
|
|
||||||
ScalaTokenAdapter(Token token, GenericToken comment) {
|
ScalaTokenAdapter(Token token, ScalaTokenAdapter comment) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.previousComment = comment;
|
this.previousComment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GenericToken getNext() {
|
public ScalaTokenAdapter getNext() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GenericToken getPreviousComment() {
|
public ScalaTokenAdapter getPreviousComment() {
|
||||||
return previousComment;
|
return previousComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +56,11 @@ public class ScalaTokenAdapter implements GenericToken {
|
|||||||
return token.pos().endColumn() + 2;
|
return token.pos().endColumn() + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEof() {
|
||||||
|
return token instanceof Token.EOF;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ScalaTokenAdapter{"
|
return "ScalaTokenAdapter{"
|
||||||
|
@@ -13,7 +13,6 @@ import net.sourceforge.pmd.cpd.token.internal.BaseTokenFilter;
|
|||||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||||
import net.sourceforge.pmd.lang.TokenManager;
|
import net.sourceforge.pmd.lang.TokenManager;
|
||||||
import net.sourceforge.pmd.lang.ast.GenericToken;
|
|
||||||
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
||||||
import net.sourceforge.pmd.lang.scala.ScalaLanguageHandler;
|
import net.sourceforge.pmd.lang.scala.ScalaLanguageHandler;
|
||||||
import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
||||||
@@ -80,7 +79,7 @@ public class ScalaTokenizer implements Tokenizer {
|
|||||||
ScalaTokenManager scalaTokenManager = new ScalaTokenManager(tokens.iterator());
|
ScalaTokenManager scalaTokenManager = new ScalaTokenManager(tokens.iterator());
|
||||||
ScalaTokenFilter filter = new ScalaTokenFilter(scalaTokenManager);
|
ScalaTokenFilter filter = new ScalaTokenFilter(scalaTokenManager);
|
||||||
|
|
||||||
GenericToken token;
|
ScalaTokenAdapter token;
|
||||||
while ((token = filter.getNextToken()) != null) {
|
while ((token = filter.getNextToken()) != null) {
|
||||||
if (StringUtils.isEmpty(token.getImage())) {
|
if (StringUtils.isEmpty(token.getImage())) {
|
||||||
continue;
|
continue;
|
||||||
@@ -113,20 +112,20 @@ public class ScalaTokenizer implements Tokenizer {
|
|||||||
*
|
*
|
||||||
* Keeps track of comments, for special comment processing
|
* Keeps track of comments, for special comment processing
|
||||||
*/
|
*/
|
||||||
private static class ScalaTokenManager implements TokenManager {
|
private static class ScalaTokenManager implements TokenManager<ScalaTokenAdapter> {
|
||||||
|
|
||||||
Iterator<Token> tokenIter;
|
Iterator<Token> tokenIter;
|
||||||
Class<?>[] skippableTokens = new Class<?>[] { Token.Space.class, Token.Tab.class, Token.CR.class,
|
Class<?>[] skippableTokens = new Class<?>[] { Token.Space.class, Token.Tab.class, Token.CR.class,
|
||||||
Token.LF.class, Token.FF.class, Token.LFLF.class, Token.EOF.class, Token.Comment.class };
|
Token.LF.class, Token.FF.class, Token.LFLF.class, Token.EOF.class, Token.Comment.class };
|
||||||
|
|
||||||
GenericToken previousComment = null;
|
ScalaTokenAdapter previousComment = null;
|
||||||
|
|
||||||
ScalaTokenManager(Iterator<Token> iterator) {
|
ScalaTokenManager(Iterator<Token> iterator) {
|
||||||
this.tokenIter = iterator;
|
this.tokenIter = iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GenericToken getNextToken() {
|
public ScalaTokenAdapter getNextToken() {
|
||||||
if (!tokenIter.hasNext()) {
|
if (!tokenIter.hasNext()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -155,15 +154,10 @@ public class ScalaTokenizer implements Tokenizer {
|
|||||||
private boolean isComment(Token token) {
|
private boolean isComment(Token token) {
|
||||||
return token instanceof Token.Comment;
|
return token instanceof Token.Comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFileName(String fileName) {
|
|
||||||
throw new UnsupportedOperationException("setFileName deprecated");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ScalaTokenFilter extends BaseTokenFilter<ScalaTokenAdapter> {
|
private static class ScalaTokenFilter extends BaseTokenFilter<ScalaTokenAdapter> {
|
||||||
ScalaTokenFilter(TokenManager tokenManager) {
|
ScalaTokenFilter(TokenManager<ScalaTokenAdapter> tokenManager) {
|
||||||
super(tokenManager);
|
super(tokenManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,7 +80,6 @@ L48
|
|||||||
[threadPoolSize] 17 32
|
[threadPoolSize] 17 32
|
||||||
[=] 32 34
|
[=] 32 34
|
||||||
[16] 34 37
|
[16] 34 37
|
||||||
[// issue 194] 37 50
|
|
||||||
L50
|
L50
|
||||||
[@] 3 5
|
[@] 3 5
|
||||||
[volatile] 4 13
|
[volatile] 4 13
|
||||||
|
Reference in New Issue
Block a user