Delete extensions nodes which have been made empty

If they have allowedEmpty=false.

Also remove unnecessary instanceof check.

Change-Id: I388202c9da5673534486b1d9d345296feeec53c3
Merge "Delete extensions nodes which have been made empty"