[BLUEJ-326] Strange debug output during auto-layout operation
Load the attached java source (it is from a Greenfoot project) and perform auto-layout. Notice the following debug output:
{noformat} Element mismatch!!!! Element mismatch!!!! Element mismatch!!!! {noformat}
This comes from bluej.editor.Moe.!MoeIndent.!DocumentIndentAction, near the start of the apply() method:
{noformat} if (doc.getDefaultRootElement().getElement(ll) != el) { System.out.println("Element mismatch!!!!"); } {noformat}
Note the comment at the start of the same method:
{noformat} // Because we keep element references, we don't have to worry about the offsets // altering, because they will alter before we process the line, and thus // everything works nicely. {noformat}
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.
Issue metadata
- Issue type: Bug
- Priority: Medium
- Fix versions: 3.0.5