1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Bug 399215 - Toggle Function breaks the code...

- Test case for reproducing the problem.
- The code is lost because a copy of the body, which contains macro
references is not rewritten, but its raw signature is taken. The raw
signature of a copy is empty in this case. I've solved this issue by
using the raw signature of the original node for get raw signature. This
is a fundamental change of ASTNode.getRawSignature(). We could also
solve this in the StatementWriter to get the original node before
accessing the raw signature.

Change-Id: I64b408b09444df818d30d99d99de4a1974eacf93
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
Reviewed-on: https://git.eclipse.org/r/39406
Tested-by: Hudson CI
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Thomas Corbat 2015-01-12 17:26:26 +01:00
parent ef00469292
commit 786e2137eb
2 changed files with 23 additions and 2 deletions

View file

@ -161,8 +161,9 @@ public abstract class ASTNode implements IASTNode {
} }
protected char[] getRawSignatureChars() { protected char[] getRawSignatureChars() {
final IASTFileLocation floc= getFileLocation(); final IASTNode originalNode = getOriginalNode();
final IASTTranslationUnit ast = getTranslationUnit(); final IASTFileLocation floc= originalNode.getFileLocation();
final IASTTranslationUnit ast = originalNode.getTranslationUnit();
if (floc != null && ast != null) { if (floc != null && ast != null) {
ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class); ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class);
if (lr != null) { if (lr != null) {

View file

@ -2863,4 +2863,24 @@ public class ToggleRefactoringTest extends RefactoringTestBase {
public void testImplToHeaderTopCommentWithoutDeclaration() throws Exception { public void testImplToHeaderTopCommentWithoutDeclaration() throws Exception {
assertRefactoringSuccess(); assertRefactoringSuccess();
} }
//A.h
//#define MACRO 1
//int /*$*/freefunction/*$$*/() {
// return MACRO;
//}
//====================
//#define MACRO 1
//int freefunction();
//A.cpp
//====================
//#include "A.h"
//
//int freefunction() {
// return MACRO;
//}
public void testFunctionWithMacroReference_399215() throws Exception {
assertRefactoringSuccess();
}
} }