From 0710877d05b8afa34abb69f95b60d6c2e1bf5852 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 10 Apr 2020 18:50:58 +0200 Subject: [PATCH] [core] Deprecate AntlrToken#getType() in favor of #getKind() Refs #2371 --- docs/pages/release_notes.md | 1 + .../java/net/sourceforge/pmd/cpd/token/AntlrToken.java | 10 +++++++++- .../sourceforge/pmd/cpd/token/AntlrTokenFilter.java | 2 +- .../main/java/net/sourceforge/pmd/cpd/CsTokenizer.java | 6 +++--- .../java/net/sourceforge/pmd/cpd/DartTokenizer.java | 6 +++--- .../java/net/sourceforge/pmd/cpd/KotlinTokenizer.java | 4 ++-- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9978d9b8b8..a470494bab 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -123,6 +123,7 @@ implementations, and their corresponding Parser if it exists (in the same packag * {% jdoc !!core::lang.TokenManager#setFileName(java.lang.String) %} * {% jdoc !!core::lang.ast.AbstractTokenManager#setFileName(java.lang.String) %} * {% jdoc !!core::lang.ast.AbstractTokenManager#getFileName(java.lang.String) %} +* {% jdoc !!core::cpd.token.AntlrToken#getType() %} - use `getKind()` instead. ### External Contributions diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrToken.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrToken.java index 476577e325..f28544d8d4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrToken.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrToken.java @@ -64,10 +64,18 @@ public class AntlrToken implements GenericToken { return token.getCharPositionInLine() + token.getStopIndex() - token.getStartIndex(); } - public int getType() { + public int getKind() { return token.getType(); } + /** + * @deprecated use {@link #getKind()} instead. + */ + @Deprecated + public int getType() { + return getKind(); + } + public boolean isHidden() { return token.getChannel() == Lexer.HIDDEN; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrTokenFilter.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrTokenFilter.java index c76332d69e..bb29f4d120 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrTokenFilter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/token/AntlrTokenFilter.java @@ -25,6 +25,6 @@ public class AntlrTokenFilter extends BaseTokenFilter { @Override protected boolean shouldStopProcessing(final AntlrToken currentToken) { - return currentToken.getType() == EOF; + return currentToken.getKind() == EOF; } } diff --git a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java index d54c3794dd..f56ee3d1a4 100644 --- a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java +++ b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java @@ -78,7 +78,7 @@ public class CsTokenizer extends AntlrTokenizer { private void skipUsingDirectives(final AntlrToken currentToken, final Iterable remainingTokens) { if (ignoreUsings) { - final int type = currentToken.getType(); + final int type = currentToken.getKind(); if (type == CSharpLexer.USING && isUsingDirective(remainingTokens)) { discardingUsings = true; } else if (type == CSharpLexer.SEMICOLON && discardingUsings) { @@ -91,7 +91,7 @@ public class CsTokenizer extends AntlrTokenizer { private boolean isUsingDirective(final Iterable remainingTokens) { UsingState usingState = UsingState.KEYWORD; for (final AntlrToken token : remainingTokens) { - final int type = token.getType(); + final int type = token.getKind(); if (usingState == UsingState.KEYWORD) { // The previous token was a using keyword. switch (type) { @@ -147,7 +147,7 @@ public class CsTokenizer extends AntlrTokenizer { } private void skipNewLines(final AntlrToken currentToken) { - discardingNL = currentToken.getType() == CSharpLexer.NL; + discardingNL = currentToken.getKind() == CSharpLexer.NL; } @Override diff --git a/pmd-dart/src/main/java/net/sourceforge/pmd/cpd/DartTokenizer.java b/pmd-dart/src/main/java/net/sourceforge/pmd/cpd/DartTokenizer.java index d8a53823d6..6050b5bd30 100644 --- a/pmd-dart/src/main/java/net/sourceforge/pmd/cpd/DartTokenizer.java +++ b/pmd-dart/src/main/java/net/sourceforge/pmd/cpd/DartTokenizer.java @@ -52,7 +52,7 @@ public class DartTokenizer extends AntlrTokenizer { } private void skipLibraryAndImport(final AntlrToken currentToken) { - final int type = currentToken.getType(); + final int type = currentToken.getKind(); if (type == Dart2Lexer.LIBRARY || type == Dart2Lexer.IMPORT) { discardingLibraryAndImport = true; } else if (discardingLibraryAndImport && (type == Dart2Lexer.SEMICOLON || type == Dart2Lexer.NEWLINE)) { @@ -61,11 +61,11 @@ public class DartTokenizer extends AntlrTokenizer { } private void skipNewLines(final AntlrToken currentToken) { - discardingNL = currentToken.getType() == Dart2Lexer.NEWLINE; + discardingNL = currentToken.getKind() == Dart2Lexer.NEWLINE; } private void skipSemicolons(final AntlrToken currentToken) { - discardingSemicolon = currentToken.getType() == Dart2Lexer.SEMICOLON; + discardingSemicolon = currentToken.getKind() == Dart2Lexer.SEMICOLON; } @Override diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinTokenizer.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinTokenizer.java index dcfe0da1c0..35b94d48f0 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinTokenizer.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinTokenizer.java @@ -50,7 +50,7 @@ public class KotlinTokenizer extends AntlrTokenizer { } private void skipPackageAndImport(final AntlrToken currentToken) { - final int type = currentToken.getType(); + final int type = currentToken.getKind(); if (type == Kotlin.PACKAGE || type == Kotlin.IMPORT) { discardingPackageAndImport = true; } else if (discardingPackageAndImport && (type == Kotlin.SEMICOLON || type == Kotlin.NL)) { @@ -59,7 +59,7 @@ public class KotlinTokenizer extends AntlrTokenizer { } private void skipNewLines(final AntlrToken currentToken) { - discardingNL = currentToken.getType() == Kotlin.NL; + discardingNL = currentToken.getKind() == Kotlin.NL; } @Override