Whoops, I think I get it now, you are tracking a different stringbuilder each time java gets inserted, and escaping only that intermediate content. I realize it would mean more work, but would it be saner to just re-implement the whole printer code from the superclass consistently, hitting Generator.escape right when it is needed each time?