Load the attached java source (it is from a Greenfoot project) and perform auto-layout. Notice the following debug output:
This comes from bluej.editor.Moe.!MoeIndent.!DocumentIndentAction, near the start of the apply() method:
Note the comment at the start of the same method:
I think that may be an incorrect assumption; any edits might change the elements that are part of the document. In particular deleting blank lines probably causes this, but even without that we're relying on undocumented behaviour here and ideally we shouldn't cache the elements like we do. I think it would be best to do two passes, one which removes the blank lines, and another which fixes the indents on the remaining lines, but even then it would ideally associate the updates with line numbers rather than with elements.