-
Notifications
You must be signed in to change notification settings - Fork 682
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
SONARJAVA-4462 Add quickfix support for S6485 #4461
Conversation
SonarQube Quality Gate |
7093a23
to
dd10ada
Compare
Quality Gate passedIssues Measures |
dd10ada
to
4922e8d
Compare
4922e8d
to
8a82049
Compare
|
||
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath; | ||
|
||
class KnownCapacityHashBasedCollectionCheckTest { | ||
|
||
@Test | ||
void test() { | ||
CheckVerifier.newVerifier() | ||
InternalCheckVerifier.newInstance() |
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.
I realize now that it is misleading having 2 different types of verifier, and one of them as a .withQuickFixes
method, but actually the CheckVerifier.newVerifier()
that was there before was already checking quickfixes since we introduced the analyzer-commons-api underneath, so you can undo these changes here
.forRule(this) | ||
.onTree(newClassTree) | ||
.withMessage(getIssueMessage(newClassTree)) | ||
.withQuickFixes(() -> computeQuickFix(newClassTree)) |
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.
Here we can use the singular api withQuickFix
since we always provide only one
private static List<JavaQuickFix> computeQuickFix(NewClassTree newClassTree) { | ||
String replacementMethod = TYPES_TO_METHODS.get(newClassTree.symbolType().name()).replace("(int numMappings)", ""); | ||
JavaTextEdit edit = JavaTextEdit.replaceBetweenTree(newClassTree.firstToken(), newClassTree.identifier().lastToken(), replacementMethod); | ||
JavaQuickFix quickFix = JavaQuickFix.newQuickFix("Replace with \"" + replacementMethod + "\".") | ||
.addTextEdit(edit) | ||
.build(); | ||
return List.of(quickFix); | ||
} |
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.
This can be simplified to return 1 quickfix
private static List<JavaQuickFix> computeQuickFix(NewClassTree newClassTree) { | |
String replacementMethod = TYPES_TO_METHODS.get(newClassTree.symbolType().name()).replace("(int numMappings)", ""); | |
JavaTextEdit edit = JavaTextEdit.replaceBetweenTree(newClassTree.firstToken(), newClassTree.identifier().lastToken(), replacementMethod); | |
JavaQuickFix quickFix = JavaQuickFix.newQuickFix("Replace with \"" + replacementMethod + "\".") | |
.addTextEdit(edit) | |
.build(); | |
return List.of(quickFix); | |
} | |
private static JavaQuickFix computeQuickFix(NewClassTree newClassTree) { | |
String replacementMethod = TYPES_TO_METHODS.get(newClassTree.symbolType().name()).replace("(int numMappings)", ""); | |
JavaTextEdit edit = JavaTextEdit.replaceBetweenTree(newClassTree.firstToken(), newClassTree.identifier().lastToken(), replacementMethod); | |
return JavaQuickFix.newQuickFix("Replace with \"" + replacementMethod + "\".") | |
.addTextEdit(edit) | |
.build(); | |
} |
* Use the right type of checkverifier * Set singular quickfix with matching reporting method * Remove ambiguous test with missing Java version
2bf468c
to
cfbe793
Compare
Quality Gate passedIssues Measures |
No description provided.