@NotNull private String inferTypeArguments(final PsiMethodCallExpression methodCallExpression) { final PsiReferenceParameterList list = methodCallExpression.getMethodExpression().getParameterList(); if (list != null && list.getTypeArguments().length > 0) { return list.getText(); } final PsiTypeParameter[] methodTypeParameters = getMethod().getTypeParameters(); if (methodTypeParameters.length > 0) { List<String> typeSignature = new ArrayList<String>(); final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(getMethod().getProject()).getResolveHelper(); for (final PsiTypeParameter typeParameter : methodTypeParameters) { final PsiType type = resolveHelper.inferTypeForMethodTypeParameter(typeParameter, getMethod().getParameterList().getParameters(), methodCallExpression.getArgumentList().getExpressions(), PsiSubstitutor.EMPTY, methodCallExpression, DefaultParameterTypeInferencePolicy.INSTANCE); if (type == null || PsiType.NULL.equals(type)) { return ""; } typeSignature.add(type.getPresentableText()); } return "<" + StringUtil.join(typeSignature, ", ") + ">"; } return ""; }
public InferenceSession(InitialInferenceState initialState) { myContext = initialState.getContext(); myManager = myContext.getManager(); myInferenceSubstitution = initialState.getInferenceSubstitutor(); myInferenceVariables.addAll(initialState.getInferenceVariables()); mySiteSubstitutor = initialState.getSiteSubstitutor(); for(Pair<InferenceVariable[], PsiClassType> capture : initialState.getCaptures()) { myIncorporationPhase.addCapture(capture.first, capture.second); } myInferenceSessionContainer = initialState.getInferenceSessionContainer(); myErased = initialState.isErased(); myPolicy = DefaultParameterTypeInferencePolicy.INSTANCE; }
public InferenceSession(PsiTypeParameter[] typeParams, PsiType[] leftTypes, PsiType[] rightTypes, PsiSubstitutor siteSubstitutor, PsiManager manager, PsiElement context) { myManager = manager; mySiteSubstitutor = siteSubstitutor; myContext = context; initBounds(typeParams); LOG.assertTrue(leftTypes.length == rightTypes.length); for(int i = 0; i < leftTypes.length; i++) { final PsiType rightType = mySiteSubstitutor.substitute(rightTypes[i]); PsiType t = substituteWithInferenceVariables(leftTypes[i]); PsiType s = substituteWithInferenceVariables(rightType); if(t != null && s != null) { addConstraint(new TypeCompatibilityConstraint(t, s)); } } myPolicy = DefaultParameterTypeInferencePolicy.INSTANCE; }
@NotNull public PsiSubstitutor getSubstitutor(boolean includeReturnConstraint) { PsiSubstitutor substitutor = myCalcedSubstitutor; if (substitutor == null || !includeReturnConstraint && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) || isOverloadCheck()) { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); PsiMethod method = getElement(); if (myTypeArguments == null) { final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack(); final PsiSubstitutor inferredSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE, includeReturnConstraint); if (!stackStamp.mayCacheNow() || isOverloadCheck() || !includeReturnConstraint && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) || getMarkerList() != null && PsiResolveHelper.ourGraphGuard.currentStack().contains(getMarkerList().getParent())) { return inferredSubstitutor; } myCalcedSubstitutor = substitutor = inferredSubstitutor; } else { PsiTypeParameter[] typeParams = method.getTypeParameters(); for (int i = 0; i < myTypeArguments.length && i < typeParams.length; i++) { incompleteSubstitutor = incompleteSubstitutor.put(typeParams[i], myTypeArguments[i]); } myCalcedSubstitutor = substitutor = incompleteSubstitutor; } } return substitutor; }
private PsiSubstitutor inferTypeArguments() { final JavaPsiFacade facade = JavaPsiFacade.getInstance(myNewExpression.getProject()); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); final PsiParameter[] parameters = myTargetMethod.getParameterList().getParameters(); final PsiExpressionList argumentList = myNewExpression.getArgumentList(); LOG.assertTrue(argumentList != null); final PsiExpression[] expressions = argumentList.getExpressions(); return resolveHelper.inferTypeArguments(myPsiClass.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, myNewExpression.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE); }
private static void inferTypeArgs(HighlightInfo highlightInfo, PsiType lType, PsiExpression thenExpression) { final JavaResolveResult result = ((PsiMethodCallExpression)thenExpression).resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); if (method != null) { final PsiType returnType = method.getReturnType(); final PsiClass aClass = method.getContainingClass(); if (returnType != null && aClass != null && aClass.getQualifiedName() != null) { final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(method.getProject()); final PsiDeclarationStatement variableDeclarationStatement = javaPsiFacade.getElementFactory().createVariableDeclarationStatement("xxx", lType, thenExpression); final PsiExpression initializer = ((PsiLocalVariable)variableDeclarationStatement.getDeclaredElements()[0]).getInitializer(); LOG.assertTrue(initializer != null); final PsiSubstitutor substitutor = javaPsiFacade.getResolveHelper() .inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(), ((PsiMethodCallExpression)thenExpression).getArgumentList().getExpressions(), PsiSubstitutor.EMPTY, initializer, DefaultParameterTypeInferencePolicy.INSTANCE); PsiType substitutedType = substitutor.substitute(returnType); if (substitutedType != null && TypeConversionUtil.isAssignable(lType, substitutedType)) { QuickFixAction.registerQuickFixAction(highlightInfo, thenExpression.getTextRange(), new AddTypeArgumentsConditionalFix(substitutor, (PsiMethodCallExpression)thenExpression, method)); } } } }
@Nullable public static PsiSubstitutor inferSubstitutor(final PsiMethod method, final PsiMethodCallExpression callExpr, boolean forCompletion) { final PsiResolveHelper helper = JavaPsiFacade.getInstance(method.getProject()).getResolveHelper(); final PsiParameter[] parameters = method.getParameterList().getParameters(); PsiExpression[] args = callExpr.getArgumentList().getExpressions(); PsiSubstitutor result = PsiSubstitutor.EMPTY; for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(method.getContainingClass())) { PsiType type = helper.inferTypeForMethodTypeParameter(typeParameter, parameters, args, PsiSubstitutor.EMPTY, callExpr.getParent(), forCompletion ? CompletionParameterTypeInferencePolicy.INSTANCE : DefaultParameterTypeInferencePolicy.INSTANCE); if (PsiType.NULL.equals(type)) return null; result = result.put(typeParameter, type); } return result; }
private static void substituteTypeParametersInInitializer(PsiElement initializer, PsiCall callExpression, PsiExpressionList argList, PsiMethod method) { final Project project = method.getProject(); final PsiSubstitutor psiSubstitutor = JavaPsiFacade.getInstance(project).getResolveHelper() .inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(), argList.getExpressions(), PsiSubstitutor.EMPTY, callExpression, DefaultParameterTypeInferencePolicy.INSTANCE); RefactoringUtil.replaceMovedMemberTypeParameters(initializer, PsiUtil.typeParametersIterable(method), psiSubstitutor, JavaPsiFacade.getElementFactory(project)); }
private static PsiSubstitutor inferTypeParametersForStaticFactory(@NotNull PsiMethod staticFactoryMethod, PsiNewExpression expression, PsiElement parent) { final JavaPsiFacade facade = JavaPsiFacade.getInstance(staticFactoryMethod.getProject()); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); final PsiParameter[] parameters = staticFactoryMethod.getParameterList().getParameters(); final PsiExpressionList argumentList = expression.getArgumentList(); final PsiExpression[] expressions = argumentList.getExpressions(); return resolveHelper .inferTypeArguments(staticFactoryMethod.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, parent, DefaultParameterTypeInferencePolicy.INSTANCE); }
@Override public PsiSubstitutor getSubstitutor() { if (myCalcedSubstitutor == null) { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); PsiMethod method = getElement(); if (myTypeArguments == null) { final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack(); final PsiSubstitutor inferredSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE); if (!stackStamp.mayCacheNow()) { return inferredSubstitutor; } myCalcedSubstitutor = inferredSubstitutor; } else { PsiTypeParameter[] typeParams = method.getTypeParameters(); for (int i = 0; i < myTypeArguments.length && i < typeParams.length; i++) { incompleteSubstitutor = incompleteSubstitutor.put(typeParams[i], myTypeArguments[i]); } myCalcedSubstitutor = incompleteSubstitutor; } } return myCalcedSubstitutor; }
@NotNull public PsiSubstitutor getSubstitutor(boolean includeReturnConstraint) { PsiSubstitutor substitutor = myCalcedSubstitutor; if(substitutor == null || !includeReturnConstraint && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) || isOverloadCheck()) { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); PsiMethod method = getElement(); if(myTypeArguments == null) { final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack(); final PsiSubstitutor inferredSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE, includeReturnConstraint); if(!stackStamp.mayCacheNow() || isOverloadCheck() || !includeReturnConstraint && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) || getMarkerList() != null && PsiResolveHelper .ourGraphGuard.currentStack().contains(getMarkerList().getParent()) || LambdaUtil.isLambdaParameterCheck()) { return inferredSubstitutor; } myCalcedSubstitutor = substitutor = inferredSubstitutor; } else { PsiTypeParameter[] typeParams = method.getTypeParameters(); for(int i = 0; i < myTypeArguments.length && i < typeParams.length; i++) { incompleteSubstitutor = incompleteSubstitutor.put(typeParams[i], myTypeArguments[i]); } myCalcedSubstitutor = substitutor = incompleteSubstitutor; } } return substitutor; }
private static void inferTypeArgs(HighlightInfo highlightInfo, PsiType lType, PsiExpression thenExpression) { final JavaResolveResult result = ((PsiMethodCallExpression) thenExpression).resolveMethodGenerics(); final PsiMethod method = (PsiMethod) result.getElement(); if(method != null) { final PsiType returnType = method.getReturnType(); final PsiClass aClass = method.getContainingClass(); if(returnType != null && aClass != null && aClass.getQualifiedName() != null) { final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(method.getProject()); final PsiDeclarationStatement variableDeclarationStatement = javaPsiFacade.getElementFactory() .createVariableDeclarationStatement("xxx", lType, thenExpression); final PsiExpression initializer = ((PsiLocalVariable) variableDeclarationStatement.getDeclaredElements ()[0]).getInitializer(); LOG.assertTrue(initializer != null); final PsiSubstitutor substitutor = javaPsiFacade.getResolveHelper().inferTypeArguments(method .getTypeParameters(), method.getParameterList().getParameters(), ((PsiMethodCallExpression) thenExpression).getArgumentList().getExpressions(), PsiSubstitutor.EMPTY, initializer, DefaultParameterTypeInferencePolicy.INSTANCE); PsiType substitutedType = substitutor.substitute(returnType); if(substitutedType != null && TypeConversionUtil.isAssignable(lType, substitutedType)) { QuickFixAction.registerQuickFixAction(highlightInfo, thenExpression.getTextRange(), new AddTypeArgumentsConditionalFix(substitutor, (PsiMethodCallExpression) thenExpression, method)); } } } }
private static boolean isInferredSameTypeAfterConversion(PsiLambdaExpression lambdaExpression, PsiMethodReferenceExpression methodReferenceExpression, PsiType functionalInterfaceType) { PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodReferenceExpression.getParent()); if(!(parent instanceof PsiExpressionList)) { return true; } PsiElement gParent = parent.getParent(); if(gParent instanceof PsiCall) { if(gParent instanceof PsiCallExpression && ((PsiCallExpression) gParent).getTypeArguments().length > 0) { return true; } JavaResolveResult result = ((PsiCall) gParent).resolveMethodGenerics(); if(result instanceof MethodCandidateInfo) { PsiMethod method = ((MethodCandidateInfo) result).getElement(); if(!method.hasTypeParameters()) { return true; } PsiExpression[] args = ((PsiExpressionList) parent).getExpressions(); int lambdaIdx = LambdaUtil.getLambdaIdx((PsiExpressionList) parent, methodReferenceExpression); args[lambdaIdx] = lambdaExpression; final PsiParameter[] methodParams = method.getParameterList().getParameters(); final PsiSubstitutor substitutor = ((MethodCandidateInfo) result).inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE, args, true); PsiType formalTargetType = substitutor.substitute(PsiTypesUtil.getParameterType(methodParams, lambdaIdx, ((MethodCandidateInfo) result).isVarargs())); return functionalInterfaceType.equals(FunctionalInterfaceParameterizationUtil.getGroundTargetType(formalTargetType)); } } return false; }
private static PsiType getInferredType(PsiAnonymousClass aClass) { final PsiExpression expression = (PsiExpression)aClass.getParent(); final PsiType psiType = PsiTypesUtil.getExpectedTypeByParent(expression); if (psiType != null) { return psiType; } PsiExpression topExpr = expression; while (topExpr.getParent() instanceof PsiParenthesizedExpression) { topExpr = (PsiExpression)topExpr.getParent(); } final PsiElement parent = topExpr.getParent(); if (parent instanceof PsiExpressionList) { PsiExpressionList expressionList = (PsiExpressionList)parent; final PsiElement callExpr = expressionList.getParent(); if (callExpr instanceof PsiCallExpression) { final JavaResolveResult result = ((PsiCallExpression)callExpr).resolveMethodGenerics(); if (result instanceof MethodCandidateInfo) { final PsiMethod method = ((MethodCandidateInfo)result).getElement(); PsiExpression[] expressions = expressionList.getExpressions(); int i = ArrayUtilRt.find(expressions, topExpr); if (i < 0) return null; expressions[i] = null; final PsiParameter[] parameters = method.getParameterList().getParameters(); final PsiSubstitutor substitutor = PsiResolveHelper.SERVICE.getInstance(aClass.getProject()) .inferTypeArguments(method.getTypeParameters(), parameters, expressions, ((MethodCandidateInfo)result).getSiteSubstitutor(), callExpr.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE); PsiType paramType; if (i < parameters.length) { paramType = parameters[i].getType(); } else if (parameters.length > 0) { paramType = parameters[parameters.length - 1].getType(); if (!(paramType instanceof PsiEllipsisType)) { return null; } paramType = ((PsiEllipsisType)paramType).getComponentType(); } else { return null; } return substitutor.substitute(paramType); } } } return null; }
@NotNull public static List<IntentionAction> getQuickFixActions(@NotNull PsiMethodCallExpression methodCall, @NotNull PsiExpressionList list) { final JavaResolveResult result = methodCall.getMethodExpression().advancedResolve(false); PsiMethod method = (PsiMethod) result.getElement(); final PsiSubstitutor substitutor = result.getSubstitutor(); PsiExpression[] expressions = list.getExpressions(); if (method == null) return Collections.emptyList(); final PsiParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length != expressions.length) return Collections.emptyList(); List<IntentionAction> actions = new ArrayList<IntentionAction>(); for (int i = 0; i < expressions.length; i++) { final PsiExpression expression = expressions[i]; PsiType expressionType = expression.getType(); if (expressionType instanceof PsiPrimitiveType) { expressionType = ((PsiPrimitiveType)expressionType).getBoxedType(expression); } if (expressionType == null) continue; final PsiParameter parameter = parameters[i]; final PsiType formalParamType = parameter.getType(); final PsiType parameterType = substitutor.substitute(formalParamType); if (parameterType.isAssignableFrom(expressionType)) continue; final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression(); if (qualifierExpression instanceof PsiReferenceExpression) { final PsiElement resolved = ((PsiReferenceExpression)qualifierExpression).resolve(); if (resolved instanceof PsiVariable) { final PsiType varType = ((PsiVariable)resolved).getType(); final PsiClass varClass = PsiUtil.resolveClassInType(varType); final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(expression.getProject()).getResolveHelper(); if (varClass != null) { final PsiSubstitutor psiSubstitutor = resolveHelper.inferTypeArguments(varClass.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, resolved, DefaultParameterTypeInferencePolicy.INSTANCE); final PsiClassType appropriateVarType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(varClass, psiSubstitutor); if (!varType.equals(appropriateVarType)) { actions.add(new VariableTypeFromCallFix(appropriateVarType, (PsiVariable)resolved)); } break; } } } actions.addAll(getParameterTypeChangeFixes(method, expression, parameterType)); } return actions; }
public static void registerQuickFixActions(PsiMethodCallExpression methodCall, PsiExpressionList list, HighlightInfo highlightInfo) { final JavaResolveResult result = methodCall.getMethodExpression().advancedResolve(false); PsiMethod method = (PsiMethod) result.getElement(); final PsiSubstitutor substitutor = result.getSubstitutor(); PsiExpression[] expressions = list.getExpressions(); if (method == null || method.getParameterList().getParametersCount() != expressions.length) return; final PsiParameter[] parameters = method.getParameterList().getParameters(); for (int i = 0; i < expressions.length; i++) { final PsiExpression expression = expressions[i]; PsiType expressionType = expression.getType(); if (expressionType instanceof PsiPrimitiveType) { expressionType = ((PsiPrimitiveType)expressionType).getBoxedType(expression); } if (expressionType == null) continue; final PsiParameter parameter = parameters[i]; final PsiType formalParamType = parameter.getType(); final PsiType parameterType = substitutor.substitute(formalParamType); if (parameterType.isAssignableFrom(expressionType)) continue; final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression(); if (qualifierExpression instanceof PsiReferenceExpression) { final PsiElement resolved = ((PsiReferenceExpression)qualifierExpression).resolve(); if (resolved instanceof PsiVariable) { final PsiType varType = ((PsiVariable)resolved).getType(); final PsiClass varClass = PsiUtil.resolveClassInType(varType); final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(expression.getProject()).getResolveHelper(); if (varClass != null) { final PsiSubstitutor psiSubstitutor = resolveHelper.inferTypeArguments(varClass.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, resolved, DefaultParameterTypeInferencePolicy.INSTANCE); final PsiClassType appropriateVarType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(varClass, psiSubstitutor); if (!varType.equals(appropriateVarType)) { QuickFixAction.registerQuickFixAction(highlightInfo, new VariableTypeFromCallFix(appropriateVarType, (PsiVariable) resolved)); } break; } } } registerParameterTypeChange(highlightInfo, method, expression, parameterType); } }
private static PsiExpression createArrayCreationExpression(String text, int startOffset, int endOffset, PsiCallExpression parent) { if (text == null || parent == null) return null; final String[] varargsExpressions = text.split("s*,s*"); if (varargsExpressions.length > 1) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(parent.getProject()); final PsiMethod psiMethod = parent.resolveMethod(); if (psiMethod == null || !psiMethod.isVarArgs()) return null; final PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); final PsiParameter varargParameter = parameters[parameters.length - 1]; final PsiType type = varargParameter.getType(); LOG.assertTrue(type instanceof PsiEllipsisType); final PsiArrayType psiType = (PsiArrayType)((PsiEllipsisType)type).toArrayType(); final PsiExpression[] args = parent.getArgumentList().getExpressions(); final PsiSubstitutor psiSubstitutor = JavaPsiFacade.getInstance(parent.getProject()).getResolveHelper().inferTypeArguments(psiMethod.getTypeParameters(), parameters, args, PsiSubstitutor.EMPTY, parent, DefaultParameterTypeInferencePolicy.INSTANCE); if (args.length < parameters.length || startOffset < args[parameters.length - 1].getTextRange().getStartOffset()) return null; final PsiFile containingFile = parent.getContainingFile(); PsiElement startElement = containingFile.findElementAt(startOffset); while (startElement != null && startElement.getParent() != parent.getArgumentList()) { startElement = startElement.getParent(); } if (startElement == null || startOffset > startElement.getTextOffset()) return null; PsiElement endElement = containingFile.findElementAt(endOffset - 1); while (endElement != null && endElement.getParent() != parent.getArgumentList()) { endElement = endElement.getParent(); } if (endElement == null || endOffset < endElement.getTextRange().getEndOffset()) return null; final PsiType componentType = TypeConversionUtil.erasure(psiSubstitutor.substitute(psiType.getComponentType())); try { final PsiExpression expressionFromText = elementFactory.createExpressionFromText("new " + componentType.getCanonicalText() + "[]{" + text + "}", parent); final RangeMarker rangeMarker = FileDocumentManager.getInstance().getDocument(containingFile.getVirtualFile()).createRangeMarker(startOffset, endOffset); expressionFromText.putUserData(ElementToWorkOn.TEXT_RANGE, rangeMarker); expressionFromText.putUserData(ElementToWorkOn.PARENT, parent); return expressionFromText; } catch (IncorrectOperationException e) { return null; } } return null; }
public InferenceSession(PsiTypeParameter[] typeParams, PsiSubstitutor siteSubstitutor, PsiManager manager, PsiElement context) { this(typeParams, siteSubstitutor, manager, context, DefaultParameterTypeInferencePolicy.INSTANCE); }
@NotNull public static List<IntentionAction> getQuickFixActions(@NotNull PsiMethodCallExpression methodCall, @NotNull PsiExpressionList list) { final JavaResolveResult result = methodCall.getMethodExpression().advancedResolve(false); PsiMethod method = (PsiMethod) result.getElement(); final PsiSubstitutor substitutor = result.getSubstitutor(); PsiExpression[] expressions = list.getExpressions(); if(method == null) { return Collections.emptyList(); } final PsiParameter[] parameters = method.getParameterList().getParameters(); if(parameters.length != expressions.length) { return Collections.emptyList(); } List<IntentionAction> actions = new ArrayList<>(); for(int i = 0; i < expressions.length; i++) { final PsiExpression expression = expressions[i]; PsiType expressionType = expression.getType(); if(expressionType instanceof PsiPrimitiveType) { expressionType = ((PsiPrimitiveType) expressionType).getBoxedType(expression); } if(expressionType == null) { continue; } final PsiParameter parameter = parameters[i]; final PsiType formalParamType = parameter.getType(); final PsiType parameterType = substitutor.substitute(formalParamType); if(parameterType.isAssignableFrom(expressionType)) { continue; } final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression(); if(qualifierExpression instanceof PsiReferenceExpression) { final PsiElement resolved = ((PsiReferenceExpression) qualifierExpression).resolve(); if(resolved instanceof PsiVariable) { final PsiType varType = ((PsiVariable) resolved).getType(); final PsiClass varClass = PsiUtil.resolveClassInType(varType); final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(expression.getProject()).getResolveHelper(); if(varClass != null) { final PsiSubstitutor psiSubstitutor = resolveHelper.inferTypeArguments(varClass.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, resolved, DefaultParameterTypeInferencePolicy.INSTANCE); final PsiClassType appropriateVarType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(varClass, psiSubstitutor); if(!varType.equals(appropriateVarType)) { actions.add(new VariableTypeFromCallFix(appropriateVarType, (PsiVariable) resolved)); } break; } } } actions.addAll(getParameterTypeChangeFixes(method, expression, parameterType)); } return actions; }