An energy residual-based approach to gradient effects within the mechanics of generalized continua