[java-inspections] RedundantStringOperation: suggest a more suitable quick-fix

IDEA-296617

GitOrigin-RevId: 03e7b3d6c733e8630e29a5867dc715daf5c1d2a9
This commit is contained in:
Andrey.Cherkasov
2022-06-24 03:29:12 +04:00
committed by intellij-monorepo-bot
parent bfc2636b4d
commit 8cebcabdc1
3 changed files with 4 additions and 1 deletions

View File

@@ -11,5 +11,6 @@ class X {
if (s.startsWith("xyzt", 1)) { }
if (s.endsWith("...")) {}
if (s.endsWith(s2)) {}
if (s.endsWith("xyzt")) {}
}
}

View File

@@ -11,5 +11,6 @@ class X {
if (s.substring(1, 1+"xyzt".length()).equals("xyzt")) { }
if (s.substring(s.length() - 3).equals("...")) {}
if (s.substring(s.length() - s2.length()).equals(s2)) {}
if (s.substring(s.length() - 4, s.length()).equals("xyzt")) {}
}
}

View File

@@ -313,10 +313,11 @@ public class RedundantStringOperationInspection extends AbstractBaseJavaLocalIns
return createSubstringToCharAtProblemDescriptor(call);
}
}
RemoveRedundantSubstringFix fix = new RemoveRedundantSubstringFix(isLengthOf(args[1], receiver) ? "endsWith" : "startsWith");
return myManager.createProblemDescriptor(anchor, (TextRange)null,
InspectionGadgetsBundle.message("inspection.redundant.string.call.message"),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly,
new RemoveRedundantSubstringFix("startsWith"));
fix);
}
}
}