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

Bug 333936

Summary: When ASTNodes are moved (as in Extract Method) formatting is not preserved and macros are expanded
Product: [Tools] CDT Reporter: Fredrik Berg Kjolstad <fredrikbk>
Component: cdt-refactoringAssignee: Emanuel Graf <emanuel>
Status: RESOLVED FIXED QA Contact: Emanuel Graf <emanuel>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle
Version: 8.0   
Target Milestone: 8.0   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 337937    
Bug Blocks: 296192    
Attachments:
Description Flags
Test case extracting macro
emanuel: iplog-
Fix for the expansion bug
emanuel: iplog-
Fix for the expansion bug emanuel: iplog-

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

In the current refactoring infrastructure formatting does not follow ASTNodes.  Therefore, when these are moved, as happens in Extract Method when code is moved from one method to another, the code is pretty-printed and code formatting does not follow the nodes.

The result is that whitespaces in the code are replaced with those inserted by the pretty-printer and that macros are expanded

This bug was first reported by Alex Richardson in bug 296192, but that bug has become an aggregate of many bugs, so I am splitting them.

Reproducible: Always

Steps to Reproduce:
1. Create some code with strange formatting and use of macros
2. Select the code and choose Refactor -> Extract method
3. The new code in the new method has now been reformatted according to the rules of the pretty-printer and the macros has been expanded.
Comment 1 Emanuel Graf CLA 2011-02-22 07:45:30 EST
Created attachment 189481 [details]
Test case extracting macro
Comment 2 Emanuel Graf CLA 2011-03-07 05:51:14 EST
Created attachment 190533 [details]
Fix for the expansion bug
Comment 3 Emanuel Graf CLA 2011-03-07 06:06:09 EST
Created attachment 190536 [details]
Fix for the expansion bug

The old patch contains some comment handling code that belongs to an other bug report.
Comment 4 Emanuel Graf CLA 2011-03-07 06:15:07 EST
Fixed the macro expansion bug in HEAD > 20110307. I'm not going to have a look at the formatting issue now. Im closing this Bug an create a new one for the formatting.
Comment 5 CDT Genie CLA 2011-03-07 06:23:24 EST
*** cdt cvs genie on behalf of egraf ***
Bug 333936: When ASTNodes are moved (as in Extract Method) formatting is not preserved and macros are expanded
<a  href=https://bugs.eclipse.org/bugs/show_bug.cgi?id=333936>https://bugs.eclipse.org/bugs/show_bug.cgi?id=333936</a>

[*] ExtractExpression.rts 1.9 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts?root=Tools_Project&r1=1.8&r2=1.9

[*] MacroExpansionHandler.java 1.7 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java?root=Tools_Project&r1=1.6&r2=1.7

[*] NamespaceHelper.java 1.6 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java?root=Tools_Project&r1=1.5&r2=1.6
[*] NameHelper.java 1.11 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java?root=Tools_Project&r1=1.10&r2=1.11

[*] ExtractStatement.java 1.3 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractStatement.java?root=Tools_Project&r1=1.2&r2=1.3
[*] ExtractedFunctionConstructionHelper.java 1.6 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java?root=Tools_Project&r1=1.5&r2=1.6
[*] ExtractFunctionRefactoring.java 1.30 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java?root=Tools_Project&r1=1.29&r2=1.30
[*] ExtractExpression.java 1.16 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java?root=Tools_Project&r1=1.15&r2=1.16

[*] ImplementMethodRefactoring.java 1.17 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java?root=Tools_Project&r1=1.16&r2=1.17

[*] FunctionFactory.java 1.9 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java?root=Tools_Project&r1=1.8&r2=1.9
[*] GetterSetterInsertEditProvider.java 1.7 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java?root=Tools_Project&r1=1.6&r2=1.7

[*] ExtractLocalVariableRefactoring.java 1.14 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java?root=Tools_Project&r1=1.13&r2=1.14

[*] NodeContainer.java 1.18 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java?root=Tools_Project&r1=1.17&r2=1.18