Rewriting nodes in java