mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-05 23:46:49 +07:00
for "Redundant 'String' operation" inspection GitOrigin-RevId: 96c3b5d310b9639c74241f48348257bbb83dbe93
33 lines
1.6 KiB
Java
33 lines
1.6 KiB
Java
import java.io.ByteArrayOutputStream;
|
|
|
|
class Substring {
|
|
|
|
void m(String message) {
|
|
boolean underline = message.<warning descr="'substring()' call can be replaced with 'charAt()'">substring</warning>(1, 2).equals("_");
|
|
String s1 = message.<warning descr="Call to 'substring()' is redundant">substring</warning>(message.length());
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(message.<warning descr="'substring()' call can be replaced with 'charAt()'">substring</warning>(2, 3));
|
|
if (!!!!!message.<warning descr="'substring()' call can be replaced with 'charAt()'">substring</warning>(4, 5).equals("_")) { }
|
|
String s = new <warning descr="'new String()' is redundant">String</warning>("foo");
|
|
String.valueOf(<warning descr="'new char[]' is redundant">new char[] </warning>{ 'c' });
|
|
new <warning descr="Can be replaced with 'String.valueOf()'">String</warning>(new char[] { 'c' });
|
|
String s2 = new <warning descr="'new String()' is redundant">String</warning>();
|
|
sb.append(message.<warning descr="Call to 'substring()' is redundant">substring</warning>(1, <warning descr="Unnecessary string length argument">message.length()</warning>));
|
|
sb.append(message.<warning descr="Call to 'substring()' is redundant">substring</warning>(1));
|
|
|
|
// incorrect type
|
|
if (s.substring(0, 1).equals(1)) {
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void m(StringBuilder sb, StringBuilder chars) {
|
|
sb.append(chars.<warning descr="Call to 'substring()' is redundant">substring</warning>(1, 3));
|
|
}
|
|
|
|
int z(String s) {
|
|
return s.<warning descr="Unnecessary 'toCharArray()' call">toCharArray</warning>().length;
|
|
}
|
|
} |