-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JUnitMethodDeclaration: Prevent renaming methods to Java keywords
- Loading branch information
Showing
3 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JavaKeywords.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
|
||
@SuppressWarnings("DeclarationOrder" /* The private constructor should come first. */) | ||
final class JavaKeywords { | ||
private JavaKeywords() {} | ||
|
||
/** | ||
* List of all Java Language Keywords. | ||
* | ||
* <p>See: the <a | ||
* href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html">Oracle | ||
* Documentation</a> on Java Keywords. | ||
*/ | ||
private static final ImmutableSet<String> JAVA_KEYWORDS = | ||
ImmutableSet.of( | ||
"assert", | ||
"boolean", | ||
"break", | ||
"byte", | ||
"case", | ||
"catch", | ||
"char", | ||
"class", | ||
"const", | ||
"continue", | ||
"default", | ||
"do", | ||
"double", | ||
"else", | ||
"enum", | ||
"extends", | ||
"final", | ||
"finally", | ||
"float", | ||
"for", | ||
"goto", | ||
"if", | ||
"implements", | ||
"import", | ||
"instanceof", | ||
"int", | ||
"interface", | ||
"long", | ||
"native", | ||
"new", | ||
"package", | ||
"private", | ||
"protected", | ||
"public", | ||
"return", | ||
"short", | ||
"static", | ||
"strictfp", | ||
"super", | ||
"switch", | ||
"synchronized", | ||
"this", | ||
"throw", | ||
"throws", | ||
"transient", | ||
"try", | ||
"void", | ||
"volatile", | ||
"while"); | ||
|
||
/** | ||
* Check whether the String is a Java Language Keyword. | ||
* | ||
* @param possibleKeyword a possible Java keyword | ||
* @return whether the String is a Java keyword | ||
*/ | ||
public static boolean isJavaKeyword(String possibleKeyword) { | ||
return JAVA_KEYWORDS.contains(possibleKeyword); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters