Add UseLocaleWithCaseConversions recipe for STR02-J (#78)#944
Open
kush2439p wants to merge 7 commits into
Open
Add UseLocaleWithCaseConversions recipe for STR02-J (#78)#944kush2439p wants to merge 7 commits into
kush2439p wants to merge 7 commits into
Conversation
…has dependent type params (<T, S extends T>) Adds hasDependentTypeParameters() check so that explicit type arguments are preserved when the enclosing method has a type parameter whose bound references another type parameter of the same method (e.g. <T, S extends T>). Also adds a regression test covering the minimal reproduction from the issue.
This class specifies a Locale for case conversions to avoid locale-dependent issues.
…ConversionsTest.java
Author
|
Opened a PR for this: adds |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Adds a new recipe,
UseLocaleWithCaseConversions, implementing STR02-J: it rewritesString#toLowerCase()/String#toUpperCase()calls that don't specify aLocaletoexplicitly pass
Locale.ROOT(or a user-configured locale). This avoids locale-dependentcase-conversion bugs — e.g. converting
"I"to lowercase under a Turkish locale yields adotless
ıinstead of the expectedi.STR02-J#78Changes
UseLocaleWithCaseConversions: new recipe with an optional@Option locale(defaults to
ROOTif not provided, per the issue's request), usingMethodMatcher+JavaTemplateto rewrite the method call andmaybeAddImportfor theLocaleimport.toLowerCase()→toLowerCase(Locale.ROOT),toUpperCase()→toUpperCase(Locale.ROOT), no-op when aLocaleis already specified, and aconfigured non-default locale.
common-static-analysis.yml: registered the recipe, but commented out / opt-in,since it changes case-conversion semantics (not just style) for one of the most
commonly called
Stringmethods. Happy to discuss making it active-by-default ifmaintainers feel differently.
Example
Backward compatibility
Since the recipe is registered as opt-in (commented out in
common-static-analysis.yml),existing users of
CommonStaticAnalysissee no behavior change unless they explicitlyactivate this recipe.