Project: JDT
Bug 157203 [ltk] [patch] TextEditBasedChange/TextChange provides incorrect diff when one side is empty
Reported: 2006-09-13 13:19:28 | Status: resolved fixed

When previewing changes for a refactoring whose changes are TextChanges, sometimes spurious changes are displayed in the preview/diff UI due to the presence of empty regions in the source or target. For instance, given a ReplaceEdit that inserts a line, the source's region is empty and the target's is not. But in the diff page, it looks like a line is inserted in the source AND the following line from the source's context is deleted. This is confusing. I think the issue comes down to TextEditBasedChange#getContent() when dealing with the expandRegionToFullLine argument. If the incoming region is empty, then expanding to full line introduces a new line in the content, whereas a non-empty region always has line(s) to work with. Thus, the fix is to remove one line of context when expanding an empty region, so the two sides (current and preview) balance out in total number of lines displayed.

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/changes/AllTests.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/changes/TextDiffContentTest.java org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextEditBasedChange.java