Bug 239447 - [formatter] Problem with save action "Format edited lines"
Summary: [formatter] Problem with save action "Format edited lines"
Status: VERIFIED DUPLICATE of bug 234583
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-03 10:25 EDT by Patrick Schonbach CLA
Modified: 2008-09-15 09:14 EDT (History)
3 users (show)

See Also:


Attachments
Formatter used for comment #0 (28.09 KB, text/xml)
2008-07-07 07:55 EDT, Patrick Schonbach CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Schonbach CLA 2008-07-03 10:25:16 EDT
Consider the following lines:

	private static final String CONTENT = "test.ObjectB {\n" + "	multiEle = { name=\"Foo\" }\n"
	+ "	multiEle = :x { name=\"Bar\" }\n" + "	singleEle = x;\n" + "}";

The file is saved.

Now:

1. Reformat the whole document.
2. The indentation of the second line is corrected and the second line is marked as being edited.
3. Now, save again with "Format edited line" turned on.

The indentation of the second line incorrectly is changed back because only the second line is considered since the first line has not been changed.

This problem makes the "Format edited line" option rather unusable.
Comment 1 Dani Megert CLA 2008-07-04 06:35:44 EDT
Looks like a selection format problem.

1. paste this code into Package Explorer:

public class Bug239447 {
private static final String CONTENT = "test.ObjectB {\n"
+ "     multiEle = { name=\"Foo\" }\n"
+ "     multiEle = :x { name=\"Bar\" }\n" + "   singleEle = x;\n"
+ "}";
}

2. Format
3. Save
4. delete the leading whitespace of line 3
5. select line 3 (from start to end)
6. format
   ==> OK: line gets correctly indented as it was after save
7. now add some whitespace to line 3 (before the '+')
8. select line 3 (from start to end)
9. format
   ==> BUG: line not correctly indented
Comment 2 Frederic Fusier CLA 2008-07-07 07:46:32 EDT
I can reproduce the problem described in comment 1 which is a consequence of bug 234583.

However, I cannot reproduce the initial issue described in comment 0: can you attach the formatter profile used for this test case?

Using the default Eclipse built-in profile, here's the output I get:
public class Test {
>>  private static final String CONTENT = "test.ObjectB {\n"
>>  >>  >>  "multiEle = { name=\"Foo\" }\n"
>>  >>  >>  + "     multiEle = :x { name=\"Bar\" }\n" + "   singleEle = x;\n"
>>  >>  >>  + "}";
}

(I replaced the tabulations with '>>  ' to show the used indentation character)

Reformatting this output does not change any lines, hence the problem does not occur.
Comment 3 Patrick Schonbach CLA 2008-07-07 07:55:18 EDT
Created attachment 106712 [details]
Formatter used for comment #0

I attached the formatter.
Comment 4 Frederic Fusier CLA 2008-07-08 10:47:52 EDT
(In reply to comment #3)
> Created an attachment (id=106712) [details]
> Formatter used for comment #0
> 
> I attached the formatter.
> 
I still cannot reproduce even with your profile...

Based on your comment 0, here's the test case I'm starting from to run your steps:

public class Test {
........private static final String CONTENT = "test.ObjectB {\n"
........+ "     multiEle = :x { name=\"Bar\" }\n";
}

I've removed some strings to make it readable with bugzilla and also shown lines leading spaces replacing them by '.'

Step 1: format the whole unit
------
Using your profile but reducing the line wrapping to 80 to have the same line split than with your initial snippet, I get the following output:
public class Test {
>>  private static final String CONTENT = "test.ObjectB {\n"
>>  >>  >>  + "     multiEle = :x { name=\"Bar\" }\n";
}

Step 2: As you can see, both lines 2 and 3 are modified while formatting
------

Step 3: Save with "Format edited line" turned on
------
I still get the same output after this save action as the two lines were correctly formatted after step 1:
public class Test {
>>  private static final String CONTENT = "test.ObjectB {\n"
>>  >>  >>  + "     multiEle = :x { name=\"Bar\" }\n";
}
Comment 5 Patrick Schonbach CLA 2008-07-08 10:53:08 EDT
Did you try to just modify the second line and then format the edited lines only?
Comment 6 Frederic Fusier CLA 2008-07-08 11:44:30 EDT
(In reply to comment #5)
> Did you try to just modify the second line and then format the edited lines
> only?
> 
Yes, see my answer in comment 2:
> I can reproduce the problem described in comment 1 which is a consequence of
> bug 234583.
> 

But the scenario described in comment 1 was different than yours... And as you didn't say that comment 1 scenario should be used instead or that your scenario was missing one step: modify the line 2, I desperately tried to reproduce yours :-(

So, the conclusion is that your issue is also a consequence of bug 234583
=> set it as duplicate because fix for bug 234583 will fix this one...


*** This bug has been marked as a duplicate of bug 234583 ***
Comment 7 David Audel CLA 2008-09-15 09:14:42 EDT
Verified for 3.5M2 using I20080914-2000