PsiType (final PsiMethod psiMethod) { final PsiType returnType = psiMethod.getReturnType(); if (returnType != null) { PsiElement parent = getMatchEnd().getParent(); if (parent instanceof PsiExpression) { if (parent instanceof PsiMethodCallExpression) { JavaResolveResult result = ((PsiMethodCallExpression)parent).resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); if (method != null) { PsiType type = method.getReturnType(); if (type != null) { type = result.getSubstitutor().substitute(type); if (weakerType(psiMethod, returnType, type)) { return type; } } } } else if (parent instanceof PsiReferenceExpression) { final JavaResolveResult result = ((PsiReferenceExpression)parent).advancedResolve(false); final PsiElement element = result.getElement(); if (element instanceof PsiMember) { final PsiClass psiClass = ((PsiMember)element).getContainingClass(); if (psiClass != null && psiClass.isPhysical()) { final JavaPsiFacade facade = JavaPsiFacade.getInstance(parent.getProject()); final PsiClassType expressionType = facade.getElementFactory().createType(psiClass, result.getSubstitutor()); if (weakerType(psiMethod, returnType, expressionType)) { return expressionType; } } } } } else if (parent instanceof PsiExpressionList) { final PsiExpression[] expressions = ((PsiExpressionList)parent).getExpressions(); final PsiElement call = parent.getParent(); if (call instanceof PsiMethodCallExpression) { final JavaResolveResult result = ((PsiMethodCallExpression)call).resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); if (method != null) { final int idx = ArrayUtil.find(expressions, getMatchEnd()); final PsiParameter[] psiParameters = method.getParameterList().getParameters(); if (idx >= 0 && idx < psiParameters.length) { PsiType type = result.getSubstitutor().substitute(psiParameters[idx].getType()); if (type instanceof PsiEllipsisType) { type = ((PsiEllipsisType)type).getComponentType(); } if (weakerType(psiMethod, returnType, type)){ return type; } } } } } else if (parent instanceof PsiLocalVariable) { final PsiType localVariableType = ((PsiLocalVariable)parent).getType(); if (weakerType(psiMethod, returnType, localVariableType)) return localVariableType; } else if (parent instanceof PsiReturnStatement) { final PsiMethod replacedMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class); LOG.assertTrue(replacedMethod != null); final PsiType replacedMethodReturnType = replacedMethod.getReturnType(); if (replacedMethodReturnType != null && weakerType(psiMethod, returnType, replacedMethodReturnType)) { return replacedMethodReturnType; } } } return null; }