mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
[codeInsight] IDEA-219640 Inspection to detect some pointless String.substring
This patch fixes the notes from the review, it contains:
1. fixing the javadoc for ExpressionUtils#isConversionToStringNecessary
2. properly handling JavaTokenType.MINUS in ExpressionUtils#isDifference
3. properly handling complex PsiPolyadicExpression values in ExpressionUtils#isDifference
4. changing ProblemHighlightType to GENERIC_ERROR_OR_WARNING for
inspecitons like these
5. fixing the comments duplication problem when replacing the old string
with a new one for inspections like stringValue.substring(0, 1).equals("_")
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 907524c9026e2d1d7cd6f0bd7b988e478e73298d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0c70f74bee
commit
565443bca4
@@ -3,16 +3,18 @@ class Foo {
|
||||
public static void main(String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int i = Integer.parseInt(args[4]);
|
||||
int i = Integer.parseInt(args[3]);
|
||||
int j = Integer.parseInt(args[4]);
|
||||
|
||||
sb.append(args[0].charAt(0));
|
||||
sb.append(args[0].charAt(2));
|
||||
sb.append(args[0].charAt(i));
|
||||
|
||||
sb.append(args[0].substring(i - 3, i - 2));
|
||||
sb.append(args[0].charAt(i - 3));
|
||||
sb.append(args[0].substring(i - 3, 2 - i));
|
||||
sb.append(args[0].substring(3 - i, i - 2));
|
||||
sb.append(args[0].substring(3 - i, 2 - i));
|
||||
sb.append(args[0].charAt(2 - i));
|
||||
|
||||
sb.append(args[0].substring(2 - i, 4 - i));
|
||||
sb.append(args[0].substring(i - 2, i - 4));
|
||||
@@ -40,5 +42,22 @@ class Foo {
|
||||
|
||||
System.out.print(args[0].substring(2, 4));
|
||||
System.out.println(args[0].substring(2, 4));
|
||||
|
||||
sb.append(args[0].charAt(i + j + 1));
|
||||
sb.append(args[0].charAt(i + j + (j + 1)));
|
||||
|
||||
sb.append(args[0].substring(i + j + 2 * j, i + j + 3 * j));
|
||||
sb.append(args[0].substring(i + j + 3 * j, i + j + 2 * j));
|
||||
|
||||
sb.append(args[0].charAt(i - j - 2));
|
||||
sb.append(args[0].charAt(i - (j + 2)));
|
||||
|
||||
sb.append(args[0].charAt(2 - (j + 2)));
|
||||
sb.append(args[0].charAt(2 - ((2 - i) - j)));
|
||||
sb.append(args[0].charAt(i - (-2*j + 3)));
|
||||
sb.append(args[0].substring(i + j * 2, i + j * 3));
|
||||
sb.append(args[0].substring(i + j * 3, i + j * 2));
|
||||
|
||||
sb.append(args[0].charAt(i - ((j - 1) - (j + 1))));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,22 @@
|
||||
// "Fix all 'Redundant String operation' problems in file" "true"
|
||||
class Foo {
|
||||
public static void main(String[] args) {
|
||||
int i = Integer.parseInt(args[2]);
|
||||
int j = Integer.parseInt(args[4]);
|
||||
|
||||
boolean value = args[0].charAt(4) == '_';
|
||||
|
||||
if(args[0].charAt(4) == '_') { }
|
||||
if(args[0].charAt(4) != '_') { }
|
||||
if(args[0].charAt(4) == '_') { }
|
||||
if(args[0].charAt(4) != '_') { }
|
||||
if (args[0].charAt(4) == '_') { }
|
||||
if (args[0].charAt(4) != '_') { }
|
||||
if (args[0].charAt(4) == '_') { }
|
||||
if (args[0].charAt(4) != '_') { }
|
||||
|
||||
if (/* one */args/* two */[/* three */ 0 /* four */].charAt(i /* five */ + 1) == 'x') { }
|
||||
/* one */
|
||||
if (args/* two */[/* three */ 0 /* four */].charAt(i /* five */ + 1) != 'x') { }
|
||||
/* one */
|
||||
if (args/* two */[/* three */ 0 /* four */].charAt(i /* five */ + 1) != 'x') { }
|
||||
|
||||
if (args[0].charAt(i - ((j - 1) - (j + 1))) == '\'') {}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ class Foo {
|
||||
public static void main(String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int i = Integer.parseInt(args[4]);
|
||||
int i = Integer.parseInt(args[3]);
|
||||
int j = Integer.parseInt(args[4]);
|
||||
|
||||
sb.append(args[0].sub<caret>string(0, 1));
|
||||
sb.append(args[0].substring(2, 3));
|
||||
@@ -13,6 +14,7 @@ class Foo {
|
||||
sb.append(args[0].substring(i - 3, 2 - i));
|
||||
sb.append(args[0].substring(3 - i, i - 2));
|
||||
sb.append(args[0].substring(3 - i, 2 - i));
|
||||
sb.append(args[0].substring(2 - i, 3 - i));
|
||||
|
||||
sb.append(args[0].substring(2 - i, 4 - i));
|
||||
sb.append(args[0].substring(i - 2, i - 4));
|
||||
@@ -40,5 +42,22 @@ class Foo {
|
||||
|
||||
System.out.print(args[0].substring(2, 4));
|
||||
System.out.println(args[0].substring(2, 4));
|
||||
|
||||
sb.append(args[0].substring(i + j + 1, i + j + 2));
|
||||
sb.append(args[0].substring(i + j + (j + 1), i + j + (j + 2)));
|
||||
|
||||
sb.append(args[0].substring(i + j + 2 * j, i + j + 3 * j));
|
||||
sb.append(args[0].substring(i + j + 3 * j, i + j + 2 * j));
|
||||
|
||||
sb.append(args[0].substring(i - j - 2, i - j - 1));
|
||||
sb.append(args[0].substring(i - (j + 2), i - (j + 1)));
|
||||
|
||||
sb.append(args[0].substring(2 - (j + 2), 3 - (j + 2)));
|
||||
sb.append(args[0].substring(2 - ((2 - i) - j), 3 - ((2 - i) - j)));
|
||||
sb.append(args[0].substring(i - (-2*j + 3), i - (-2*j + 2) ));
|
||||
sb.append(args[0].substring(i + j * 2, i + j * 3));
|
||||
sb.append(args[0].substring(i + j * 3, i + j * 2));
|
||||
|
||||
sb.append(args[0].substring(i - ((j - 1) - (j + 1)), i - ((j - 2) - (j + 1))));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,20 @@
|
||||
// "Fix all 'Redundant String operation' problems in file" "true"
|
||||
class Foo {
|
||||
public static void main(String[] args) {
|
||||
int i = Integer.parseInt(args[2]);
|
||||
int j = Integer.parseInt(args[4]);
|
||||
|
||||
boolean value = args[0].substring(4, 5).equals("_");
|
||||
|
||||
if(args[0].sub<caret>string(4, 5).equals("_")) { }
|
||||
if(!args[0].substring(4, 5).equals("_")) { }
|
||||
if(!!args[0].substring(4, 5).equals("_")) { }
|
||||
if(!!!!!args[0].substring(4, 5).equals("_")) { }
|
||||
if (args[0].sub<caret>string(4, 5).equals("_")) { }
|
||||
if (!args[0].substring(4, 5).equals("_")) { }
|
||||
if (!!args[0].substring(4, 5).equals("_")) { }
|
||||
if (!!!!!args[0].substring(4, 5).equals("_")) { }
|
||||
|
||||
if (/* one */args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x")) { }
|
||||
if (!/* one */args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x")) { }
|
||||
if (!/* one */(!!args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x"))) { }
|
||||
|
||||
if (args[0].substring(i - ((j - 1) - (j + 1)), i - ((j - 2) - (j + 1))).equals("\'")) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user