diff --git a/java/java-analysis-impl/src/com/intellij/refactoring/util/VariableData.java b/java/java-analysis-impl/src/com/intellij/refactoring/util/VariableData.java
index 0fd6cc0569e4..bcb4e271d545 100644
--- a/java/java-analysis-impl/src/com/intellij/refactoring/util/VariableData.java
+++ b/java/java-analysis-impl/src/com/intellij/refactoring/util/VariableData.java
@@ -15,9 +15,8 @@
*/
package com.intellij.refactoring.util;
-import com.intellij.psi.PsiType;
-import com.intellij.psi.PsiVariable;
-import com.intellij.psi.SmartTypePointerManager;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
public class VariableData {
@@ -33,6 +32,9 @@ public class VariableData {
public VariableData(@NotNull PsiVariable var, @NotNull PsiType type) {
variable = var;
+ if (type instanceof PsiLambdaParameterType || type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType) {
+ type = PsiType.getJavaLangObject(var.getManager(), GlobalSearchScope.allScope(var.getProject()));
+ }
this.type = SmartTypePointerManager.getInstance(var.getProject()).createSmartTypePointer(type).getType();
}
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java
index 9fc5f475d029..bc05efb60871 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java
@@ -634,6 +634,12 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
if (isIdentifier(text)) {
return new NamesByExprInfo(text, getSuggestionsByName(text, variableKind, false, correctKeywords));
}
+ } else if (expr instanceof PsiFunctionalExpression) {
+ final PsiType functionalInterfaceType = ((PsiFunctionalExpression)expr).getFunctionalInterfaceType();
+ if (functionalInterfaceType != null) {
+ final String[] namesByType = suggestVariableNameByType(functionalInterfaceType, variableKind, correctKeywords);
+ return new NamesByExprInfo(null, namesByType);
+ }
}
return new NamesByExprInfo(null, ArrayUtil.EMPTY_STRING_ARRAY);
diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java
index 43758f620342..e782fd1c7847 100644
--- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java
+++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java
@@ -386,7 +386,7 @@ public class RefactoringUtil {
public static PsiType getTypeByExpressionWithExpectedType(PsiExpression expr) {
PsiType type = getTypeByExpression(expr);
- final boolean isFunctionalType = type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType;
+ final boolean isFunctionalType = type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType || type instanceof PsiLambdaParameterType;
if (type != null && !isFunctionalType) {
return type;
}
diff --git a/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression.java b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression.java
new file mode 100644
index 000000000000..016c43a73e8c
--- /dev/null
+++ b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression.java
@@ -0,0 +1,12 @@
+import java.util.function.Supplier;
+class Test {
+
+ private void a()
+ {
+ b((s) -> {
+ System.out.println(s);
+ });
+ }
+
+ void b(Supplier s) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression_after.java b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression_after.java
new file mode 100644
index 000000000000..668bc271b59d
--- /dev/null
+++ b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaExpression_after.java
@@ -0,0 +1,16 @@
+import java.util.function.Supplier;
+class Test {
+
+ private void a()
+ {
+ b(newMethod());
+ }
+
+ private Supplier newMethod() {
+ return (s) -> {
+ System.out.println(s);
+ };
+ }
+
+ void b(Supplier s) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter.java b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter.java
new file mode 100644
index 000000000000..b273927c2d1d
--- /dev/null
+++ b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter.java
@@ -0,0 +1,12 @@
+import java.util.function.Supplier;
+class Test {
+
+ private void a()
+ {
+ b((s) -> {
+ System.out.println(s);
+ });
+ }
+
+ void b(Supplier s) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter_after.java b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter_after.java
new file mode 100644
index 000000000000..668b9ede9be4
--- /dev/null
+++ b/java/java-tests/testData/refactoring/extractMethod/ExtractUnresolvedLambdaParameter_after.java
@@ -0,0 +1,16 @@
+import java.util.function.Supplier;
+class Test {
+
+ private void a()
+ {
+ b((s) -> {
+ System.out.println(newMethod((Object) s));
+ });
+ }
+
+ private boolean newMethod(Object s) {
+ return s;
+ }
+
+ void b(Supplier s) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java
index 00359a356b63..cf82ecbf0818 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java
@@ -661,6 +661,14 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
+ public void testExtractUnresolvedLambdaParameter() throws Exception {
+ doTest();
+ }
+
+ public void testExtractUnresolvedLambdaExpression() throws Exception {
+ doTest();
+ }
+
public void testTheOnlyParenthesisExpressionWhichIsSkippedInControlFlow() throws Exception {
doTest();
}