mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
reuse utility method; ensure unknown functional type reduced to Object before create new psi
EA-75452 - IOE: PsiJavaParserFacadeImpl.createTypeElementFromText
This commit is contained in:
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package com.intellij.refactoring.util;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.LambdaUtil;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.psi.SmartTypePointerManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,7 +35,7 @@ public class VariableData extends AbstractVariableData {
|
||||
public VariableData(@Nullable PsiVariable var, PsiType type) {
|
||||
variable = var;
|
||||
if (var != null) {
|
||||
if (type instanceof PsiLambdaParameterType || type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType) {
|
||||
if (LambdaUtil.notInferredType(type)) {
|
||||
type = PsiType.getJavaLangObject(var.getManager(), GlobalSearchScope.allScope(var.getProject()));
|
||||
}
|
||||
this.type = SmartTypePointerManager.getInstance(var.getProject()).createSmartTypePointer(type).getType();
|
||||
|
||||
@@ -261,10 +261,7 @@ public class CreateFromUsageUtils {
|
||||
names = new String[]{"p" + i};
|
||||
}
|
||||
|
||||
if (argType == null || PsiType.NULL.equals(argType) ||
|
||||
argType instanceof PsiLambdaExpressionType ||
|
||||
argType instanceof PsiLambdaParameterType ||
|
||||
argType instanceof PsiMethodReferenceType) {
|
||||
if (argType == null || PsiType.NULL.equals(argType) || LambdaUtil.notInferredType(argType)) {
|
||||
argType = PsiType.getJavaLangObject(psiManager, resolveScope);
|
||||
} else if (argType instanceof PsiDisjunctionType) {
|
||||
argType = ((PsiDisjunctionType)argType).getLeastUpperBound();
|
||||
|
||||
@@ -78,6 +78,9 @@ public class CreateLocalFromUsageFix extends CreateVarFromUsageFix {
|
||||
final SmartTypePointer defaultType = SmartTypePointerManager.getInstance(project).createSmartTypePointer(expectedTypes[0]);
|
||||
final PsiType preferredType = TypeSelectorManagerImpl.getPreferredType(expectedTypes, expectedTypes[0]);
|
||||
PsiType type = preferredType != null ? preferredType : expectedTypes[0];
|
||||
if (LambdaUtil.notInferredType(type)) {
|
||||
type = PsiType.getJavaLangObject(myReferenceExpression.getManager(), targetClass.getResolveScope());
|
||||
}
|
||||
|
||||
String varName = myReferenceExpression.getReferenceName();
|
||||
PsiExpression initializer = null;
|
||||
|
||||
@@ -385,7 +385,7 @@ public class RefactoringUtil {
|
||||
public static PsiType getTypeByExpressionWithExpectedType(PsiExpression expr) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();
|
||||
PsiType type = getTypeByExpression(expr, factory);
|
||||
final boolean isFunctionalType = type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType || type instanceof PsiLambdaParameterType;
|
||||
final boolean isFunctionalType = LambdaUtil.notInferredType(type);
|
||||
final boolean isDenotable = PsiTypesUtil.isDenotableType(expr.getType());
|
||||
if (type != null && !isFunctionalType && isDenotable) {
|
||||
return type;
|
||||
@@ -404,9 +404,7 @@ public class RefactoringUtil {
|
||||
public static PsiType getTypeByExpression(PsiExpression expr) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();
|
||||
PsiType type = getTypeByExpression(expr, factory);
|
||||
if (type instanceof PsiLambdaParameterType ||
|
||||
type instanceof PsiLambdaExpressionType ||
|
||||
type instanceof PsiMethodReferenceType) {
|
||||
if (LambdaUtil.notInferredType(type)) {
|
||||
type = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, expr.getResolveScope());
|
||||
}
|
||||
return type;
|
||||
|
||||
@@ -42,7 +42,7 @@ class TypeCorrector extends PsiTypeMapper {
|
||||
|
||||
@Override
|
||||
public PsiType visitType(PsiType type) {
|
||||
if (type instanceof PsiLambdaParameterType || type instanceof PsiLambdaExpressionType || type instanceof PsiMethodReferenceType) {
|
||||
if (LambdaUtil.notInferredType(type)) {
|
||||
return type;
|
||||
}
|
||||
return super.visitType(type);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Create local variable 'a'" "true"
|
||||
class C {
|
||||
void foo() {
|
||||
(s) -> {
|
||||
Object a = s;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Create local variable 'a'" "true"
|
||||
class C {
|
||||
void foo() {
|
||||
(s) -> {
|
||||
<caret>a = s;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user