mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not return lambda parameter type as denotable in RefactoringUtil (IDEA-136617)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import java.util.function.Supplier;
|
||||
class Test {
|
||||
|
||||
private void a()
|
||||
{
|
||||
b(<selection>(s) -> {
|
||||
System.out.println(s);
|
||||
}</selection>);
|
||||
}
|
||||
|
||||
void b(Supplier s) {}
|
||||
}
|
||||
+16
@@ -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) {}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import java.util.function.Supplier;
|
||||
class Test {
|
||||
|
||||
private void a()
|
||||
{
|
||||
b((s) -> {
|
||||
System.out.println(<selection>s</selection>);
|
||||
});
|
||||
}
|
||||
|
||||
void b(Supplier s) {}
|
||||
}
|
||||
+16
@@ -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) {}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user