From 81f3fcdfa155f4e7e6dd6bc5592ad41e02f815de Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 5 Sep 2017 15:49:30 +0300 Subject: [PATCH] GuessTypeParameters: use expected type instead of inplace type element 2 --- .../impl/quickfix/GuessTypeParameters.java | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GuessTypeParameters.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GuessTypeParameters.java index 1ff849bb62e1..c65856042ad7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GuessTypeParameters.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GuessTypeParameters.java @@ -26,7 +26,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -72,36 +71,28 @@ public class GuessTypeParameters { return; } - PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory(); PsiType type = info.getType(); PsiType defaultType = info.getDefaultType(); - try { - PsiTypeElement inplaceTypeElement = ((PsiVariable)factory.createVariableDeclarationStatement("foo", type, null).getDeclaredElements()[0]).getTypeElement(); - - PsiSubstitutor rawingSubstitutor = getRawingSubstitutor (myProject, context, targetClass); - int substitionResult = hasNullSubstitutions(substitutor) ? SUBSTITUTED_NONE : substituteToTypeParameters(typeElement, type, substitutor, builder, rawingSubstitutor, true); - if (substitionResult != SUBSTITUTED_NONE) { - if (substitionResult == SUBSTITUTED_IN_PARAMETERS) { - PsiJavaCodeReferenceElement refElement = typeElement.getInnermostComponentReferenceElement(); - LOG.assertTrue(refElement != null && refElement.getReferenceNameElement() != null); - type = getComponentType(type); - LOG.assertTrue(type != null); - defaultType = getComponentType(defaultType); - LOG.assertTrue(defaultType != null); - ExpectedTypeInfo info1 = ExpectedTypesProvider.createInfo(((PsiClassType)defaultType).rawType(), - TYPE_STRICTLY, - ((PsiClassType)defaultType).rawType(), - info.getTailType()); - MyTypeVisitor visitor = new MyTypeVisitor(manager, scope); - builder.replaceElement(refElement.getReferenceNameElement(), - new TypeExpression(myProject, ExpectedTypesProvider.processExpectedTypes(new ExpectedTypeInfo[]{info1}, visitor, myProject))); - } - - return; + PsiSubstitutor rawingSubstitutor = getRawingSubstitutor(myProject, context, targetClass); + int substitionResult = hasNullSubstitutions(substitutor) ? SUBSTITUTED_NONE : substituteToTypeParameters(typeElement, type, substitutor, builder, rawingSubstitutor, true); + if (substitionResult != SUBSTITUTED_NONE) { + if (substitionResult == SUBSTITUTED_IN_PARAMETERS) { + PsiJavaCodeReferenceElement refElement = typeElement.getInnermostComponentReferenceElement(); + LOG.assertTrue(refElement != null && refElement.getReferenceNameElement() != null); + type = getComponentType(type); + LOG.assertTrue(type != null); + defaultType = getComponentType(defaultType); + LOG.assertTrue(defaultType != null); + ExpectedTypeInfo info1 = ExpectedTypesProvider.createInfo(((PsiClassType)defaultType).rawType(), + TYPE_STRICTLY, + ((PsiClassType)defaultType).rawType(), + info.getTailType()); + MyTypeVisitor visitor = new MyTypeVisitor(manager, scope); + builder.replaceElement(refElement.getReferenceNameElement(), + new TypeExpression(myProject, ExpectedTypesProvider.processExpectedTypes(new ExpectedTypeInfo[]{info1}, visitor, myProject))); } - } - catch (IncorrectOperationException e) { - LOG.error(e); + + return; } }