//!Extract boolean comparison from if-condition. //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=check //@test.h class Test { void test(); }; //= class Test { void test(); bool check(); }; //@test.cpp #include "test.h" void Test::test() { if (/*$*/5 == 3 + 2/*$$*/) { //... } } //= #include "test.h" bool Test::check() { return 5 == 3 + 2; } void Test::test() { if (check()) { //... } } //!Extract boolean comparison from if-condition with parameter. //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=check //@test.h class Test { void test(); }; //= class Test { void test(); bool check(int num); }; //@test.cpp #include "test.h" void Test::test() { int num = 1; if (/*$*/5 != 3 + num/*$$*/) { //... } } //= #include "test.h" bool Test::check(int num) { return 5 != 3 + num; } void Test::test() { int num = 1; if (check(num)) { //... } } //!Extract binary expression that results in a function with the same return type (BasicType) as the LHS. //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=add //@test.h class Test { void test(); }; //= class Test { void test(); int add(int five, int six); }; //@test.cpp #include "test.h" void Test::test() { int five = 5; int six = 6; int result = /*$*/five + six/*$$*/; } //= #include "test.h" int Test::add(int five, int six) { return five + six; } void Test::test() { int five = 5; int six = 6; int result = add(five, six); } //!Extract binary expression that results in a function with the same return type (ClassType) as the LHS //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=cat //@test.h struct helper {}; class Test { void test(); }; //= struct helper {}; class Test { void test(); helper cat(helper s1, helper s2); }; //@test.cpp #include "test.h" void Test::test() { helper s1 = "a"; helper s2 = "b"; helper result = /*$*/s1 + s2/*$$*/; } //= #include "test.h" helper Test::cat(helper s1, helper s2) { return s1 + s2; } void Test::test() { helper s1 = "a"; helper s2 = "b"; helper result = cat(s1, s2); } //!Extract binary expression that results in a function with the same return type (Typedef) as the LHS //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=cat //@test.h struct helper {}; typedef helper new_helper; class Test { void test(); }; //= struct helper {}; typedef helper new_helper; class Test { void test(); new_helper cat(new_helper s1, new_helper s2); }; //@test.cpp #include "test.h" void Test::test() { new_helper s1 = "a"; new_helper s2 = "b"; new_helper result = /*$*/s1 + s2/*$$*/; } //= #include "test.h" new_helper Test::cat(new_helper s1, new_helper s2) { return s1 + s2; } void Test::test() { new_helper s1 = "a"; new_helper s2 = "b"; new_helper result = cat(s1, s2); } //!Extract new-Expression //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=new_helper //@test.cpp struct helper {}; int main(int argc, char** argv) { helper* h = /*$*/new helper/*$$*/; return 0; } //= struct helper {}; helper* new_helper() { return new helper; } int main(int argc, char** argv) { helper* h = new_helper(); return 0; } //!Extract function call //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=join_with_world //@test.cpp class string {}; string join(string s1, char* s2) { return s1 + " " + s2; } int main() { string hello = "Hello"; cout << /*$*/join(hello, "World")/*$$*/ << endl; } //= class string {}; string join(string s1, char* s2) { return s1 + " " + s2; } string join_with_world(string hello) { return join(hello, "World"); } int main() { string hello = "Hello"; cout << join_with_world(hello) << endl; } //!Extract method call //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=value_from //@test.cpp struct other { bool value() {} }; class Klass { void set(bool b) { } void test() { other o; this->set(/*$*/o.value()/*$$*/); } }; //= struct other { bool value() {} }; class Klass { void set(bool b) { } bool value_from(other o) { return o.value(); } void test() { other o; this->set(value_from(o)); } }; //!Extract function call [we only have the declaration] that returns a pointer //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=has //@test.cpp class Cursor{}; Cursor* contains(const Cursor& pos); int main() { Cursor c; contains(/*$*/contains(c)/*$$*/); } //= class Cursor{}; Cursor* contains(const Cursor& pos); Cursor* has(Cursor c) { return contains(c); } int main() { Cursor c; contains(has(c)); } //!Extract function call [we have the definition] that returns a pointer //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=has //@test.cpp class Cursor{}; Cursor* contains(const Cursor& pos) { ; } int main() { Cursor c; contains(/*$*/contains(c)/*$$*/); } //= class Cursor{}; Cursor* contains(const Cursor& pos) { ; } Cursor* has(Cursor c) { return contains(c); } int main() { Cursor c; contains(has(c)); } //!Extract string constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=greeting //@test.h class Test { void test(); }; //= class Test { void test(); const char greeting(); }; //@test.cpp #include "test.h" void Test::test() { char* hi = /*$*/"hello"/*$$*/; } //= #include "test.h" const char Test::greeting() { return "hello"; } void Test::test() { char* hi = greeting(); } //!Extract int constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=size //@test.h class Test { void test(); }; //= class Test { void test(); int size(); }; //@test.cpp #include "test.h" void Test::test() { int i = /*$*/42/*$$*/; } //= #include "test.h" int Test::size() { return 42; } void Test::test() { int i = size(); } //!Extract float constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=certainty //@test.h class Test { void test(); }; //= class Test { void test(); float certainty(); }; //@test.cpp #include "test.h" void Test::test() { float f = /*$*/0.42f/*$$*/; } //= #include "test.h" float Test::certainty() { return 0.42f; } void Test::test() { float f = certainty(); } //!Extract char constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=newline //@test.h class Test { void test(); }; //= class Test { void test(); char newline(); }; //@test.cpp #include "test.h" void Test::test() { char nl = /*$*/'\n'/*$$*/; } //= #include "test.h" char Test::newline() { return '\n'; } void Test::test() { char nl = newline(); } //!Extract boolean true constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=valid //@test.h class Test { void test(); }; //= class Test { void test(); bool valid(); }; //@test.cpp #include "test.h" void Test::test() { bool b = /*$*/true/*$$*/; } //= #include "test.h" bool Test::valid() { return true; } void Test::test() { bool b = valid(); } //!Extract boolean false constant //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=invalid //@test.h class Test { void test(); }; //= class Test { void test(); bool invalid(); }; //@test.cpp #include "test.h" void Test::test() { bool b = /*$*/false/*$$*/; } //= #include "test.h" bool Test::invalid() { return false; } void Test::test() { bool b = invalid(); } //!Extract expression with typedef Bug 331985 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=bar //@test.cpp typedef int& foo; int test(foo s) { int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&' return a; } //= typedef int& foo; int bar(foo s) { return s + 1; } int test(foo s) { int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&' return a; } //!Bug 260133 Extract function and extract local variable don't handle type promotion //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=bar //@test.cpp void foo() { int x = 3; double y = /*$*/x + 2.5/*$$*/; } //= double bar(int x) { return x + 2.5; } void foo() { int x = 3; double y = bar(x); } //! Extract macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config filename=test.cpp methodname=bar //@test.cpp #define five 5 #define ADD(a, b) a + b int main() { int i = five; //comment3 i = /*$*/ADD(i, five)/*$$*/; return i; } //= #define five 5 #define ADD(a, b) a + b int bar(int i) { return ADD(i, five); } int main() { int i = five; //comment3 i = bar(i); return i; }