public static PsiType getTypeByExpression(PsiExpression expr, final PsiElementFactory factory) {
    PsiType type = RefactoringChangeUtil.getTypeByExpression(expr);
    if (PsiTypes.nullType().equals(type)) {
      ExpectedTypeInfo[] infos = ExpectedTypesProvider.getExpectedTypes(expr, false);
      if (infos.length > 0) {
        type = infos[0].getType();
        if (type instanceof PsiPrimitiveType) {
          type = infos.length > 1 && !(infos[1].getType() instanceof PsiPrimitiveType) ? infos[1].getType()
                                                                                       : ((PsiPrimitiveType)type).getBoxedType(expr);
        }
      }
      else {
        type = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, expr.getResolveScope());
      }
    }

    return type;
  }
public static PsiType getTypeByExpression(PsiExpression expr, final PsiElementFactory factory)