-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JUnitMethodDeclarationCheck
: emit warning instead of SuggestedFix
if method name clashes
#35
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
56ac6ad
`JUnitMethodDecl`: emit warning instead of `SuggestedFix` if name cla…
rickie 302fb01
Suggestions
werli 610cce7
Tweaks
rickie 8eed4f3
Suggestions
werli 41d9692
JUnitMethodDeclaration: Prevent renaming methods to Java keywords
rickie 744b41a
JavaKeywords: Add `sealed`
rickie f2e1c73
Review `JavaKeywords`
Stephan202 c27c0ff
Suggestions
Stephan202 d9f283c
Remove unnecessary filter on generated constructor
rickie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
112 changes: 112 additions & 0 deletions
112
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,112 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Sets; | ||
|
||
final class JavaKeywords { | ||
/** | ||
* List of all reserved keywords in the Java language. | ||
* | ||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.9">JDK 17 JLS | ||
* section 3.9: Keywords</a> | ||
*/ | ||
private static final ImmutableSet<String> RESERVED_KEYWORDS = | ||
ImmutableSet.of( | ||
"_", | ||
"abstract", | ||
"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"); | ||
|
||
/** | ||
* List of all contextual keywords in the Java language. | ||
* | ||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.9">JDK 17 JLS | ||
* section 3.9: Keywords</a> | ||
*/ | ||
private static final ImmutableSet<String> CONTEXTUAL_KEYWORDS = | ||
ImmutableSet.of( | ||
"exports", | ||
"module", | ||
"non-sealed", | ||
"open", | ||
"opens", | ||
"permits", | ||
"provides", | ||
"record", | ||
"requires", | ||
"sealed", | ||
"to", | ||
"transitive", | ||
"uses", | ||
"var", | ||
"with", | ||
"yield"); | ||
|
||
/** List of all keywords in the Java language. */ | ||
private static final ImmutableSet<String> ALL_KEYWORDS = | ||
Sets.union(RESERVED_KEYWORDS, CONTEXTUAL_KEYWORDS).immutableCopy(); | ||
|
||
private JavaKeywords() {} | ||
|
||
/** Tells whether the given string is a reserved keyword in the Java language. */ | ||
public static boolean isReservedKeyword(String str) { | ||
return RESERVED_KEYWORDS.contains(str); | ||
} | ||
|
||
/** Tells whether the given string is a contextual keyword in the Java language. */ | ||
public static boolean isContextualKeyword(String str) { | ||
return CONTEXTUAL_KEYWORDS.contains(str); | ||
} | ||
|
||
/** Tells whether the given string is a reserved or contextual keyword in the Java language. */ | ||
public static boolean isKeyword(String str) { | ||
return ALL_KEYWORDS.contains(str); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're missing
abstract
and_
👀