| Summary: | XML formatter produces wrong output, and hang up on huge files | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [WebTools] WTP Source Editing | Reporter: | Jochen Hiller <jochen.hiller> | ||||||||||
| Component: | wst.xml | Assignee: | Amy Wu <for.work.things> | ||||||||||
| Status: | CLOSED FIXED | QA Contact: | |||||||||||
| Severity: | normal | ||||||||||||
| Priority: | P2 | CC: | brian.jakubik, david_williams | ||||||||||
| Version: | 0.7.1 | ||||||||||||
| Target Milestone: | 1.5 RC5 | ||||||||||||
| Hardware: | PC | ||||||||||||
| OS: | Windows XP | ||||||||||||
| Whiteboard: | PMC_approved | ||||||||||||
| Attachments: |
|
||||||||||||
|
Description
Jochen Hiller
Created attachment 29650 [details]
contains all test files
Thanks, we've got a couple of these and will (try) and flush out formatting issues before 1.0. The poor performance in XML formatting is being tracked in bug 102822. As for the wrong output, if you hit enter at the end of the file and add an additional line, everything will format correctly. I believe the problem lies in everything sitting on the first line of the file and how the formatter is looking up the line delimiter. It looks like the formatter is trying to find the line delimiter of the last line, and since there is none, it does not add a line delimiter. The fix is if no line delimiter is found, use the default line delimiter for the document. org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter #formatIndentationAfterNode CHANGE: String lineDelimiter = doc.getLineDelimiter(); try { lineDelimiter = doc.getLineDelimiter(line); if (lineDelimiter == null) lineDelimiter = ""; //$NON-NLS-1$ } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } TO THIS: String lineDelimiter = doc.getLineDelimiter(); try { lineDelimiter = doc.getLineDelimiter(line); } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } // BUG115716: if cannot get line delimiter from current line, just // use default line delimiter if (lineDelimiter == null) lineDelimiter = doc.getLineDelimiter(); Created attachment 43550 [details]
org.eclipse.wst.xml.core.patch
I'm seeing 2 unit test failures, and it looks like it may be issues with the very last line delimiter at the end of the file. So I may have to rethink this fix slightly. (Though I think this fix is better than what we currently have) Created attachment 43569 [details]
org.eclipse.wst.xml.core.patch
Okay, I figured out the end of file line delimiter issue. Fix is the same as stated earlier, but I've added additional checks so that when formatting the last node, do not add a line delimiter at the end.
-ElementNodeFormatter#formatNode
==>// only indent if not at last node
==>if (newNode != null && newNode.getNextSibling() != null)
// format indentation after node
formatIndentationAfterNode(newNode, formatContraints);
-NodeFormatter#formatIndentationAfterNode
else {
==> // as long as not at the end of the document
==> IStructuredDocumentRegion endRegion = node.getLastStructuredDocumentRegion();
==> if (endRegion != null && endRegion.getNext() != null)
// append indentation
insertAfterNode(lastChild, lineDelimiter + lineIndent);
}
I also noticed the same if linedelimiter == null linedelimiter = "" mistake in NodeFormatter#formatIndentationBeforeNode so i went ahead and corrected the logic in that method as well.
Created attachment 43570 [details]
org.eclipse.wst.xml.core.tests.patch
And now the JUnit tests all pass. And to make sure this bug stays fixed, I added a unit test to check formatting of one line.
Excellent, thanks Amy. +1 +1 1.5 Released fix for 1.5RC5. Hi all, RETESTED: FINE I did a retest of my posted XML files. It is now working quite well, the formatting results always in same and expected result. Performance is OK. On a 2 GHz Notebook, it takes about 3 seconds to open a XML file with about 40k. Maybe that really huge files may yet be slow. Thanks for your quite good work. thanks, closing *** Bug 159349 has been marked as a duplicate of this bug. *** |