CPD: Remove deprecations in Mark / TokenEntry
* Provide these values for more languages
This commit is contained in:
@ -55,7 +55,8 @@ public class ApexTokenizer implements Tokenizer {
|
|||||||
if (!caseSensitive) {
|
if (!caseSensitive) {
|
||||||
tokenText = tokenText.toLowerCase(Locale.ROOT);
|
tokenText = tokenText.toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine());
|
TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine(),
|
||||||
|
token.getCharPositionInLine(), token.getCharPositionInLine() + tokenText.length());
|
||||||
tokenEntries.add(tokenEntry);
|
tokenEntries.add(tokenEntry);
|
||||||
}
|
}
|
||||||
token = lexer.nextToken();
|
token = lexer.nextToken();
|
||||||
|
@ -58,8 +58,7 @@ public abstract class AbstractTokenizer implements Tokenizer {
|
|||||||
// if ( CPD.debugEnable ) {
|
// if ( CPD.debugEnable ) {
|
||||||
// System.out.println("Token added:" + token.toString());
|
// System.out.println("Token added:" + token.toString());
|
||||||
// }
|
// }
|
||||||
tokenEntries.add(new TokenEntry(token.toString(), tokens.getFileName(), lineNumber + 1));
|
tokenEntries.add(new TokenEntry(token.toString(), tokens.getFileName(), lineNumber + 1, loc - token.length(), loc - 1));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,11 @@ public class Mark implements Comparable<Mark> {
|
|||||||
return this.token.getBeginLine();
|
return this.token.getBeginLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
|
* The column number where this duplication begins.
|
||||||
|
* returns -1 if not available
|
||||||
|
* @return the begin column number
|
||||||
|
*/
|
||||||
public int getBeginColumn() {
|
public int getBeginColumn() {
|
||||||
return this.token.getBeginColumn(); // TODO Java 1.8 make optional
|
return this.token.getBeginColumn(); // TODO Java 1.8 make optional
|
||||||
}
|
}
|
||||||
@ -35,7 +39,11 @@ public class Mark implements Comparable<Mark> {
|
|||||||
return getBeginLine() + getLineCount() - 1;
|
return getBeginLine() + getLineCount() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
|
* The column number where this duplication ends.
|
||||||
|
* returns -1 if not available
|
||||||
|
* @return the end column number
|
||||||
|
*/
|
||||||
public int getEndColumn() {
|
public int getEndColumn() {
|
||||||
return this.endToken == null ? -1 : this.endToken.getEndColumn(); // TODO Java 1.8 make optional
|
return this.endToken == null ? -1 : this.endToken.getEndColumn(); // TODO Java 1.8 make optional
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ public class TokenEntry implements Comparable<TokenEntry> {
|
|||||||
public static final TokenEntry EOF = new TokenEntry();
|
public static final TokenEntry EOF = new TokenEntry();
|
||||||
|
|
||||||
private String tokenSrcID;
|
private String tokenSrcID;
|
||||||
private int beginLine;
|
private final int beginLine;
|
||||||
private int beginColumn;
|
private final int beginColumn;
|
||||||
private int endColumn;
|
private final int endColumn;
|
||||||
private int index;
|
private int index;
|
||||||
private int identifier;
|
private int identifier;
|
||||||
private int hashCode;
|
private int hashCode;
|
||||||
@ -38,6 +38,9 @@ public class TokenEntry implements Comparable<TokenEntry> {
|
|||||||
private TokenEntry() {
|
private TokenEntry() {
|
||||||
this.identifier = 0;
|
this.identifier = 0;
|
||||||
this.tokenSrcID = "EOFMarker";
|
this.tokenSrcID = "EOFMarker";
|
||||||
|
this.beginLine = -1;
|
||||||
|
this.beginColumn = -1;
|
||||||
|
this.endColumn = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,12 +112,20 @@ public class TokenEntry implements Comparable<TokenEntry> {
|
|||||||
return beginLine;
|
return beginLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
|
* The column number where this token begins.
|
||||||
|
* returns -1 if not available
|
||||||
|
* @return the begin column number
|
||||||
|
*/
|
||||||
public int getBeginColumn() {
|
public int getBeginColumn() {
|
||||||
return beginColumn; // TODO Java 1.8 make optional
|
return beginColumn; // TODO Java 1.8 make optional
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
|
* The column number where this token ends.
|
||||||
|
* returns -1 if not available
|
||||||
|
* @return the end column number
|
||||||
|
*/
|
||||||
public int getEndColumn() {
|
public int getEndColumn() {
|
||||||
return endColumn; // TODO Java 1.8 make optional
|
return endColumn; // TODO Java 1.8 make optional
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ public class GroovyTokenizer implements Tokenizer {
|
|||||||
Token token = tokenStream.nextToken();
|
Token token = tokenStream.nextToken();
|
||||||
|
|
||||||
while (token.getType() != Token.EOF_TYPE) {
|
while (token.getType() != Token.EOF_TYPE) {
|
||||||
TokenEntry tokenEntry = new TokenEntry(token.getText(), sourceCode.getFileName(), token.getLine());
|
String tokenText = token.getText();
|
||||||
|
TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine(),
|
||||||
|
token.getColumn(), tokenText.length());
|
||||||
|
|
||||||
tokenEntries.add(tokenEntry);
|
tokenEntries.add(tokenEntry);
|
||||||
token = tokenStream.nextToken();
|
token = tokenStream.nextToken();
|
||||||
|
@ -27,7 +27,8 @@ public class EcmascriptTokenizer extends JavaCCTokenizer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TokenEntry processToken(Tokens tokenEntries, GenericToken currentToken, String filename) {
|
protected TokenEntry processToken(Tokens tokenEntries, GenericToken currentToken, String filename) {
|
||||||
return new TokenEntry(getTokenImage(currentToken), filename, currentToken.getBeginLine());
|
return new TokenEntry(getTokenImage(currentToken), filename, currentToken.getBeginLine(),
|
||||||
|
currentToken.getBeginColumn(), currentToken.getEndColumn());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTokenImage(GenericToken token) {
|
private String getTokenImage(GenericToken token) {
|
||||||
|
@ -30,7 +30,7 @@ public class JSPTokenizer implements Tokenizer {
|
|||||||
|
|
||||||
while (currentToken.image.length() > 0) {
|
while (currentToken.image.length() > 0) {
|
||||||
tokenEntries.add(new TokenEntry(String.valueOf(currentToken.kind), sourceCode.getFileName(),
|
tokenEntries.add(new TokenEntry(String.valueOf(currentToken.kind), sourceCode.getFileName(),
|
||||||
currentToken.beginLine));
|
currentToken.beginLine, currentToken.beginColumn, currentToken.endColumn));
|
||||||
currentToken = (Token) tokenMgr.getNextToken();
|
currentToken = (Token) tokenMgr.getNextToken();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -68,7 +68,8 @@ public class PLSQLTokenizer extends JavaCCTokenizer {
|
|||||||
image = String.valueOf(plsqlToken.kind);
|
image = String.valueOf(plsqlToken.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TokenEntry(image, fileName, currentToken.getBeginLine());
|
return new TokenEntry(image, fileName, currentToken.getBeginLine(),
|
||||||
|
currentToken.getBeginColumn(), currentToken.getEndColumn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,7 @@ import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
|||||||
import scala.collection.Iterator;
|
import scala.collection.Iterator;
|
||||||
import scala.meta.Dialect;
|
import scala.meta.Dialect;
|
||||||
import scala.meta.inputs.Input;
|
import scala.meta.inputs.Input;
|
||||||
|
import scala.meta.inputs.Position;
|
||||||
import scala.meta.internal.tokenizers.ScalametaTokenizer;
|
import scala.meta.internal.tokenizers.ScalametaTokenizer;
|
||||||
import scala.meta.tokens.Token;
|
import scala.meta.tokens.Token;
|
||||||
|
|
||||||
@ -74,7 +75,9 @@ public class ScalaTokenizer implements Tokenizer {
|
|||||||
Token token;
|
Token token;
|
||||||
while ((token = filter.getNextToken()) != null) {
|
while ((token = filter.getNextToken()) != null) {
|
||||||
String tokenText = token.text() != null ? token.text() : token.name();
|
String tokenText = token.text() != null ? token.text() : token.name();
|
||||||
TokenEntry cpdToken = new TokenEntry(tokenText, filename, token.pos().startLine());
|
Position tokenPosition = token.pos();
|
||||||
|
TokenEntry cpdToken = new TokenEntry(tokenText, filename, tokenPosition.startLine(),
|
||||||
|
tokenPosition.startColumn(), tokenPosition.endColumn());
|
||||||
tokenEntries.add(cpdToken);
|
tokenEntries.add(cpdToken);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -34,7 +34,7 @@ public class VfTokenizer implements Tokenizer {
|
|||||||
|
|
||||||
while (currentToken.image.length() > 0) {
|
while (currentToken.image.length() > 0) {
|
||||||
tokenEntries.add(new TokenEntry(String.valueOf(currentToken.kind), sourceCode.getFileName(),
|
tokenEntries.add(new TokenEntry(String.valueOf(currentToken.kind), sourceCode.getFileName(),
|
||||||
currentToken.beginLine));
|
currentToken.beginLine, currentToken.beginColumn, currentToken.endColumn));
|
||||||
currentToken = (Token) tokenMgr.getNextToken();
|
currentToken = (Token) tokenMgr.getNextToken();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Reference in New Issue
Block a user