refactor rule application

Move invariant out of doApply.

Change-Id: I02ffa00b53e722dbb3d94d2bc14f4a5b88302675
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>