mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-10 09:39:37 +07:00
IDEA didn't use to report pointless String.substring invocations for
cases when only one character in the string is extracted. In such cases
it makes more sense to use the String#charAt method because it is
allocation free.
IDEA didn't use to suggest to refactor for the code when String.substring
selects a single character and is followed by the equals method(e.g.
args[0].substring(0, 1).equals("_")) to more readable version e.g.
args[0].charAt(0) == '_'.
This patch adds such refactorings to both of the cases. It also adds
the possiblity to handle expressions like "i+1" and "i+2" to
com.siyeh.ig.psiutils.ExpressionUtils#isDifference.
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 6d179c7c9c605f08b4d4468712f8468fd68045a1
37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
// "Fix all 'Redundant String operation' problems in file" "true"
|
|
class Foo {
|
|
public static void main(String[] args) {
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
int i = 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].charAt(i + 2));
|
|
sb.append(args[0].charAt(2 + i));
|
|
sb.append(args[0].charAt(i + 2));
|
|
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));
|
|
|
|
String s1 = "xxx" + args[0].substring(3, 5);
|
|
String s2 = "xxx" + args[0].charAt(3);
|
|
String s3 = args[0].charAt(2) + "xxx";
|
|
|
|
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) != '_') { }
|
|
|
|
System.out.print(args[0].charAt(2));
|
|
System.out.println(args[0].charAt(2));
|
|
|
|
System.out.print(args[0].substring(2, 4));
|
|
System.out.println(args[0].substring(2, 4));
|
|
}
|
|
} |