Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333937

Summary: The refactoring infrastructure does not adhere to user set indentation rules
Product: [Tools] CDT Reporter: Fredrik Berg Kjolstad <fredrikbk>
Component: cdt-refactoringAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Emanuel Graf <emanuel>
Severity: normal    
Priority: P3 CC: cdtdoug, eclipse.sprigogin, malaperle, yevshif
Version: 8.0   
Target Milestone: 8.0.2   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 296192    
Attachments:
Description Flags
Bugfix that makes the refactoring infrastructure insert new code with user workspace indentation settings instead of four spaces
none
Bugfix: First attempt at a patch to set indentation width based on project settings if available none

Description Fredrik Berg Kjolstad CLA 2011-01-10 22:50:13 EST
Build Identifier: M20100909-0800

When inserting, replacing or moving statements the refactoring infrastructure always inserts four spaces instead of using the user set (project or workspace) indentation rules.

Reproducible: Always

Steps to Reproduce:
1. Set the workspace indentation settings to use a tab
2. Select some statements and choose Refactor -> Extract method
3. The new code in the new method uses four spaces for indentation
Comment 1 Fredrik Berg Kjolstad CLA 2011-01-10 23:30:51 EST
Created attachment 186458 [details]
Bugfix that makes the refactoring infrastructure insert new code with user workspace indentation settings instead of four spaces

Patch that changes the indentation of inserted/replaced statements to the user-specified settings (tab/space/mixed and number of spaces).
Comment 2 Fredrik Berg Kjolstad CLA 2011-01-10 23:31:31 EST
Comment by Emanuel Graf in original bug:

(In reply to comment #7)
> Created an attachment (id=184307) [details]
> Patch that changes fixed four space statement indentation to user settings

You use the workspace settings better use the project specific settings if
available.
Comment 3 Fredrik Berg Kjolstad CLA 2011-01-10 23:33:20 EST
Created attachment 186459 [details]
Bugfix: First attempt at a patch to set indentation width based on project settings if available

This patch is a first attempt at a way to use project indentation settings, if available, to govern refactoring rewriting.  The solution passes an option map down to the Scribe class and is not the cleanest, but the project seems only to be available at the higher levels.  Specifically I found no way to retrieve a project if I have an AST node.

I welcome alternate approaches. If not, then this might be good enough.
Comment 4 Fredrik Berg Kjolstad CLA 2011-01-11 20:15:10 EST
Attachment 186458 [details]:
The class CCodeFormatter already has functionality to generate properly formatted indent strings, given project/workspace options, and should be used instead of the custom indent code.

Attachment 186459 [details]:
A CCodeFormatter should be passed down instead of the ugly and verbose options Map.

Lastly, should look into how JDT handles this so as to avoid passing unnecessary state around.
Comment 5 Marc-André Laperle CLA 2011-06-15 22:30:47 EDT
*** Bug 347495 has been marked as a duplicate of this bug. ***
Comment 6 Sergey Prigogin CLA 2011-11-07 16:18:03 EST
Fixed in cdt_8_0 and master.