Java: Improved inspection "MethodHandle/VarHandle type mismatch" - show candidates for replacement of method/constructor in a separate pop-up menu (IDEA-167318)

This commit is contained in:
Pavel Dolgov
2017-03-17 15:15:45 +03:00
parent 741b74a23a
commit d81332e1f8
60 changed files with 268 additions and 105 deletions
@@ -0,0 +1,13 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, MethodType.methodType(void.class, int.class));
}
}
class Test {
public Test() {}
public Test(int a) {}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, MethodType.methodType(void.class, int.class));
}
}
class Test {
public Test(int a) {}
}
@@ -0,0 +1,11 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, MethodType.methodType(void.class));
}
}
class Test {
}
@@ -0,0 +1,13 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, MethodType.methodType(void.class));
}
}
class Test {
public Test() {}
public Test(int a) {}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(Object.class, Object.class));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(Object.class, Object.class, Object[].class));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(Object.class, Object.class, String.class));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(Object.class, Object.class));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", MethodType.methodType(String.class, String.class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", MethodType.methodType(String.class, String.class, String[].class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public static void method() {}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.findVirtual(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(String.class, String.class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", MethodType.methodType(String.class, String.class, String[].class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.findVirtual(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public void method() {}
}
@@ -0,0 +1,13 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, <caret>MethodType.methodType(void.class, String.class));
}
}
class Test {
public Test() {}
public Test(int a) {}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, <caret>MethodType.methodType(void.class));
}
}
class Test {
public Test(int a) {}
}
@@ -0,0 +1,11 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, <caret>MethodType.methodType(void.class, String.class));
}
}
class Test {
}
@@ -0,0 +1,13 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findConstructor(Test.class, <caret>MethodType.methodType(void.class, String.class));
}
}
class Test {
public Test() {}
public Test(int a) {}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.genericMethodType(2));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.genericMethodType(2));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.genericMethodType(2));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.genericMethodType(0, true));
}
}
class Test {
public <T> T method(T a) {return null;}
public <T> T method(T a, T... b) {return null;}
public <T> T method(T a, String b) {return null;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", <caret>MethodType.methodType(String.class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", <caret>MethodType.methodType(void.class, void.class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findStatic(Test.class, "method", <caret>MethodType.methodType(String.class));
}
}
class Test {
public static void method() {}
public static String method(String a) {return a;}
public static String method(String a, String... b) {return a;}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.<caret>findVirtual(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public static void method() {}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.findVirtual(Test.class, "method", <caret>MethodType.methodType(String.class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.methodType(void.class, void.class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,14 @@
import java.lang.invoke.*;
class Main {
void foo() throws Exception {
MethodHandles.Lookup l = MethodHandles.lookup();
l.findVirtual(Test.class, "method", <caret>MethodType.methodType(String.class));
}
}
class Test {
public void method() {}
public String method(String a) {return a;}
public String method(String a, String... b) {return a;}
}
@@ -0,0 +1,12 @@
import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.<caret>findStatic(Test.class, "method", MethodType.methodType(void.class));
}
}
class Test {
public void method() {}
}