fix(S5838): wire quick fix for Map.get isEqualTo/isNotEqualTo#5608
fix(S5838): wire quick fix for Map.get isEqualTo/isNotEqualTo#5608asm0dey wants to merge 0 commit intoSonarSource:masterfrom
Conversation
SummaryThis PR completes the quick-fix implementation for S5838's Map.get simplification, converting The changes:
What reviewers should knowStart with: The simplifier registrations and their cleanup — understand what duplicate code was removed and why it became dead code. Type safety is key: The fix only applies to Test fixtures: Look for how the annotations changed from Quick-fix wiring: The
|
There was a problem hiding this comment.
Overall this is a well-scoped follow-up with a clear goal. The dead-code cleanup is correct and the type gate is sound. One structural concern below needs verification before merging.
Note — the following observations could not be attached as inline comments:
java-checks/src/main/java/org/sonar/java/checks/tests/AssertJChainSimplificationIndex.java:631-638: TheMAP_GETentries on lines 155 and 198 currently callmsgWithActualCustom, which hard-codesNoQuickFixvia the single-argumentWithContextSimplificationconstructor (line 637 — no second arg).
If the PR wires ActualKeyExpectedQuickFix inside msgWithActualCustom, every other caller (TO_STRING, isInstanceOf, isNotInstanceOf) would also get a quick fix, which is likely unintended.
Please confirm one of the following:
- The MAP_GET entries are changed away from
msgWithActualCustomto a dedicated factory (e.g.msgWithActualKeyExpected) that passesnew ActualKeyExpectedQuickFix(...)to the two-argumentWithContextSimplificationconstructor. - OR
msgWithActualCustomgains an overload and only the MAP_GET call sites use it.
Without this, the new ActualKeyExpectedQuickFix class will exist but its apply() result will be silently discarded by NoQuickFix.
java-checks/src/main/java/org/sonar/java/checks/tests/AssertJChainSimplificationIndex.java:156: This entry is a verbatim duplicate of line 154: both registerPATH_GET_PARENT_AND_PARENT_FILE→hasParentRawunderIS_EQUAL_TO. BecausecheckPredicatesForSimplificationcalls.findFirst()(seeAssertJChainSimplificationCheck.java:120), the second occurrence is unreachable — this is confirmed dead code introduced by#5607. The PR should delete this line.java-checks/src/main/java/org/sonar/java/checks/tests/AssertJChainSimplificationIndex.java:199: Same dead-code pattern: this entry is an exact duplicate of line 197 (TRIM/isEmptyString→isNotBlankunderIS_NOT_EQUAL_TO). TheMAP_GETentry inserted between them at line 198 split the original pair, butfindFirst()still stops at the first match, making line 199 unreachable. The PR should delete this line.java-checks-test-sources/default/src/test/java/checks/tests/AssertJChainSimplificationCheckTest_QuickFix.java:109: After the PR addsActualKeyExpectedQuickFix, the[[quickfixes=!]]annotation here must be replaced with realfix@/edit@annotations. Two separate things to verify:
isEqualTocase (this line): the edits must remove.get(x)from the subject and replaceisEqualTo(y)withcontainsEntry(x, y). Column offsets in the annotations must be exact.isNotEqualTocase (not yet in this file): the PR should add a symmetric test fordoesNotContainEntry.
Also confirm the isNotEqualTo quick-fix annotation passes the key argument correctly — the transformation is identical in structure but the predicate name differs.
Follow-up to #5607 addressing review feedback that landed after merge.
Summary
ActualKeyExpectedQuickFixto actually wire the quick fix forassertThat(map.get(k)).isEqualTo(v)→assertThat(map).containsEntry(k, v)(andisNotEqualTo→doesNotContainEntry)Map.get(key)isEqualTo/isNotEqualTo(value)#5607 around the newMAP_GETentries (PATH_GET_PARENT_AND_PARENT_FILEinIS_EQUAL_TO,TRIM/isEmptyStringinIS_NOT_EQUAL_TO);findFirstmade them dead code[[quickfixes=!]]annotation on theMap.getquick-fix fixture with realfix@/edit@annotations and add theisNotEqualTocaseCompliantnegative test forList.get(int)to lock in theofSubTypes(JAVA_UTIL_MAP)gate