//!ExtractFunctionRefactoringTest variable defined in scope //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); int exp(); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { /*$*/int i = 2; ++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } int A::exp() { int i = 2; ++i; help(); return i; } int A::foo() { int i = exp(); return i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int & i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; //comment /*$*/++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int & i) { //comment ++i; help(); } int A::foo() { int i = 2; exp(i); return i; } int A::help() { return 42; } //@.config filename=A.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 //!Extract Function first extracted statement with leading comment //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@main.cpp int main(){ int i; // Comment /*$*/i= 7;/*$$*/ return i; } //= void exp(int & i) { // Comment i = 7; } int main(){ int i; exp(i); return i; } //@.config filename=main.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 //!Extract Function last extracted statement with trailling comment //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@main.cpp int main(){ int i; /*$*/i= 7;/*$$*/ // Comment return i; } //= void exp(int & i) { i = 7; // Comment } int main(){ int i; exp(i); return i; } //@.config filename=main.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 //!ExtractFunctionRefactoringTest with two variable defined in scope //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config fatalerror=true //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { /*$*/int o = 1; int i = 2; ++i; o++; help();/*$$*/ o++; return i; }int A::help() { return 42; } //!ExtractFunctionRefactoringTest with named typed field //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); void foo(); B b; private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); void foo(); B b; private: int help(); void exp(); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } void A::foo() { /*$*/b = new B(); help();/*$$*/ } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp() { b = new B(); help(); } void A::foo() { exp(); } int A::help() { return 42; } //@B.h #ifndef B_H_ #define B_H_ class B { public: B(); virtual ~B(); }; #endif /*B_H_*/ //!ExtractFunctionRefactoringTest with named typed variable defined in scope //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); void foo(); B b; private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); void foo(); B b; private: int help(); void exp(); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } void A::foo() { /*$*/b = new B(); help();/*$$*/ } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp() { b = new B(); help(); } void A::foo() { exp(); } int A::help() { return 42; } //@B.h #ifndef B_H_ #define B_H_ class B { public: B(); virtual ~B(); }; #endif /*B_H_*/ //!ExtractFunctionRefactoringTest with ObjectStyleMacro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int & i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" #define ZWO 2 A::A() { } A::~A() { } int A::foo() { int i = 2; /*$*/++i; i += ZWO; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" #define ZWO 2 A::A() { } A::~A() { } void A::exp(int & i) { ++i; i += ZWO; help(); } int A::foo() { int i = 2; exp(i); return i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest with FunctionStyleMacro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int & i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" #define ADD(a,b) a + b + 2 A::A() { } A::~A() { } int A::foo() { int i = 2; /*$*/++i; i = ADD(i, 42); help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" #define ADD(a,b) a + b + 2 A::A() { } A::~A() { } void A::exp(int & i) { ++i; i = ADD(i, 42); help(); } int A::foo() { int i = 2; exp(i); return i; } int A::help() { return 42; } //!ExtractMethod with Pointer //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int *& i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int* i = new int(2); /*$*/++*i; help();/*$$*/ return *i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int *& i) { ++*i; help(); } int A::foo() { int* i = new int(2); exp(i); return *i; } int A::help() { return 42; } //!ExtractMethod with Pointer and Comment at the end //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int *& i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int* i = new int(2); /*$*/++*i; help(); //A end-comment/*$$*/ return *i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int *& i) { ++*i; help(); } int A::foo() { int* i = new int(2); exp(i); //A end-comment return *i; } int A::help() { return 42; } //!ExtractMethod with Pointer and Comment //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); void exp(int *& i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { //A beautiful comment int* i = new int(2); /*$*/++*i; help();/*$$*/ return *i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int *& i) { ++*i; help(); } int A::foo() { //A beautiful comment int* i = new int(2); exp(i); return *i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest with Return Value //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true returnvalue=true //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); int exp(int i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; /*$*/++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } int A::exp(int i) { ++i; help(); return i; } int A::foo() { int i = 2; i = exp(i); return i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest with Return Value and Ref Parameter //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true returnvalue=true //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); int exp(int i, int & b); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; int b = i; /*$*/++i; i = i + b; help();/*$$*/ ++b; return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } int A::exp(int i, int & b) { ++i; i = i + b; help(); return i; } int A::foo() { int i = 2; int b = i; i = exp(i, b); ++b; return i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest with Return Value and Ref Parameter and some more not used aferwards //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true returnvalue=true //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); int exp(int i, B *b, int y, float & x); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; /*$*/++i; b->hello(y); i = i + x; help();/*$$*/ ++x; return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } int A::exp(int i, B *b, int y, float & x) { ++i; b->hello(y); i = i + x; help(); return i; } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; i = exp(i, b, y, x); ++x; return i; } int A::help() { return 42; } //!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter and some more not used aferwards //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config returnparameterindex=1 returnvalue=true //@A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); float exp(int & i, B *b, int y, float x); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; /*$*/++i; b->hello(y); i = i + x; help();/*$$*/ ++x; return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } float A::exp(int & i, B *b, int y, float x) { ++i; b->hello(y); i = i + x; help(); return x; } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; x = exp(i, b, y, x); ++x; return i; } int A::help() { return 42; } //@B.h #ifndef B_H_ #define B_H_ class B { public: B(); virtual ~B(); void hello(float y); }; #endif /*B_H_*/ //!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true returnvalue=true //@A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); int exp(int i, B *& b, int & y, float & x); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; /*$*/++i; b->hello(y); i = i + x; help();/*$$*/ b->hello(y); ++x; return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } int A::exp(int i, B *& b, int & y, float & x) { ++i; b->hello(y); i = i + x; help(); return i; } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; i = exp(i, b, y, x); b->hello(y); ++x; return i; } int A::help() { return 42; } //@B.h #ifndef B_H_ #define B_H_ class B { public: B(); virtual ~B(); void hello(float y); }; #endif /*B_H_*/ //!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config returnparameterindex=1 returnvalue=true //@A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ #include "B.h" class A { public: A(); virtual ~A(); int foo(); private: int help(); B *exp(int & i, B *b, int & y, float & x); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; /*$*/++i; b->hello(y); i = i + x; help();/*$$*/ b->hello(y); ++x; return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } B *A::exp(int & i, B *b, int & y, float & x) { ++i; b->hello(y); i = i + x; help(); return b; } int A::foo() { int i = 2; float x = i; B* b = new B(); int y = x + i; b = exp(i, b, y, x); b->hello(y); ++x; return i; } int A::help() { return 42; } //@B.h #ifndef B_H_ #define B_H_ class B { public: B(); virtual ~B(); void hello(float y); }; #endif /*B_H_*/ //!ExtractFunctionRefactoringTest protected visibility //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); protected: void exp(int & i); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; /*$*/++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int & i) { ++i; help(); } int A::foo() { int i = 2; exp(i); return i; } int A::help() { return 42; } //@.config filename=A.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 visibility=protected //!ExtractFunctionRefactoringTest public visibility //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(); void exp(int & i); private: int help(); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() { int i = 2; /*$*/++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int & i) { ++i; help(); } int A::foo() { int i = 2; exp(i); return i; } int A::help() { return 42; } //@.config filename=A.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 visibility=public //!ExtractFunctionRefactoringTest const Method Bug # 46 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo() const; private: int help(); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo() const; private: int help(); void exp(int & i) const; }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo() const { int i = 2; /*$*/++i; help();/*$$*/ return i; } int A::help() { return 42; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int & i) const { ++i; help(); } int A::foo() const { int i = 2; exp(i); return i; } int A::help() { return 42; } //@.config filename=A.cpp methodname=exp replaceduplicates=false returnvalue=false returnparameterindex=0 //!don't return variables that aren't used //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=main.h methodname=loop //@main.h void method() { /*$*/for (int var = 0; var < 100; ++var) { if(var < 50) continue; }/*$$*/ } //= void loop() { for(int var = 0;var < 100;++var){ if(var < 50) continue; } } void method() { loop(); } //!don't extract code that contains 'return' //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=main.h fatalerror=true //@main.h void method() { /*$*/if(true) return;/*$$*/ //unreachable } //!test if we don't allow to extract 'continue' Bug #53 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config fatalerror=true filename=A.h //@A.h void function() { for (int var = 0; var < 100; ++var) { /*$*/if(var < 50) continue;/*$$*/ } } //! Bug #124 Extract Function with a Macro call in selected code "forgets" the macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=runTest //@Test.cpp #define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) #define ASSERT(cond) ASSERTM(#cond, cond) void testFuerRainer(){ int i=int(); /*$*/++i; //Leading Comment ASSERT (i); //Trailling Comment --i;/*$$*/ } //= #define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) #define ASSERT(cond) ASSERTM(#cond, cond) void runTest(int i) { ++i; //Leading Comment ASSERT (i); //Trailling Comment --i; } void testFuerRainer(){ int i=int(); runTest(i); } //! Bug #124 with comments Extract Function with a Macro call in selected code "forgets" the macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=runTest //@Test.cpp #define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) #define ASSERT(cond) ASSERTM(#cond, cond) void testFuerRainer(){ int i=int(); /*$*/++i; ASSERT (i); --i;/*$$*/ } //= #define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) #define ASSERT(cond) ASSERTM(#cond, cond) void runTest(int i) { ++i; ASSERT (i); --i; } void testFuerRainer(){ int i=int(); runTest(i); } //! Bug #137 String Array problem in Extract Function //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=runTest //@Test.cpp #include using namespace std; int const INITIAL_CAPACITY = 10; int main(){ int m_capacity; /*$*/m_capacity += INITIAL_CAPACITY; string* newElements = new string[m_capacity];/*$$*/ newElements[0] = "s"; } //= #include using namespace std; int const INITIAL_CAPACITY = 10; string *runTest(int m_capacity) { m_capacity += INITIAL_CAPACITY; string *newElements = new string[m_capacity]; return newElements; } int main(){ int m_capacity; string *newElements = runTest(m_capacity); newElements[0] = "s"; } //!Bug 239059: Double & in signature of extracted functions //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config returnvalue=false returnparameterindex=0 //@A.h #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(int& a); }; #endif /*A_H_*/ //= #ifndef A_H_ #define A_H_ class A { public: A(); virtual ~A(); int foo(int& a); private: void exp(int & a, int b, int c); }; #endif /*A_H_*/ //@A.cpp #include "A.h" A::A() { } A::~A() { } int A::foo(int& a) { int b = 7; int c = 8; /*$*/a = b + c;/*$$*/ return a; } //= #include "A.h" A::A() { } A::~A() { } void A::exp(int & a, int b, int c) { a = b + c; } int A::foo(int& a) { int b = 7; int c = 8; exp(a, b, c); return a; } //!Bug 241717: Typdef causes void as return type //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp //@Test.h #ifndef TEST_H_ #define TEST_H_ class RetValueType{ }; typedef RetValueType RetType; class Test { public: Test(); virtual ~Test(); private: void test(); }; #endif /* TEST_H_ */ //= #ifndef TEST_H_ #define TEST_H_ class RetValueType{ }; typedef RetValueType RetType; class Test { public: Test(); virtual ~Test(); private: void test(); RetType exp(); }; #endif /* TEST_H_ */ //@Test.cpp #include "Test.h" Test::Test() { } Test::~Test() { } void Test::test() { RetType v = /*$*/RetType()/*$$*/; } //= #include "Test.h" Test::Test() { } Test::~Test() { } RetType Test::exp() { return RetType(); } void Test::test() { RetType v = exp(); } //!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Classtype //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=startTag //@testString.h namespace test{ class string{ public: friend string operator+(const string& lhs, const string& rhs) { return rhs; } string operator+(const string& rhs){return rhs;} string(char* cp){} string(){}; }; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return /*$*/"<" + name + ">"/*$$*/ + ""; } int main() { return 0; } //= #include "testString.h" test::string startTag(test::string & name) { return "<" + name + ">"; } test::string toXML() { test::string name; name = "hello"; return startTag(name) + ""; } int main() { return 0; } //!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Typedef //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=startTag //@testString.h namespace test{ class string2{ public: friend string2 operator+(const string2& lhs, const string2& rhs) { return rhs; } string2 operator+(const string2& rhs){return rhs;} string2(char* cp){} string2(){}; }; typedef string2 string; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return /*$*/"<" + name + ">"/*$$*/ + ""; } int main() { return 0; } //= #include "testString.h" test::string startTag(test::string & name) { return "<" + name + ">"; } test::string toXML() { test::string name; name = "hello"; return startTag(name) + ""; } int main() { return 0; } //!Bug 248622: Extract function fails to extract several expressions; Selection at the end //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=endTag //@testString.h namespace test{ class string{ public: friend string operator+(const string& lhs, const string& rhs) { return rhs; } string operator+(const string& rhs){return rhs;} string(char* cp){} string(){}; }; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return "<" + name + ">" + /*$*/""/*$$*/; } int main() { return 0; } //= #include "testString.h" wchar_t endTag(test::string name) { return ""; } test::string toXML() { test::string name; name = "hello"; return "<" + name + ">" + endTag(name); } int main() { return 0; } //!Bug 248622: Extract function fails to extract several expressions; Selection in the middle //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=exp //@testString.h namespace test{ class string{ public: friend string operator+(const string& lhs, const string& rhs) { return rhs; } string operator+(const string& rhs){return rhs;} string(char* cp){} string(){}; }; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return "<" + name + /*$*/">" + ""; } int main() { return 0; } //= #include "testString.h" wchar_t exp() { return ">" + ""; } int main() { return 0; } //!Bug 248622: Extract function fails to extract several expressions; Selection at the end //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=endTag //@testString.h namespace test{ class string{ public: friend string operator+(const string& lhs, const string& rhs) { return rhs; } string operator+(const string& rhs){return rhs;} string(char* cp){} string(){}; }; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return "<" + name + ">" + /*$*/""/*$$*/; } int main() { return 0; } //= #include "testString.h" wchar_t endTag(test::string name) { return ""; } test::string toXML() { test::string name; name = "hello"; return "<" + name + ">" + endTag(name); } int main() { return 0; } //!Bug 248622: Extract function fails to extract several expressions; Selection in the middle //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=Test.cpp methodname=exp //@testString.h namespace test{ class string{ public: friend string operator+(const string& lhs, const string& rhs) { return rhs; } string operator+(const string& rhs){return rhs;} string(char* cp){} string(){}; }; } //@Test.cpp #include "testString.h" test::string toXML() { test::string name; name = "hello"; return "<" + name + /*$*/">" + ""; } int main() { return 0; } //= #include "testString.h" wchar_t exp() { return ">" + ""; } int main() { return 0; } //!Bug#262000 refactoring "extract function" misinterprets artificial blocks //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=main.cpp methodname=exp //@main.cpp int main(int argc, char **argv) { /*$*/int a = 0; { a++; }/*$$*/ } //= void exp() { int a = 0; { a++; } } int main(int argc, char **argv) { exp(); } //!Bug#264712 Refactor extract function deletes comments in header //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=exp //@classhelper.h // Comment // // Comment // Comment #ifndef utils_classhelper_h_seen #define utils_classhelper_h_seen #define IMPORTANT_VALUE 1 #endif //@test.h /* * Copyright 2009 */ #ifndef test_h_seen #define test_h_seen #include "classhelper.h" class Test { public: /** * Small class with some comments */ Test(); /** Calculate important things. * @returns the result of the calculation */ int calculateStuff(); private: /** * Retain a value for something. */ int m_value; }; #endif //= /* * Copyright 2009 */ #ifndef test_h_seen #define test_h_seen #include "classhelper.h" class Test { public: /** * Small class with some comments */ Test(); /** Calculate important things. * @returns the result of the calculation */ int calculateStuff(); private: /** * Retain a value for something. */ int m_value; int exp(); }; #endif //@test.cpp #include "test.h" Test::Test() {} int Test::calculateStuff() { // refactor these lines to a new method: /*$*/int result = m_value; result += 10; result *= 10;/*$$*/ return result; } //= #include "test.h" Test::Test() {} int Test::exp() { // refactor these lines to a new method: int result = m_value; result += 10; result *= 10; return result; } int Test::calculateStuff() { int result = exp(); return result; } //!Bug#281564 Extract Function fails when catching an unnamed exception //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=main.cpp methodname=exp //@main.cpp int myFunc() { return 5; } int main() { int a = 0; /*$*/try { a = myFunc(); } catch(const int & ){ a = 3; }/*$$*/ return a; } //= int myFunc() { return 5; } void exp(int & a) { try { a = myFunc(); } catch(const int & ){ a = 3; } } int main() { int a = 0; exp(a); return a; } //!Bug#282004 Refactor->Extract Function in C Project (not C++) won't extract parameters //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=main.c methodname=exp //@main.c int main() { int a,b; /*$*/b=a*2;/*$$*/ return a; } //= void exp(int b, int & a) { b = a * 2; } int main() { int a,b; exp(b, a); return a; }