diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodFromMethodReferenceFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodFromMethodReferenceFix.java index b0c29bf641e3..74df48381201 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodFromMethodReferenceFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodFromMethodReferenceFix.java @@ -124,15 +124,16 @@ public class CreateMethodFromMethodReferenceFix extends CreateFromUsageBaseFix { final PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType); LOG.assertTrue(interfaceReturnType != null); + final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, classResolveResult); final ExpectedTypeInfo[] expectedTypes = {new ExpectedTypeInfoImpl(interfaceReturnType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, interfaceReturnType, TailType.NONE, null, ExpectedTypeInfoImpl.NULL)}; CreateMethodFromUsageFix.doCreate(targetClass, method, false, ContainerUtil.map2List(interfaceMethod.getParameterList().getParameters(), new Function>() { @Override public Pair fun(PsiParameter parameter) { - return Pair.create(null, parameter.getType()); + return Pair.create(null, substitutor.substitute(parameter.getType())); } }), - LambdaUtil.getSubstitutor(interfaceMethod, classResolveResult), + PsiSubstitutor.EMPTY, expectedTypes, context); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/afterSubstitutionParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/afterSubstitutionParams.java new file mode 100644 index 000000000000..f4c31662d976 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/afterSubstitutionParams.java @@ -0,0 +1,15 @@ +// "Create Method 'fooBar'" "true" +class FooBar { + { + Comparator c = this::fooBar; + } + + private int fooBar(String s, String s1) { + return 0; + } +} + + +interface Comparator { + int compare(T o1, T o2); +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/beforeSubstitutionParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/beforeSubstitutionParams.java new file mode 100644 index 000000000000..96dc6d176061 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef/beforeSubstitutionParams.java @@ -0,0 +1,11 @@ +// "Create Method 'fooBar'" "true" +class FooBar { + { + Comparator c = this::fooBar; + } +} + + +interface Comparator { + int compare(T o1, T o2); +} \ No newline at end of file