do not return lambda parameter type as denotable in RefactoringUtil (IDEA-136617)

This commit is contained in:
Anna Kozlova
2015-02-17 14:58:56 +01:00
parent e294ec2192
commit 6482dfe733
8 changed files with 76 additions and 4 deletions
@@ -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();
}
}
@@ -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;
}
@@ -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) {}
}
@@ -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) {}
}
@@ -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) {}
}
@@ -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();
}