substring(x, x+y.length()).equals(y) -> startsWith(y, x) (IDEA-226148, case#1)

GitOrigin-RevId: 04fe1be3e9f48783ad8d95897497ea55109453f5
This commit is contained in:
Tagir Valeev
2019-11-22 13:26:29 +07:00
committed by intellij-monorepo-bot
parent 7f8d9a2372
commit 476b3ff5bb
6 changed files with 105 additions and 20 deletions

View File

@@ -0,0 +1,13 @@
// "Fix all 'Redundant String operation' problems in file" "true"
class X {
void test(String s, int pos, String s2) {
if (s.startsWith("xyzt", pos)) { }
if (s.substring(pos, pos + 5).equals("xyzt")) { }
if (s.startsWith(s2, pos)) { }
if (s.startsWith(s2, pos)) { }
if (s.substring(pos, pos + pos).equals(s2)) { }
if (s.startsWith("xyzt")) { }
if (s.startsWith("xyzt", 1)) { }
if (s.startsWith("xyzt", 1)) { }
}
}

View File

@@ -7,5 +7,6 @@ class X {
int posBounded = s.substring(10, 20).indexOf("foo");
int posChar = s.indexOf('f', 10);
int posIdx = s.substring(10).indexOf('f', 2);
int posFromZero = s.indexOf("xyzt") > 0;
}
}

View File

@@ -0,0 +1,13 @@
// "Fix all 'Redundant String operation' problems in file" "true"
class X {
void test(String s, int pos, String s2) {
if (s.sub<caret>string(pos, pos + 4).equals("xyzt")) { }
if (s.substring(pos, pos + 5).equals("xyzt")) { }
if (s.substring(pos, pos + s2.length()).equals(s2)) { }
if (s.substring(pos, s2.length() + pos).equals(s2)) { }
if (s.substring(pos, pos + pos).equals(s2)) { }
if (s.substring(0, 4).equals("xyzt")) { }
if (s.substring(1, 5).equals("xyzt")) { }
if (s.substring(1, 1+"xyzt".length()).equals("xyzt")) { }
}
}

View File

@@ -5,5 +5,6 @@ class X {
int posBounded = s.substring(10, 20).indexOf("foo");
int posChar = s.substring(10).indexOf('f');
int posIdx = s.substring(10).indexOf('f', 2);
int posFromZero = s.substring(0).indexOf("xyzt") > 0;
}
}