mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 11:00:04 +07:00
Java: In the inspection that checks existence of methods accessed via reflection take into account type information from Class.newInstance() and Array.newInstance() (IDEA-172003)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
class Vararg {
|
||||
void foo() throws Exception {
|
||||
A.class.getConstructor(B[].class);
|
||||
A.class.getMethod("bar", int.class, B[].class);
|
||||
A.class.getMethod("bar", B.class);
|
||||
|
||||
A.class.getConstructor<warning descr="Cannot resolve constructor with specified argument types">(B.class)</warning>;
|
||||
A.class.getMethod(<warning descr="Cannot resolve method 'bar' with specified argument types">"bar"</warning>, int.class, B.class);
|
||||
|
||||
Class<?> a = Class.forName("A");
|
||||
Class<?> b = Class.forName("B");
|
||||
Object bb = Array.newInstance(b, 1);
|
||||
Class<?> bc = bb.getClass();
|
||||
Object o = b.newInstance();
|
||||
Class<?> oc = o.getClass();
|
||||
a.getConstructor(bc);
|
||||
a.getMethod("bar", String.class, bc);
|
||||
a.getMethod("bar", oc);
|
||||
|
||||
a.getConstructor<warning descr="Cannot resolve constructor with specified argument types">(B.class)</warning>;
|
||||
a.getMethod(<warning descr="Cannot resolve method 'bar' with specified argument types">"bar"</warning>, String.class, B.class);
|
||||
a.getMethod(<warning descr="Cannot resolve method 'bar' with specified argument types">"bar"</warning>, B[].class);
|
||||
|
||||
ourA.getConstructor(bc);
|
||||
ourA.getMethod("bar", String.class, Array.newInstance(myB, 0).getClass());
|
||||
ourA.getMethod("bar", myB.newInstance().getClass());
|
||||
}
|
||||
|
||||
static final Class<?> ourA;
|
||||
static {
|
||||
try {
|
||||
ourA = Class.forName("A");
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
final Class<?> myB;
|
||||
{
|
||||
myB = Class.forName("B");
|
||||
}
|
||||
|
||||
Vararg(int n) throws Exception {
|
||||
Object bb = Array.newInstance(myB, n);
|
||||
Class<?> bc = bb.getClass();
|
||||
ourA.getConstructor(bc);
|
||||
ourA.getMethod("bar", String.class, bc);
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public A(B... b) {}
|
||||
public void bar(int n, B... b) {}
|
||||
public void bar(String s, B... b) {}
|
||||
public void bar(B b) {}
|
||||
}
|
||||
|
||||
class B {}
|
||||
Reference in New Issue
Block a user