return Object if denotable type is needed for functional expression (e.g. lambda expression) type

EA-75552 - IOE: PsiElementFactoryImpl.createField
This commit is contained in:
Anna Kozlova
2015-11-02 14:14:18 +01:00
parent 58914b5ee0
commit 41916174b6
5 changed files with 31 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
@@ -215,7 +216,7 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix implement
expectedTypes = new PsiType[]{type};
}
else {
type = myMethodCall.getArgumentList().getExpressions()[0].getType();
type = RefactoringUtil.getTypeByExpression(myMethodCall.getArgumentList().getExpressions()[0]);
if (type == null || PsiType.NULL.equals(type)) type = PsiType.getJavaLangObject(manager, myMethodCall.getResolveScope());
expectedTypes = new PsiType[]{type};
}

View File

@@ -416,6 +416,12 @@ public class RefactoringUtil {
}
}
if (type instanceof PsiLambdaParameterType ||
type instanceof PsiLambdaExpressionType ||
type instanceof PsiMethodReferenceType) {
type = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, expr.getResolveScope());
}
return type;
}

View File

@@ -0,0 +1,16 @@
// "Create property" "true"
class Calculator {
private Object i;
{
setI(() -> {});
}
public void setI(Object i) {
this.i = i;
}
public Object getI() {
return i;
}
}

View File

@@ -0,0 +1,6 @@
// "Create property" "true"
class Calculator {
{
set<caret>I(() -> {});
}
}

View File

@@ -27,6 +27,6 @@ public class CreatePropertyFromUsageTest extends LightQuickFixParameterizedTestC
@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_1_5;
return LanguageLevel.JDK_1_8;
}
}