mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-209951 Inspection to detect when collection is accidentally passed as vararg and will be wrapped into one-element array
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
// "Call 'toArray(new String[0])'" "true"
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
class Test {
|
||||
static <T> boolean contains(T needle, T... haystack) {
|
||||
for (final T t : haystack) {
|
||||
if (Objects.equals(t, needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void use(List<String> list, String s) {
|
||||
if (contains(s, list.toArray(new String[0]))) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Call 'toArray(new String[0])'" "true"
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
class Test {
|
||||
static <T> boolean contains(T needle, T... haystack) {
|
||||
for (final T t : haystack) {
|
||||
if (Objects.equals(t, needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void use(List<String> list, String s) {
|
||||
if (contains(s, <caret>list)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Call 'toArray(new String[0])'" "false"
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
class Test {
|
||||
static <T> boolean contains(T needle, T... haystack) {
|
||||
for (final T t : haystack) {
|
||||
if (Objects.equals(t, needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void useOk(List<String> list, List<String> s) {
|
||||
if (contains(s, <caret>list)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user