1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Improved handling of blank lines when appending to a translation unit.

This commit is contained in:
Sergey Prigogin 2011-12-29 18:15:35 -08:00
parent da95eb2605
commit e3bdead668
19 changed files with 144 additions and 186 deletions

View file

@ -12,6 +12,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -144,6 +146,24 @@ public class ASTWriter {
* @return <code>true</code> if the blank line between the nodes is needed. * @return <code>true</code> if the blank line between the nodes is needed.
*/ */
public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) { public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) {
if (node1 instanceof ContainerNode) {
List<IASTNode> nodes = ((ContainerNode) node1).getNodes();
if (!nodes.isEmpty()) {
node1 = nodes.get(nodes.size() - 1);
}
}
if (node2 instanceof ContainerNode) {
List<IASTNode> nodes = ((ContainerNode) node2).getNodes();
if (!nodes.isEmpty()) {
node2 = nodes.get(0);
}
}
while (node1 instanceof ICPPASTTemplateDeclaration) {
node1 = ((ICPPASTTemplateDeclaration) node1).getDeclaration();
}
while (node2 instanceof ICPPASTTemplateDeclaration) {
node2 = ((ICPPASTTemplateDeclaration) node2).getDeclaration();
}
if (node1 instanceof ICPPASTVisibilityLabel && node2 instanceof ICPPASTVisibilityLabel) { if (node1 instanceof ICPPASTVisibilityLabel && node2 instanceof ICPPASTVisibilityLabel) {
return true; return true;
} }

View file

@ -132,6 +132,7 @@ public class ASTWriterVisitor extends ASTVisitor {
} }
public void visit(ASTLiteralNode lit) { public void visit(ASTLiteralNode lit) {
insertBlankLineIfNeeded(lit);
scribe.print(lit.getRawSignature()); scribe.print(lit.getRawSignature());
} }

View file

@ -75,7 +75,6 @@ import org.eclipse.jface.text.TextUtilities;
import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange; import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MalformedTreeException; import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit; import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.ReplaceEdit;
@ -559,26 +558,47 @@ public class ChangeGenerator extends ASTVisitor {
if (modifications.isEmpty()) if (modifications.isEmpty())
return; return;
ASTWriter synthWriter = new ASTWriter(); IASTNode prevNode = null;
synthWriter.setModificationStore(modificationStore); IASTDeclaration[] declarations = tu.getDeclarations();
if (declarations.length != 0) {
prevNode = declarations[declarations.length - 1];
} else {
IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements();
if (preprocessorStatements.length != 0) {
prevNode = preprocessorStatements[preprocessorStatements.length - 1];
}
}
int offset = prevNode != null ? getEndOffsetIncludingComments(prevNode) : 0;
String source = tu.getRawSignature();
int endOffset = skipTrailingBlankLines(source, offset);
IASTFileLocation targetLocation = tu.getFileLocation(); ChangeGeneratorWriterVisitor writer =
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
IASTNode newNode = null;
for (ASTModification modification : modifications) {
boolean first = newNode == null;
newNode = modification.getNewNode();
if (first) {
if (prevNode != null) {
writer.newLine();
if (ASTWriter.requireBlankLineInBetween(prevNode, newNode)) {
writer.newLine();
}
}
}
newNode.accept(writer);
}
if (prevNode != null) {
IASTNode nextNode = getNextSiblingOrPreprocessorNode(prevNode);
if (nextNode != null && ASTWriter.requireBlankLineInBetween(newNode, nextNode)) {
writer.newLine();
}
}
String code = writer.toString();
IFile file = FileHelper.getFileFromNode(tu); IFile file = FileHelper.getFileFromNode(tu);
MultiTextEdit parentEdit = getEdit(tu, file); MultiTextEdit parentEdit = getEdit(tu, file);
parentEdit.addChild(new ReplaceEdit(offset, endOffset - offset, code));
IASTDeclaration[] declarations = tu.getDeclarations();
for (ASTModification modification : modifications) {
String code = synthWriter.write(modification.getNewNode(), commentMap);
if (declarations.length > 0) {
IASTDeclaration lastDecl = declarations[declarations.length - 1];
targetLocation = lastDecl.getFileLocation();
}
String lineDelimiter = FileHelper.determineLineDelimiter(tu.getRawSignature());
parentEdit.addChild(new InsertEdit(endOffset(targetLocation),
lineDelimiter + lineDelimiter + code));
}
} }
/** /**

View file

@ -1173,7 +1173,6 @@ private:
}; };
#endif /* A_H_ */ #endif /* A_H_ */
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1195,9 +1194,7 @@ inline void Person::setId(int id) {
this->id = id; this->id = id;
} }
#endif /* A_H_ */ #endif /* A_H_ */
//!No Methods Separate Definition //!No Methods Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
@ -1248,7 +1245,6 @@ inline void test::setI(int i) {
this->i = i; this->i = i;
} }
#endif /* TEST_H_ */ #endif /* TEST_H_ */
//!Bug 323780 "Generate Getters and Setters..." crashes //!Bug 323780 "Generate Getters and Setters..." crashes
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
@ -1349,7 +1345,6 @@ public:
//@Test.cxx //@Test.cxx
//= //=
int Test::getTestField() const { int Test::getTestField() const {
return testField; return testField;
} }
@ -1390,7 +1385,6 @@ public:
//@component_b/implementation/Test.cpp //@component_b/implementation/Test.cpp
//= //=
int Test::getTestField() const { int Test::getTestField() const {
return testField; return testField;
} }

View file

@ -17,8 +17,6 @@ public:
inline bool X::a(int int1) const { inline bool X::a(int int1) const {
} }
//!Param const and reference and pointer two params //!Param const and reference and pointer two params
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -38,8 +36,6 @@ public:
inline bool X::xy(int int1, int i) const { inline bool X::xy(int int1, int i) const {
} }
//!Test if TemplateMethod stays in header //!Test if TemplateMethod stays in header
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -62,15 +58,13 @@ public:
template<class T> template<class T>
inline void A<T>::test() { inline void A<T>::test() {
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=
#include "A.h" #include "A.h"
//!class template member functions //!Class template member functions
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -102,9 +96,7 @@ A<T>::A() {
template<class T> template<class T>
inline void A<T>::test() { inline void A<T>::test() {
} }
//!Member class
//!member class
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -144,8 +136,6 @@ public:
inline void A::test() { inline void A::test() {
} }
//!Method declared in otherwise empty class //!Method declared in otherwise empty class
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -165,7 +155,6 @@ public:
//@A.cpp //@A.cpp
//= //=
void A::test() { void A::test() {
} }
//!Implement in existing namespace //!Implement in existing namespace
@ -205,7 +194,7 @@ void ClassInNamespace::test2() {
} }
} }
//!virtual method in the middle of con/destructor, without parameters and void return value //!Virtual method in the middle of con/destructor, without parameters and void return value
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -287,8 +276,6 @@ A::A() {
void A::foo() { void A::foo() {
} }
//!Method at beginning, without parameters, void return value and const //!Method at beginning, without parameters, void return value and const
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -348,8 +335,6 @@ A::A() {
int A::foo() { int A::foo() {
} }
//!Method with two int parameters //!Method with two int parameters
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -379,8 +364,6 @@ A::A() {
int A::foo(int param1, int param2) { int A::foo(int param1, int param2) {
} }
//!Method defined in header //!Method defined in header
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -408,8 +391,6 @@ A::A() {
inline void A::test() { inline void A::test() {
} }
//!Implement a function at end of source file //!Implement a function at end of source file
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -426,7 +407,6 @@ void function_with_impl() {
void function() { void function() {
} }
//!Implement with namespace //!Implement with namespace
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -453,7 +433,6 @@ void Namespace::ClassInNamespace::other_test() {
void Namespace::ClassInNamespace::test() { void Namespace::ClassInNamespace::test() {
} }
//!Implement function within namespace //!Implement function within namespace
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -524,7 +503,7 @@ int test2() {
} }
} }
//!class template member functions with multiple templates //!Class template member functions with multiple templates
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -538,7 +517,7 @@ public:
}; };
template<class T, class U> template<class T, class U>
A<T,U>::A() { A<T, U>::A() {
} }
//= //=
@ -550,15 +529,13 @@ public:
}; };
template<class T, class U> template<class T, class U>
A<T,U>::A() { A<T, U>::A() {
} }
template<class T, class U> template<class T, class U>
inline void A<T, U>::test() { inline void A<T, U>::test() {
} }
//!With default parameters
//!with default parameters
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -578,7 +555,7 @@ public:
void Class::test(int param1, int param2, int param3) { void Class::test(int param1, int param2, int param3) {
} }
//!static method //!Static method
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -672,7 +649,6 @@ class TestClass {
inline void nspace::TestClass::testMethod() { inline void nspace::TestClass::testMethod() {
} }
#endif /* TESTCLASS_H_ */ #endif /* TESTCLASS_H_ */
//!Bug 290110 Source-> Implement Method //!Bug 290110 Source-> Implement Method
@ -736,8 +712,6 @@ A::~A() {
void n1::n2::A::B::testmethod2() { void n1::n2::A::B::testmethod2() {
} }
//!Bug 337040 - Insert definition in empty implementation file (.cxx) //!Bug 337040 - Insert definition in empty implementation file (.cxx)
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -753,7 +727,6 @@ public:
//@A.cxx //@A.cxx
//= //=
void TestClass::foo() { void TestClass::foo() {
} }
//!Bug 355006 - NPE implementing template function //!Bug 355006 - NPE implementing template function
@ -773,7 +746,6 @@ void func(T&);
template<typename T> template<typename T>
inline void func(T&) { inline void func(T&) {
} }
//!Bug 363111 - Remove explicit in constructor definition //!Bug 363111 - Remove explicit in constructor definition
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -789,6 +761,5 @@ public:
//@A.cpp //@A.cpp
//= //=
TestClass::TestClass() { TestClass::TestClass() {
} }

View file

@ -18,7 +18,6 @@ inline void A::member() {
// return comment // return comment
return; return;
} }
//!ClassToHeaderTopCommentOrder //!ClassToHeaderTopCommentOrder
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -41,7 +40,6 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!ClassToHeaderCatchComment //!ClassToHeaderCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -68,7 +66,6 @@ try {
catch (int i) { catch (int i) {
// catch comment // catch comment
} }
//!ClassToHeaderTopComment //!ClassToHeaderTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -89,7 +86,6 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!ClassToHeaderTemplateTopComment //!ClassToHeaderTemplateTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -114,7 +110,6 @@ template<typename T>
inline T A::member() { inline T A::member() {
return T(); return T();
} }
//!ClassToHeaderTrailingComment //!ClassToHeaderTrailingComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -133,7 +128,6 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} // Trailing comment } // Trailing comment
//!ClassToHeaderTrailingCommentWithTryBlock //!ClassToHeaderTrailingCommentWithTryBlock
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -93,7 +93,6 @@ void /*$*/member/*$$*/() {
//@A.h //@A.h
//= //=
void member() { void member() {
// body comment // body comment
return; return;
@ -115,7 +114,6 @@ void /*$*/member/*$$*/() {
//@A.h //@A.h
//= //=
// Top comment // Top comment
void member() { void member() {
// body comment // body comment

View file

@ -34,7 +34,6 @@ public:
inline A::A(int x, int y) : inline A::A(int x, int y) :
a(x), b(y) { a(x), b(y) {
} }
//!TestConstructorToggleInHeaderToImplementation //!TestConstructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -85,7 +84,6 @@ int main() {
A::A(int x, int y) : A::A(int x, int y) :
a(x), b(y) { a(x), b(y) {
} }
//!TestConstructorToggleInImplementationToClass //!TestConstructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -154,7 +152,6 @@ public:
inline A::~A() { inline A::~A() {
} }
//!TestDestructorToggleInHeaderToImplementation //!TestDestructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -199,7 +196,6 @@ int main() {
A::~A() { A::~A() {
} }
//!TestDestructorToggleInImplementationToClass //!TestDestructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -20,7 +20,6 @@ class A {
inline void A::member(int a, int b) { inline void A::member(int a, int b) {
return; return;
} }
//!TestDefaultParameterInitializerInHeaderToImplementation //!TestDefaultParameterInitializerInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -57,7 +56,6 @@ int main() {
void A::member(int a, int b) { void A::member(int a, int b) {
return; return;
} }
//!TestDefaultParameterInitializerInImplementationToClass //!TestDefaultParameterInitializerInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -54,7 +54,6 @@ int main() {
int freeFunction(int* a, int& b) { int freeFunction(int* a, int& b) {
return 42; return 42;
} }
//!TestFreeFunctionToggleFromImplementationToHeaderWithDeclaration //!TestFreeFunctionToggleFromImplementationToHeaderWithDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -172,7 +171,6 @@ try {
} }
catch (std::exception& e) { catch (std::exception& e) {
} }
//!TestFreeFunction //!TestFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -260,4 +258,3 @@ void freefunction() {
} }
} }

View file

@ -1,4 +1,4 @@
//!TestSimpleNamespaceInClassToInHeader //!Test simple namespace in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -30,7 +30,7 @@ inline void A::foo() {
} }
} }
//!TestSimpleNamespaceInHeaderToImplementationWithinNSDefinition //!Test simple namespace in header to implementation within namespace definition
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -80,8 +80,7 @@ void A::foo() {
} }
} }
//!Test simple namespace in header to implementation with namespace definition in implementation
//!TestSimpleNamespaceInHeaderToImplementationWithNSDefinitionInImpl
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -134,7 +133,7 @@ void A::foo() {
} }
} }
//!TestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName //!Test simple namespace in header to implementation with namespace qualified name
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -184,7 +183,6 @@ void A::foo() {
} }
} }
//!TestSimpleNamespaceFromImplementationToInHeader //!TestSimpleNamespaceFromImplementationToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -24,7 +24,6 @@ class A {
inline void A::B::member(int a, int b) { inline void A::B::member(int a, int b) {
return; return;
} }
//!TestNestedClassInHeaderToImplementation //!TestNestedClassInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -65,7 +64,6 @@ int main() {
void A::B::member(int a, int b) { void A::B::member(int a, int b) {
return; return;
} }
//!TestNestedClassInImplementationToClass //!TestNestedClassInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -1,4 +1,4 @@
//!TestZeroLengthSelection //!Test zero length selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -16,8 +16,7 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!Test substring selection
//!TestSubstringSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -35,8 +34,7 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!Test body selection
//!TestBodySelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -54,8 +52,7 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!Test body selection with confusing name
//!TestBodySelectionWithConfusingName
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -75,8 +72,7 @@ inline void A::member() {
int abcd = 42; int abcd = 42;
return; return;
} }
//!Test left border selection
//!TestLeftBorderSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -94,8 +90,7 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!Test right border selection
//!TestRightBorderSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -113,8 +108,7 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }
//!Test overlapping selection
//!TestOverlappingSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -132,4 +126,3 @@ class A {
inline void A::member() { inline void A::member() {
return; return;
} }

View file

@ -1,4 +1,4 @@
//!TestSimpleFunctionInClassToInHeader //!Test simple function in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -28,8 +28,7 @@ private:
inline int A::function() { inline int A::function() {
return 0; return 0;
} }
//!Test simple function in header to implementation
//!TestSimpleFunctionInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -73,7 +72,6 @@ int main() {
int A::function() { int A::function() {
return 0; return 0;
} }
//!TestSimpleFunctionInImplementationToInClass //!TestSimpleFunctionInImplementationToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -1,4 +1,4 @@
//!TestTemplateFunctionInClassToInHeader //!Test template function in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -27,8 +27,7 @@ template<typename T, typename U>
inline T A<T, U>::B::member() { inline T A<T, U>::B::member() {
return T(); return T();
} }
//!Test template function in header to in class
//!TestTemplateFunctionInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -57,7 +56,7 @@ class A {
} }
}; };
}; };
//!TestTemplateFunctionInHeaderToInClassWithTemplateSelected //!Test template function in header to in class with template selected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -78,8 +77,7 @@ template<typename T>
inline T A::foo() { inline T A::foo() {
return T(); return T();
} }
//!Test complex template function from in class to in header
//!TestComplexTemplateFunctionFromInClassToInheader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -105,8 +103,7 @@ template<typename U, typename V>
inline void A<T, S>::foo(const U& u, const V& v) { inline void A<T, S>::foo(const U& u, const V& v) {
return; return;
} }
//!Test complex template function from in header to in class
//!TestComplexTemplateFunctionFromInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h

View file

@ -30,7 +30,6 @@ try {
catch (std::exception& e1) { catch (std::exception& e1) {
return; return;
} }
//!TestTryCatchFromInHeaderToImplementation //!TestTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -77,7 +76,6 @@ try {
catch (std::exception& e1) { catch (std::exception& e1) {
return; return;
} }
//!TestTryCatchFromInImplementationToClass //!TestTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -160,7 +158,6 @@ catch (std::exception& e1) {
catch (std::exception& e2) { catch (std::exception& e2) {
return; return;
} }
//!TestMultipleTryCatchFromInHeaderToImplementation //!TestMultipleTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -213,7 +210,6 @@ catch (std::exception& e1) {
catch (std::exception& e2) { catch (std::exception& e2) {
return; return;
} }
//!TestMultipleTryCatchFromInImplementationToClass //!TestMultipleTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -18,7 +18,6 @@ class A {
inline int A::foo() { inline int A::foo() {
return 0; return 0;
} }
//!TestVirtualSpecifierFromInHeaderToImplementation //!TestVirtualSpecifierFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//%CPP //%CPP
@ -52,7 +51,6 @@ int main() {
int A::foo() { int A::foo() {
return 0; return 0;
} }
//!TestVirtualSpecifierFromImplementationToHeader //!TestVirtualSpecifierFromImplementationToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation * Martin Schwab & Thomas Kallenberg - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -29,7 +29,6 @@ import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.CreateFileChange; import org.eclipse.cdt.internal.ui.refactoring.CreateFileChange;
public class ToggleFileCreator { public class ToggleFileCreator {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String H = ".h"; //$NON-NLS-1$ private static final String H = ".h"; //$NON-NLS-1$
private ToggleRefactoringContext context; private ToggleRefactoringContext context;
@ -71,7 +70,7 @@ public class ToggleFileCreator {
CreateFileChange change; CreateFileChange change;
String filename = getNewFileName(); String filename = getNewFileName();
try { try {
change = new CreateFileChange(filename, new Path(getPath()+filename), change = new CreateFileChange(filename, new Path(getPath() + filename),
EMPTY_STRING, context.getSelectionFile().getCharset()); EMPTY_STRING, context.getSelectionFile().getCharset());
change.perform(new NullProgressMonitor()); change.perform(new NullProgressMonitor());
} catch (CoreException e) { } catch (CoreException e) {
@ -85,6 +84,7 @@ public class ToggleFileCreator {
} }
final Container<Boolean> answer = new Container<Boolean>(); final Container<Boolean> answer = new Container<Boolean>();
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override
public void run() { public void run() {
Shell shell = CUIPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell(); Shell shell = CUIPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell();
String functionname; String functionname;
@ -103,7 +103,7 @@ public class ToggleFileCreator {
} }
public String getIncludeStatement() { public String getIncludeStatement() {
return "#include \"" + ToggleNodeHelper.getFilenameWithoutExtension(getNewFileName()) + ".h\""; //$NON-NLS-1$//$NON-NLS-2$ return "#include \"" + ToggleNodeHelper.getFilenameWithoutExtension(getNewFileName()) + ".h\"\n"; //$NON-NLS-1$//$NON-NLS-2$
} }
private String getNewFileName() { private String getNewFileName() {

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation * Martin Schwab & Thomas Kallenberg - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -57,7 +57,6 @@ import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefactoringStrategy { public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefactoringStrategy {
private IASTTranslationUnit impl_unit; private IASTTranslationUnit impl_unit;
private ToggleRefactoringContext context; private ToggleRefactoringContext context;
private TextEditGroup infoText; private TextEditGroup infoText;
@ -68,16 +67,16 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
this.context = context; this.context = context;
} }
@Override
public void run(ModificationCollector collector) { public void run(ModificationCollector collector) {
if(!newFileCheck()) { if (!newFileCheck()) {
return; return;
} }
// newFileCheck(); // newFileCheck();
ICPPASTFunctionDefinition newDefinition = getNewDefinition(); ICPPASTFunctionDefinition newDefinition = getNewDefinition();
if (context.getDeclaration() != null) { if (context.getDeclaration() != null) {
removeDefinitionFromHeader(collector); removeDefinitionFromHeader(collector);
} } else {
else {
replaceDefinitionWithDeclaration(collector); replaceDefinitionWithDeclaration(collector);
} }
@ -97,8 +96,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
implRewrite = implRewrite.insertBefore(impl_unit.getTranslationUnit(), implRewrite = implRewrite.insertBefore(impl_unit.getTranslationUnit(),
null, insertionParent, infoText); null, insertionParent, infoText);
} }
} } else {
else {
insertionParent = impl_unit.getTranslationUnit(); insertionParent = impl_unit.getTranslationUnit();
} }
@ -115,25 +113,6 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
private void copyCommentsToNewFile(ICPPASTFunctionDefinition newDefinition, final ASTRewrite newRewriter, private void copyCommentsToNewFile(ICPPASTFunctionDefinition newDefinition, final ASTRewrite newRewriter,
final ASTRewrite oldRewriter) { final ASTRewrite oldRewriter) {
newDefinition.accept(new ASTVisitor(true) { newDefinition.accept(new ASTVisitor(true) {
private void copy(IASTNode node) {
copyComments(node, newRewriter, oldRewriter, CommentPosition.leading);
copyComments(node, newRewriter, oldRewriter, CommentPosition.trailing);
copyComments(node, newRewriter, oldRewriter, CommentPosition.freestanding);
}
private void copyComments(IASTNode node, ASTRewrite newRewriter, ASTRewrite oldRewriter,
CommentPosition pos) {
if (node.getNodeLocations().length > 0 && node.getNodeLocations()[0] instanceof IASTCopyLocation) {
IASTCopyLocation copyLoc = (IASTCopyLocation) node.getNodeLocations()[0];
List<IASTComment> comments = oldRewriter.getComments(copyLoc.getOriginalNode(), pos);
for (IASTComment comment : comments) {
newRewriter.addComment(node, comment, pos);
}
}
}
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
copy(name); copy(name);
@ -241,20 +220,36 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
copy(designator); copy(designator);
return super.visit(designator); return super.visit(designator);
} }
});
private void copy(IASTNode node) {
copyComments(node, newRewriter, oldRewriter, CommentPosition.leading);
copyComments(node, newRewriter, oldRewriter, CommentPosition.trailing);
copyComments(node, newRewriter, oldRewriter, CommentPosition.freestanding);
}
private void copyComments(IASTNode node, ASTRewrite newRewriter, ASTRewrite oldRewriter,
CommentPosition pos) {
if (node.getNodeLocations().length > 0 && node.getNodeLocations()[0] instanceof IASTCopyLocation) {
IASTCopyLocation copyLoc = (IASTCopyLocation) node.getNodeLocations()[0];
List<IASTComment> comments = oldRewriter.getComments(copyLoc.getOriginalNode(), pos);
for (IASTComment comment : comments) {
newRewriter.addComment(node, comment, pos);
}
}
}
});
} }
private boolean newFileCheck() { private boolean newFileCheck() {
impl_unit = context.getTUForSiblingFile(); impl_unit = context.getTUForSiblingFile();
if (this.impl_unit == null) { if (impl_unit == null) {
ToggleFileCreator filecreator = new ToggleFileCreator(context, ".cpp"); //$NON-NLS-1$ ToggleFileCreator filecreator = new ToggleFileCreator(context, ".cpp"); //$NON-NLS-1$
if (filecreator.askUserForFileCreation(context)) { if (filecreator.askUserForFileCreation(context)) {
filecreator.createNewFile(); filecreator.createNewFile();
impl_unit = filecreator.loadTranslationUnit(); impl_unit = filecreator.loadTranslationUnit();
includenode = new ASTLiteralNode(filecreator.getIncludeStatement()); includenode = new ASTLiteralNode(filecreator.getIncludeStatement());
return true; return true;
}else { } else {
return false; return false;
} }
} }
@ -269,8 +264,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
return ToggleNodeHelper.getAncestorOfType(toquery, ICPPASTNamespaceDefinition.class); return ToggleNodeHelper.getAncestorOfType(toquery, ICPPASTNamespaceDefinition.class);
} }
private IASTNode findInsertionPoint(IASTNode insertionParent, private IASTNode findInsertionPoint(IASTNode insertionParent, IASTTranslationUnit unit) {
IASTTranslationUnit unit) {
IASTFunctionDeclarator declarator = context.getDeclaration(); IASTFunctionDeclarator declarator = context.getDeclaration();
if (unit == null) { if (unit == null) {
unit = context.getDefinitionUnit(); unit = context.getDefinitionUnit();
@ -283,34 +277,33 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
return insertion_point; return insertion_point;
} }
private void restoreLeadingComments( private void restoreLeadingComments(ICPPASTFunctionDefinition newDefinition,
ICPPASTFunctionDefinition newDefinition, ASTRewrite newRewriter, ModificationCollector collector) { ASTRewrite newRewriter, ModificationCollector collector) {
ASTRewrite rw = collector.rewriterForTranslationUnit(context.getDefinitionUnit()); ASTRewrite rw = collector.rewriterForTranslationUnit(context.getDefinitionUnit());
List<IASTComment>comments = rw.getComments(context.getDefinition(), CommentPosition.leading); List<IASTComment>comments = rw.getComments(context.getDefinition(), CommentPosition.leading);
if(comments != null) { if (comments != null) {
for (IASTComment comment : comments) { for (IASTComment comment : comments) {
newRewriter.addComment(newDefinition, comment, CommentPosition.leading); newRewriter.addComment(newDefinition, comment, CommentPosition.leading);
if(context.getDeclaration() != null) { if (context.getDeclaration() != null) {
rw.remove(comment, infoText); rw.remove(comment, infoText);
} }
} }
} }
} }
private void replaceDefinitionWithDeclaration( private void replaceDefinitionWithDeclaration(ModificationCollector collector) {
ModificationCollector collector) {
IASTSimpleDeclaration newdeclarator = IASTSimpleDeclaration newdeclarator =
ToggleNodeHelper.createDeclarationFromDefinition(context.getDefinition()); ToggleNodeHelper.createDeclarationFromDefinition(context.getDefinition());
ASTRewrite rewrite = collector.rewriterForTranslationUnit(context.getDefinitionUnit()); ASTRewrite rewrite = collector.rewriterForTranslationUnit(context.getDefinitionUnit());
rewrite.replace(context.getDefinition(), newdeclarator, infoText); rewrite.replace(context.getDefinition(), newdeclarator, infoText);
} }
private ICPPASTFunctionDefinition getNewDefinition() { private ICPPASTFunctionDefinition getNewDefinition() {
ICPPASTFunctionDefinition newDefinition = ICPPASTFunctionDefinition newDefinition =
ToggleNodeHelper.createFunctionSignatureWithEmptyBody( ToggleNodeHelper.createFunctionSignatureWithEmptyBody(
context.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations), context context.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations),
.getDefinition().getDeclarator().copy(CopyStyle.withLocations), context context.getDefinition().getDeclarator().copy(CopyStyle.withLocations),
.getDefinition().copy(CopyStyle.withLocations)); context.getDefinition().copy(CopyStyle.withLocations));
newDefinition.getDeclSpecifier().setInline(false); newDefinition.getDeclSpecifier().setInline(false);
newDefinition.setBody(context.getDefinition().getBody().copy(CopyStyle.withLocations)); newDefinition.setBody(context.getDefinition().getBody().copy(CopyStyle.withLocations));
if (newDefinition instanceof ICPPASTFunctionWithTryBlock) { if (newDefinition instanceof ICPPASTFunctionWithTryBlock) {
@ -329,7 +322,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
ICPPASTNamespaceDefinition ns = (ICPPASTNamespaceDefinition) parent; ICPPASTNamespaceDefinition ns = (ICPPASTNamespaceDefinition) parent;
if (new_definition.getDeclarator().getName() instanceof ICPPASTQualifiedName) { if (new_definition.getDeclarator().getName() instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname = ICPPASTQualifiedName qname =
(ICPPASTQualifiedName) new_definition.getDeclarator().getName(); (ICPPASTQualifiedName) new_definition.getDeclarator().getName();
ICPPASTQualifiedName qname_new = new CPPASTQualifiedName(); ICPPASTQualifiedName qname_new = new CPPASTQualifiedName();
boolean start = false; boolean start = false;
for(IASTName partname: qname.getNames()) { for(IASTName partname: qname.getNames()) {
@ -346,11 +339,9 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
} }
} }
private CPPASTNamespaceDefinition createNamespace( private CPPASTNamespaceDefinition createNamespace(ICPPASTNamespaceDefinition parent_namespace) {
ICPPASTNamespaceDefinition parent_namespace) {
CPPASTNamespaceDefinition insertionParent = new CPPASTNamespaceDefinition( CPPASTNamespaceDefinition insertionParent = new CPPASTNamespaceDefinition(
parent_namespace.getName() parent_namespace.getName().copy(CopyStyle.withLocations));
.copy(CopyStyle.withLocations));
insertionParent.setParent(impl_unit); insertionParent.setParent(impl_unit);
return insertionParent; return insertionParent;
} }
@ -363,19 +354,19 @@ parent_namespace.getName()
private IASTNode searchNamespaceInImplementation(final IASTName name) { private IASTNode searchNamespaceInImplementation(final IASTName name) {
final Container<IASTNode> result = new Container<IASTNode>(); final Container<IASTNode> result = new Container<IASTNode>();
this.impl_unit.accept( this.impl_unit.accept(new ASTVisitor() {
new ASTVisitor() { {
{ shouldVisitNamespaces = true;
shouldVisitNamespaces = true; }
}
@Override @Override
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) { public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
if (name.toString().equals(namespaceDefinition.getName().toString())) { if (name.toString().equals(namespaceDefinition.getName().toString())) {
result.setObject(namespaceDefinition); result.setObject(namespaceDefinition);
return PROCESS_ABORT; return PROCESS_ABORT;
} }
return super.visit(namespaceDefinition); return super.visit(namespaceDefinition);
} }
}); });
return result.getObject(); return result.getObject();
} }