1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Fixed unnecessary passing parameters by reference.

This commit is contained in:
Sergey Prigogin 2012-01-16 22:10:28 -08:00
parent 9b5c46e407
commit d184e414d0
13 changed files with 236 additions and 388 deletions

View file

@ -662,11 +662,9 @@ void foo() {
} }
//! Extract macro //! Extract macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=test.cpp filename=test.cpp
methodname=bar methodname=bar
//@test.cpp //@test.cpp
#define five 5 #define five 5
#define ADD(a, b) a + b #define ADD(a, b) a + b
@ -681,7 +679,7 @@ int main() {
#define five 5 #define five 5
#define ADD(a, b) a + b #define ADD(a, b) a + b
int bar(int& i) { int bar(int i) {
return ADD(i, five); return ADD(i, five);
} }

View file

@ -1,4 +1,4 @@
//!ExtractFunctionRefactoringTest variable defined in scope //!Extract function with variable defined in scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -74,7 +74,7 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with comment //!Extract function with comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -156,10 +156,8 @@ int A::help() {
filename=A.cpp filename=A.cpp
methodname=exp methodname=exp
replaceduplicates=false replaceduplicates=false
returnvalue=false
returnparameterindex=0
//!Extract Function first extracted statement with leading comment //!Extract function first extracted statement with leading comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@main.cpp //@main.cpp
int main() { int main() {
@ -186,10 +184,8 @@ int main() {
filename=main.cpp filename=main.cpp
methodname=exp methodname=exp
replaceduplicates=false replaceduplicates=false
returnvalue=false
returnparameterindex=0
//!Extract Function last extracted statement with trailling comment //!Extract function last extracted statement with trailling comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@main.cpp //@main.cpp
int main() { int main() {
@ -213,10 +209,8 @@ int main() {
filename=main.cpp filename=main.cpp
methodname=exp methodname=exp
replaceduplicates=false replaceduplicates=false
returnvalue=false
returnparameterindex=0
//!ExtractFunctionRefactoringTest with two variable defined in scope //!Extract function with two variable defined in scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
fatalerror=true fatalerror=true
@ -259,7 +253,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with named typed field //!Extract function with named typed field
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -352,7 +346,7 @@ public:
#endif /*B_H_*/ #endif /*B_H_*/
//!ExtractFunctionRefactoringTest with named typed variable defined in scope //!Extract function with named typed variable defined in scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -445,7 +439,7 @@ public:
#endif /*B_H_*/ #endif /*B_H_*/
//!ExtractFunctionRefactoringTest with ObjectStyleMacro //!Extract function with ObjectStyleMacro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -530,7 +524,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with FunctionStyleMacro //!Extract function with FunctionStyleMacro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -615,7 +609,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractMethod with Pointer //!Extract method with pointer
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -645,7 +639,7 @@ public:
private: private:
int help(); int help();
void exp(int*& i); void exp(int* i);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -679,7 +673,7 @@ A::A() {
A::~A() { A::~A() {
} }
void A::exp(int*& i) { void A::exp(int* i) {
++*i; ++*i;
help(); help();
} }
@ -694,7 +688,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractMethod with Pointer and Comment at the end //!Extract method with pointer and comment at the end
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -711,7 +705,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -724,11 +717,10 @@ public:
private: private:
int help(); int help();
void exp(int*& i); void exp(int* i);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -749,7 +741,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -759,7 +750,7 @@ A::A() {
A::~A() { A::~A() {
} }
void A::exp(int*& i) { void A::exp(int* i) {
++*i; ++*i;
help(); help();
} }
@ -774,8 +765,7 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract method with pointer and comment
//!ExtractMethod with Pointer and Comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -792,7 +782,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -805,11 +794,10 @@ public:
private: private:
int help(); int help();
void exp(int*& i); void exp(int* i);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -830,7 +818,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -840,7 +827,7 @@ A::A() {
A::~A() { A::~A() {
} }
void A::exp(int*& i) { void A::exp(int* i) {
++*i; ++*i;
help(); help();
} }
@ -855,12 +842,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with return value
//!ExtractFunctionRefactoringTest with Return Value
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -876,7 +862,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -893,7 +878,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -913,7 +897,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -938,12 +921,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with return value and ref parameter
//!ExtractFunctionRefactoringTest with Return Value and Ref Parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -959,7 +941,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -972,11 +953,10 @@ public:
private: private:
int help(); int help();
int exp(int i, int& b); int exp(int i, int b);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -999,7 +979,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1009,7 +988,7 @@ A::A() {
A::~A() { A::~A() {
} }
int A::exp(int i, int& b) { int A::exp(int i, int b) {
++i; ++i;
i = i + b; i = i + b;
help(); help();
@ -1027,12 +1006,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with return value and ref parameter and some more not used afterwards
//!ExtractFunctionRefactoringTest with Return Value and Ref Parameter and some more not used aferwards
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1048,7 +1026,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1061,11 +1038,10 @@ public:
private: private:
int help(); int help();
int exp(int i, B* b, int y, float& x); int exp(int i, B* b, int y, float x);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1091,7 +1067,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1101,7 +1076,7 @@ A::A() {
A::~A() { A::~A() {
} }
int A::exp(int i, B* b, int y, float& x) { int A::exp(int i, B* b, int y, float x) {
++i; ++i;
b->hello(y); b->hello(y);
i = i + x; i = i + x;
@ -1122,12 +1097,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with return value take the second and ref parameter and some more not used aferwards
//!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter and some more not used aferwards
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
returnparameterindex=1 returnparameterindex=1
returnvalue=true returnvalue=x
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1145,7 +1119,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1164,7 +1137,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1190,7 +1162,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1221,7 +1192,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@B.h //@B.h
#ifndef B_H_ #ifndef B_H_
#define B_H_ #define B_H_
@ -1234,12 +1204,11 @@ public:
}; };
#endif /*B_H_*/ #endif /*B_H_*/
//!Extract function with return value and a lot ref parameter
//!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1257,7 +1226,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1272,11 +1240,10 @@ public:
private: private:
int help(); int help();
int exp(int i, B*& b, int& y, float& x); int exp(int i, B* b, int y, float x);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1303,7 +1270,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1313,7 +1279,7 @@ A::A() {
A::~A() { A::~A() {
} }
int A::exp(int i, B*& b, int& y, float& x) { int A::exp(int i, B* b, int y, float x) {
++i; ++i;
b->hello(y); b->hello(y);
i = i + x; i = i + x;
@ -1335,7 +1301,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@B.h //@B.h
#ifndef B_H_ #ifndef B_H_
#define B_H_ #define B_H_
@ -1348,12 +1313,11 @@ public:
}; };
#endif /*B_H_*/ #endif /*B_H_*/
//!Extract function with return value take the second and ref parameter
//!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
returnparameterindex=1 returnparameterindex=1
returnvalue=true returnvalue=b
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1371,7 +1335,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1386,11 +1349,10 @@ public:
private: private:
int help(); int help();
B* exp(int& i, B* b, int& y, float& x); B* exp(int& i, B* b, int y, float x);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1417,7 +1379,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1427,7 +1388,7 @@ A::A() {
A::~A() { A::~A() {
} }
B* A::exp(int& i, B* b, int& y, float& x) { B* A::exp(int& i, B* b, int y, float x) {
++i; ++i;
b->hello(y); b->hello(y);
i = i + x; i = i + x;
@ -1449,7 +1410,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@B.h //@B.h
#ifndef B_H_ #ifndef B_H_
#define B_H_ #define B_H_
@ -1462,9 +1422,13 @@ public:
}; };
#endif /*B_H_*/ #endif /*B_H_*/
//!Extract function with protected visibility
//!ExtractFunctionRefactoringTest protected visibility
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=A.cpp
methodname=exp
replaceduplicates=false
visibility=protected
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1540,16 +1504,13 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with public visibility
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=A.cpp filename=A.cpp
methodname=exp methodname=exp
replaceduplicates=false replaceduplicates=false
returnvalue=false visibility=public
returnparameterindex=0
visibility=protected
//!ExtractFunctionRefactoringTest public visibility
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1565,7 +1526,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1582,7 +1542,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1602,7 +1561,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1626,17 +1584,12 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract function with const Method Bug # 46
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=A.cpp filename=A.cpp
methodname=exp methodname=exp
replaceduplicates=false replaceduplicates=false
returnvalue=false
returnparameterindex=0
visibility=public
//!ExtractFunctionRefactoringTest const Method Bug # 46
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1652,7 +1605,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1669,7 +1621,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -1689,7 +1640,6 @@ int A::foo() const {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -1713,14 +1663,6 @@ int A::foo() const {
int A::help() { int A::help() {
return 42; return 42;
} }
//@.config
filename=A.cpp
methodname=exp
replaceduplicates=false
returnvalue=false
returnparameterindex=0
//!Don't return variables that aren't used //!Don't return variables that aren't used
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
@ -1767,7 +1709,7 @@ void function() {
continue;/*$$*/ continue;/*$$*/
} }
} }
//! Bug #124 Extract Function with a Macro call in selected code "forgets" the macro //! Bug #124 Extract function with a Macro call in selected code "forgets" the macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=Test.cpp filename=Test.cpp
@ -1802,7 +1744,7 @@ void testFuerRainer() {
runTest(i); runTest(i);
} }
//! Bug #124 with comments Extract Function with a Macro call in selected code "forgets" the macro //! Bug #124 with comments Extract function with a Macro call in selected code "forgets" the macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=Test.cpp filename=Test.cpp
@ -1833,7 +1775,7 @@ void testFuerRainer() {
runTest(i); runTest(i);
} }
//! Bug #137 String Array problem in Extract Function //! Bug #137 String Array problem in Extract function
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=Test.cpp filename=Test.cpp
@ -1873,9 +1815,6 @@ int main() {
//!Bug 239059: Double & in signature of extracted functions //!Bug 239059: Double & in signature of extracted functions
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
returnvalue=false
returnparameterindex=0
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -2016,7 +1955,6 @@ void Test::test() {
filename=Test.cpp filename=Test.cpp
methodname=startTag methodname=startTag
//@testString.h //@testString.h
namespace test { namespace test {
class string { class string {
@ -2031,7 +1969,6 @@ public:
}; };
} }
//@Test.cpp //@Test.cpp
#include "testString.h" #include "testString.h"
@ -2044,11 +1981,10 @@ test::string toXML() {
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "testString.h" #include "testString.h"
test::string startTag(test::string& name) { test::string startTag(test::string name) {
return "<" + name + ">"; return "<" + name + ">";
} }
@ -2061,7 +1997,6 @@ test::string toXML() {
int main() { int main() {
return 0; return 0;
} }
//!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Typedef //!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Typedef
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
@ -2080,13 +2015,11 @@ public:
string2 operator+(const string2& rhs) { return rhs; } string2 operator+(const string2& rhs) { return rhs; }
string2(char* cp) {} string2(char* cp) {}
string2() {}; string2() {};
}; };
typedef string2 string; typedef string2 string;
} }
//@Test.cpp //@Test.cpp
#include "testString.h" #include "testString.h"
@ -2099,11 +2032,10 @@ test::string toXML() {
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "testString.h" #include "testString.h"
test::string startTag(test::string& name) { test::string startTag(test::string name) {
return "<" + name + ">"; return "<" + name + ">";
} }
@ -2116,7 +2048,6 @@ test::string toXML() {
int main() { int main() {
return 0; return 0;
} }
//!Bug 248622: Extract function fails to extract several expressions; Selection at the end //!Bug 248622: Extract function fails to extract several expressions; Selection at the end
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
@ -2219,7 +2150,7 @@ test::string toXML() {
int main() { int main() {
return 0; return 0;
} }
//!Bug#262000 refactoring "extract function" misinterprets artificial blocks //!Bug#262000 Extract function misinterprets artificial blocks
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=main.cpp filename=main.cpp
@ -2349,7 +2280,7 @@ int Test::calculateStuff() {
return result; return result;
} }
//!Bug#281564 Extract Function fails when catching an unnamed exception //!Bug#281564 Extract function fails when catching an unnamed exception
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=main.cpp filename=main.cpp
@ -2390,7 +2321,7 @@ int main() {
return a; return a;
} }
//!Bug#282004 Refactor->Extract Function in C Project (not C++) won't extract parameters //!Bug#282004 Extract function in C Project (not C++) won't extract parameters
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=main.c filename=main.c
@ -2401,9 +2332,8 @@ int main() {
/*$*/b=a*2;/*$$*/ /*$*/b=a*2;/*$$*/
return a; return a;
} }
//= //=
void exp(int b, int* a) { void exp(int b, int a) {
b = a * 2; b = a * 2;
} }
@ -2412,9 +2342,14 @@ int main() {
exp(b, a); exp(b, a);
return a; return a;
} }
//!Extract function with virtual
//!ExtractFunctionRefactoringTest virtual
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=A.cpp
methodname=exp
replaceduplicates=false
virtual=true
visibility=public
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -2430,7 +2365,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -2447,7 +2381,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -2468,7 +2401,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -2494,18 +2426,12 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@.config
filename=A.cpp
methodname=exp
replaceduplicates=false
returnvalue=false
returnparameterindex=0
virtual=true
visibility=public
//!Bug 288268: c-refactoring creates c++-parameters //!Bug 288268: c-refactoring creates c++-parameters
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=main.c
methodname=test
replaceduplicates=false
//@main.c //@main.c
int main() { int main() {
int a, b; int a, b;
@ -2522,14 +2448,12 @@ int main() {
test(a, b); test(a, b);
return a; return a;
} }
//@.config
filename=main.c
methodname=test
replaceduplicates=false
returnvalue=false
//!Handling of blank lines //!Handling of blank lines
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=main.c
methodname=fib
replaceduplicates=false
//@main.c //@main.c
int main() { int main() {
int f; int f;
@ -2561,7 +2485,3 @@ int main() {
int b = fib(); int b = fib();
f = b; f = b;
} }
//@.config
filename=main.c
methodname=fib
replaceduplicates=false

View file

@ -1,4 +1,4 @@
//!ExtractFunctionRefactoringTest with duplicates //!Extract method with duplicates
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -84,7 +84,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicates with different Names //!Extract method duplicates with different Names
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -170,11 +170,11 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicate with field //!Extract method duplicate with field
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=j
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -267,11 +267,11 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicate with field in marked scope //!Extract method duplicate with field in marked scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=j
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -366,11 +366,11 @@ void A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicates with different Names and return type //!Extract method duplicates with different names and return type
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -465,7 +465,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicates with a lot of different Names an variable not used afterwards in the duplicate //!Extract method duplicates with a lot of different Names an variable not used afterwards in the duplicate
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -558,7 +558,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with duplicate name used afterwards in duplicate but not in original selection this is no duplicate //!Extract method with duplicate name used afterwards in duplicate but not in original selection this is no duplicate
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -645,11 +645,11 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter and a method call //!Extract method with return value and a lot ref parameter and a method call
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -667,7 +667,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -682,11 +681,10 @@ public:
private: private:
int help(); int help();
int exp(int i, B*& b, int& y, float& x); int exp(int i, B* b, int y, float x);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -724,7 +722,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -742,7 +739,7 @@ A::~A() {
i++; i++;
} }
int A::exp(int i, B*& b, int& y, float& x) { int A::exp(int i, B* b, int y, float x) {
++i; ++i;
b->hello(y); b->hello(y);
i = i + x; i = i + x;
@ -764,13 +761,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@B.h //@B.h
#ifndef B_H_ #ifndef B_H_
#define B_H_ #define B_H_
class B class B {
{
public: public:
B(); B();
virtual ~B(); virtual ~B();
@ -778,12 +773,11 @@ public:
}; };
#endif /*B_H_*/ #endif /*B_H_*/
//!Extract method with return value and a lot ref parameter and a method call, duplicate is similar
//!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter and a method call, duplicate is not similar
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
returnvalue=true returnvalue=i
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -801,7 +795,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -816,11 +809,10 @@ public:
private: private:
int help(); int help();
int exp(int i, B*& b, int& y, float x); int exp(int i, B* b, int y, float x);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -857,7 +849,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -869,16 +860,13 @@ A::~A() {
float x = i; float x = i;
B* b = new B(); B* b = new B();
int y = x + i; int y = x + i;
++i; i = exp(i, b, y, x);
b->hello(y);
i = i + x;
help();
b->hello(y); b->hello(y);
++x; ++x;
i++; i++;
} }
int A::exp(int i, B*& b, int& y, float x) { int A::exp(int i, B* b, int y, float x) {
++i; ++i;
b->hello(y); b->hello(y);
i = i + x; i = i + x;
@ -899,13 +887,11 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@B.h //@B.h
#ifndef B_H_ #ifndef B_H_
#define B_H_ #define B_H_
class B class B {
{
public: public:
B(); B();
virtual ~B(); virtual ~B();
@ -913,8 +899,7 @@ public:
}; };
#endif /*B_H_*/ #endif /*B_H_*/
//!Extract method with duplicates and comments
//!ExtractFunctionRefactoringTest with duplicates and comments
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true

View file

@ -83,11 +83,10 @@ int A::help() {
return 42; return 42;
} }
//!Extract Method return value assinged to Macrocall Bug //!Extract method return value assigned to macro call
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
returnvalue=true returnvalue=b
returnparameterindex=1
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -103,7 +102,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -120,7 +118,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -145,7 +142,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -175,12 +171,10 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!Extract method with multiple macros
//!Extract Method Methodlength with more than 1 Macrocall Bug
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
returnvalue=true returnvalue=bb
returnparameterindex=0
replaceduplicates=true replaceduplicates=true
//@A.h //@A.h
#ifndef A_H_ #ifndef A_H_
@ -197,7 +191,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -214,7 +207,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -239,7 +231,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -269,4 +260,3 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }

View file

@ -8,6 +8,7 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractfunction; package org.eclipse.cdt.ui.tests.refactoring.extractfunction;
@ -34,7 +35,7 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionRefactoringTest extends RefactoringTest { public class ExtractFunctionRefactoringTest extends RefactoringTest {
protected String methodName; protected String methodName;
protected boolean replaceDuplicates; protected boolean replaceDuplicates;
protected boolean returnValue; protected String returnValue;
protected int returnParameterIndex; protected int returnParameterIndex;
protected boolean fatalError; protected boolean fatalError;
private VisibilityEnum visibility; private VisibilityEnum visibility;
@ -74,29 +75,25 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
info.setMethodName(methodName); info.setMethodName(methodName);
info.setReplaceDuplicates(replaceDuplicates); info.setReplaceDuplicates(replaceDuplicates);
if (info.getMandatoryReturnVariable() == null) { if (info.getMandatoryReturnVariable() == null) {
if (returnValue) { if (returnValue != null) {
info.setReturnVariable(info.getNamesUsedAfter().get(returnParameterIndex)); for (NameInformation nameInfo : info.getParameterCandidates()) {
info.getNamesUsedAfter().get(returnParameterIndex).setUserSetIsReference(false); if (returnValue.equals(String.valueOf(nameInfo.getName().getSimpleID()))) {
info.setReturnVariable(nameInfo);
nameInfo.setUserSetIsReference(false);
break;
}
}
} }
} else {
info.setReturnVariable(info.getMandatoryReturnVariable());
} }
info.setVisibility(visibility); info.setVisibility(visibility);
info.setVirtual(virtual); info.setVirtual(virtual);
for (NameInformation name : info.getNamesUsedAfter()) {
if (!name.isUserSetIsReturnValue()) {
name.setUserSetIsReference(name.isOutput());
}
}
} }
@Override @Override
protected void configureRefactoring(Properties refactoringProperties) { protected void configureRefactoring(Properties refactoringProperties) {
methodName = refactoringProperties.getProperty("methodname", "exp"); //$NON-NLS-1$ //$NON-NLS-2$ methodName = refactoringProperties.getProperty("methodname", "exp"); //$NON-NLS-1$ //$NON-NLS-2$
replaceDuplicates = Boolean.valueOf(refactoringProperties.getProperty("replaceduplicates", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ replaceDuplicates = Boolean.valueOf(refactoringProperties.getProperty("replaceduplicates", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
returnValue = Boolean.valueOf(refactoringProperties.getProperty("returnvalue", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$ returnValue = refactoringProperties.getProperty("returnvalue", null); //$NON-NLS-1$
returnParameterIndex = new Integer(refactoringProperties.getProperty("returnparameterindex", "0")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_private.toString())); //$NON-NLS-1$ visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_private.toString())); //$NON-NLS-1$
virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -24,12 +24,12 @@ public class ExtractFunctionTestSuite extends TestSuite {
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static Test suite() throws Exception { public static Test suite() throws Exception {
TestSuite suite = new ExtractFunctionTestSuite(); TestSuite suite = new ExtractFunctionTestSuite();
suite.addTest(RefactoringTester.suite("ExtractMethodRefactoringTests", "resources/refactoring/ExtractMethod.rts")); suite.addTest(RefactoringTester.suite("ExtractMethod.rts", "resources/refactoring/ExtractMethod.rts"));
suite.addTest(RefactoringTester.suite("Extract Expression", "resources/refactoring/ExtractExpression.rts")); suite.addTest(RefactoringTester.suite("ExtractExpression.rts", "resources/refactoring/ExtractExpression.rts"));
suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.rts")); suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessor.rts", "resources/refactoring/ExtractMethodPreprocessor.rts"));
suite.addTest(RefactoringTester.suite("Extract Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts")); suite.addTest(RefactoringTester.suite("ExtractFunctionTemplates.rts", "resources/refactoring/ExtractFunctionTemplates.rts"));
suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts")); suite.addTest(RefactoringTester.suite("ExtractMethodHistory.rts", "resources/refactoring/ExtractMethodHistory.rts"));
suite.addTest(RefactoringTester.suite("Extract Function Duplicates Test", "resources/refactoring/ExtractMethodDuplicates.rts")); suite.addTest(RefactoringTester.suite("ExtractFunctionDuplicates.rts", "resources/refactoring/ExtractMethodDuplicates.rts"));
return suite; return suite;
} }
} }

View file

@ -8,10 +8,12 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring; package org.eclipse.cdt.internal.ui.refactoring;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -47,13 +49,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
public class NodeContainer { public class NodeContainer {
public final NameInformation NULL_NAME_INFORMATION = new NameInformation(new CPPASTName()); public final NameInformation NULL_NAME_INFORMATION = new NameInformation(new CPPASTName());
private final List<IASTNode> nodes; private final List<IASTNode> nodes;
private List<NameInformation> names; private List<NameInformation> names;
private List<NameInformation> interfaceNames;
public class NameInformation { public class NameInformation {
private IASTName name; private IASTName name;
@ -214,8 +219,8 @@ public class NodeContainer {
return isOutput; return isOutput;
} }
public void setOutput(boolean output) { public void setOutput(boolean isOutput) {
this.isOutput = output; this.isOutput = isOutput;
} }
public boolean isReturnValue() { public boolean isReturnValue() {
@ -334,94 +339,83 @@ public class NodeContainer {
IASTName name = nameInfo.getName(); IASTName name = nameInfo.getName();
IASTTranslationUnit unit = name.getTranslationUnit(); IASTTranslationUnit unit = name.getTranslationUnit();
IASTName[] decls = unit.getDeclarationsInAST(name.resolveBinding()); IASTName[] nameDeclarations = unit.getDeclarationsInAST(name.resolveBinding());
for (IASTName declaration : decls) { if (nameDeclarations.length != 0) {
nameInfo.setDeclaration(declaration); nameInfo.setDeclaration(nameDeclarations[nameDeclarations.length - 1]);
}
if (nameInfo.isReferencedAfterSelection()) {
nameInfo.setOutput(true);
} }
} }
} }
/*
* Returns all local names in the selection which are referenced after the selection.
*/
public List<NameInformation> getNamesUsedAfter() {
findAllNames();
Set<IASTName> declarations = new HashSet<IASTName>();
List<NameInformation> usedAfter = new ArrayList<NameInformation>();
for (NameInformation nameInfo : names) {
if (declarations.add(nameInfo.getDeclaration())) {
if (nameInfo.isReferencedAfterSelection()) {
usedAfter.add(nameInfo);
}
}
}
return usedAfter;
}
public List<NameInformation> getNamesUsedAfterChoosenByUser() {
findAllNames();
Set<IASTName> declarations = new HashSet<IASTName>();
List<NameInformation> usedAfter = new ArrayList<NameInformation>();
for (NameInformation nameInfo : names) {
if (declarations.add(nameInfo.getDeclaration())) {
if (nameInfo.isUserSetIsReference() || nameInfo.isUserSetIsReturnValue()) {
usedAfter.add(nameInfo);
}
}
}
return usedAfter;
}
public List<NameInformation> getUsedNamesUnique() {
findAllNames();
Set<IASTName> declarations = new HashSet<IASTName>();
List<NameInformation> usedAfter = new ArrayList<NameInformation>();
for (NameInformation nameInfo : names) {
if (declarations.add(nameInfo.getDeclaration())) {
usedAfter.add(nameInfo);
} else {
for (NameInformation nameInformation : usedAfter) {
if (nameInfo.isWriteAccess() &&
nameInfo.getDeclaration() == nameInformation.getDeclaration()) {
nameInformation.setWriteAccess(true);
}
}
}
}
return usedAfter;
}
/** /**
* Returns all variables declared in the selection, which will are referenced after * Returns names that are either parameter or return value candidates.
* the selection.
*/ */
public List<NameInformation> getReturnValueCandidates() { private List<NameInformation> getInterfaceNames() {
if (interfaceNames == null) {
findAllNames();
Set<IASTName> declarations = new HashSet<IASTName>(); Set<IASTName> declarations = new HashSet<IASTName>();
List<NameInformation> usedAfter = new ArrayList<NameInformation>(); interfaceNames = new ArrayList<NameInformation>();
for (NameInformation nameInfo : names) { for (NameInformation nameInfo : names) {
if (nameInfo.isDeclaredInSelection() && nameInfo.isReferencedAfterSelection() && if (declarations.add(nameInfo.getDeclaration())) {
declarations.add(nameInfo.getDeclaration())) { if (nameInfo.isDeclaredInSelection()) {
usedAfter.add(nameInfo); if (nameInfo.isReferencedAfterSelection()) {
// It's a return value candidate, set return value to true and reference to false
nameInfo.setReturnValue(true); nameInfo.setReturnValue(true);
nameInfo.setOutput(false); interfaceNames.add(nameInfo);
}
} else {
for (NameInformation n2 : names) {
if (n2.getDeclaration() == nameInfo.getDeclaration()) {
int flag = CPPVariableReadWriteFlags.getReadWriteFlags(n2.getName());
if ((flag & PDOMName.WRITE_ACCESS) != 0) {
nameInfo.setWriteAccess(true);
break;
}
}
}
if (nameInfo.isWriteAccess() && nameInfo.isReferencedAfterSelection()) {
nameInfo.setOutput(true);
}
interfaceNames.add(nameInfo);
}
}
} }
} }
return usedAfter; return interfaceNames;
}
private List<NameInformation> getInterfaceNames(boolean isReturnValue) {
List<NameInformation> selectedNames = null;
for (NameInformation nameInfo : getInterfaceNames()) {
if (nameInfo.isReturnValue() == isReturnValue) {
if (selectedNames == null) {
selectedNames = new ArrayList<NameInformation>();
}
selectedNames.add(nameInfo);
}
}
if (selectedNames == null) {
selectedNames = Collections.emptyList();
}
return selectedNames;
}
/**
* Returns names that are candidates to be used as function parameters.
*/
public List<NameInformation> getParameterCandidates() {
return getInterfaceNames(false);
}
/**
* Returns names that are candidates for being used as the function return value. Multiple
* return value candidates mean that the function cannot be extracted.
*/
public List<NameInformation> getReturnValueCandidates() {
return getInterfaceNames(true);
} }
public List<IASTNode> getNodesToWrite() { public List<IASTNode> getNodesToWrite() {

View file

@ -50,11 +50,6 @@ public class ChooserComposite extends Composite {
GridLayout layout = new GridLayout(); GridLayout layout = new GridLayout();
setLayout(layout); setLayout(layout);
boolean hasNoPredefinedReturnValue = true;
if (info.getMandatoryReturnVariable() != null) {
hasNoPredefinedReturnValue = false;
}
final ArrayList<Button> returnButtons = new ArrayList<Button>(); final ArrayList<Button> returnButtons = new ArrayList<Button>();
final ArrayList<Button> referenceButtons = new ArrayList<Button>(); final ArrayList<Button> referenceButtons = new ArrayList<Button>();
@ -150,7 +145,7 @@ public class ChooserComposite extends Composite {
final Button returnButton = new Button(table, SWT.RADIO); final Button returnButton = new Button(table, SWT.RADIO);
returnButton.setSelection(name.isReturnValue()); returnButton.setSelection(name.isReturnValue());
name.setUserSetIsReference(name.isOutput()); name.setUserSetIsReference(name.isOutput());
returnButton.setEnabled(hasNoPredefinedReturnValue); returnButton.setEnabled(info.getMandatoryReturnVariable() == null);
returnButton.setBackground(table.getBackground()); returnButton.setBackground(table.getBackground());
returnButton.addSelectionListener(new SelectionListener() { returnButton.addSelectionListener(new SelectionListener() {
@Override @Override
@ -182,7 +177,7 @@ public class ChooserComposite extends Composite {
if (!info.isExtractExpression()) { if (!info.isExtractExpression()) {
voidReturn = new Button(parent, SWT.CHECK | SWT.LEFT); voidReturn = new Button(parent, SWT.CHECK | SWT.LEFT);
voidReturn.setText(Messages.ChooserComposite_NoReturnValue); voidReturn.setText(Messages.ChooserComposite_NoReturnValue);
voidReturn.setEnabled(hasNoPredefinedReturnValue); voidReturn.setEnabled(info.getMandatoryReturnVariable() == null);
voidReturn.addSelectionListener(new SelectionListener() { voidReturn.addSelectionListener(new SelectionListener() {
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
@ -213,9 +208,9 @@ public class ChooserComposite extends Composite {
column.setWidth(100); column.setWidth(100);
} }
void onVisibilityOrReturnChange(List<NameInformation> name) { void onVisibilityOrReturnChange(List<NameInformation> names) {
String variableUsedAfterBlock = null; String variableUsedAfterBlock = null;
for (NameInformation information : name) { for (NameInformation information : names) {
if (information.isReferencedAfterSelection() && if (information.isReferencedAfterSelection() &&
!(information.isUserSetIsReference() || information.isUserSetIsReturnValue())) { !(information.isUserSetIsReference() || information.isUserSetIsReturnValue())) {
variableUsedAfterBlock = information.getName().toString(); variableUsedAfterBlock = information.getName().toString();

View file

@ -11,7 +11,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction; package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
@ -24,7 +23,6 @@ public class ExtractFunctionInformation {
private VisibilityEnum visibility = VisibilityEnum.v_private; private VisibilityEnum visibility = VisibilityEnum.v_private;
private String methodName; private String methodName;
private boolean replaceDuplicates; private boolean replaceDuplicates;
private List<NameInformation> namesUsedAfter;
private List<NameInformation> parameterCandidates; private List<NameInformation> parameterCandidates;
private NameInformation mandatoryReturnVariable; private NameInformation mandatoryReturnVariable;
private NameInformation returnVariable; private NameInformation returnVariable;
@ -62,23 +60,6 @@ public class ExtractFunctionInformation {
this.replaceDuplicates = replaceDuplicates; this.replaceDuplicates = replaceDuplicates;
} }
public List<NameInformation> getNamesUsedAfter() {
if (namesUsedAfter == null) {
namesUsedAfter = new ArrayList<NameInformation>();
for (NameInformation name : getParameterCandidates()) {
if (name.isOutput() || name.isReturnValue()) {
namesUsedAfter.add(name);
}
}
}
return namesUsedAfter;
}
public void setNamesUsedAfter(List<NameInformation> names) {
this.namesUsedAfter = names;
}
public NameInformation getReturnVariable() { public NameInformation getReturnVariable() {
return returnVariable; return returnVariable;
} }
@ -96,6 +77,7 @@ public class ExtractFunctionInformation {
public void setMandatoryReturnVariable(NameInformation variable) { public void setMandatoryReturnVariable(NameInformation variable) {
this.mandatoryReturnVariable = variable; this.mandatoryReturnVariable = variable;
this.returnVariable = variable;
} }
public List<NameInformation> getParameterCandidates() { public List<NameInformation> getParameterCandidates() {

View file

@ -91,8 +91,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
@ -109,7 +107,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
public class ExtractFunctionRefactoring extends CRefactoring { public class ExtractFunctionRefactoring extends CRefactoring {
public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"; //$NON-NLS-1$ public static final String ID =
"org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"; //$NON-NLS-1$
static final Integer NULL_INTEGER = Integer.valueOf(0); static final Integer NULL_INTEGER = Integer.valueOf(0);
static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$ static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$
@ -122,7 +121,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
final Container<Integer> trailPos; final Container<Integer> trailPos;
private final Container<Integer> returnNumber; private final Container<Integer> returnNumber;
protected boolean hasNameResolvingForSimilarError = false; protected boolean hasNameResolvingForSimilarError;
HashMap<String, Integer> nameTrail; HashMap<String, Integer> nameTrail;
@ -159,27 +158,24 @@ public class ExtractFunctionRefactoring extends CRefactoring {
if (isProgressMonitorCanceld(sm, initStatus)) if (isProgressMonitorCanceld(sm, initStatus))
return initStatus; return initStatus;
if (container.isEmpty()) {
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
sm.done();
return initStatus;
}
checkForNonExtractableStatements(container, initStatus); checkForNonExtractableStatements(container, initStatus);
sm.worked(1); sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus)) if (isProgressMonitorCanceld(sm, initStatus))
return initStatus; return initStatus;
markWriteAccess(); info.setParameterCandidates(container.getParameterCandidates());
sm.worked(1); sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus)) if (isProgressMonitorCanceld(sm, initStatus))
return initStatus; return initStatus;
container.getNamesUsedAfter();
info.setParameterCandidates(container.getUsedNamesUnique());
if (container.size() < 1) {
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
sm.done();
return initStatus;
}
List<NameInformation> returnValueCandidates = container.getReturnValueCandidates(); List<NameInformation> returnValueCandidates = container.getReturnValueCandidates();
if (returnValueCandidates.size() > 1) { if (returnValueCandidates.size() > 1) {
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected); initStatus.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
@ -194,20 +190,16 @@ public class ExtractFunctionRefactoring extends CRefactoring {
info.setExtractExpression(isExtractExpression); info.setExtractExpression(isExtractExpression);
info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0))); info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0)));
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); MethodContext context =
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
info.setMethodContext(context); info.setMethodContext(context);
if (info.getMandatoryReturnVariable() != null) { if (info.getMandatoryReturnVariable() != null) {
info.getMandatoryReturnVariable().setUserSetIsReturnValue(true); info.getMandatoryReturnVariable().setUserSetIsReturnValue(true);
} }
for (int i = 0; i < info.getParameterCandidates().size(); i++) { for (NameInformation name : info.getParameterCandidates()) {
if (!info.getParameterCandidates().get(i).isDeclaredInSelection()) {
NameInformation name = info.getParameterCandidates().get(i);
if (!name.isReturnValue()) {
name.setUserSetIsReference(name.isOutput()); name.setUserSetIsReference(name.isOutput());
} }
}
}
sm.done(); sm.done();
} finally { } finally {
unlockIndex(); unlockIndex();
@ -218,15 +210,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
return initStatus; return initStatus;
} }
private void markWriteAccess() throws CoreException {
for (NameInformation name : container.getNames()) {
int flag = CPPVariableReadWriteFlags.getReadWriteFlags(name.getName());
if ((flag & PDOMName.WRITE_ACCESS) != 0) {
name.setWriteAccess(true);
}
}
}
private void checkForNonExtractableStatements(NodeContainer cont, RefactoringStatus status) { private void checkForNonExtractableStatements(NodeContainer cont, RefactoringStatus status) {
NonExtractableStmtFinder finder = new NonExtractableStmtFinder(); NonExtractableStmtFinder finder = new NonExtractableStmtFinder();
for (IASTNode node : cont.getNodesToWrite()) { for (IASTNode node : cont.getNodesToWrite()) {
@ -273,7 +256,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
finalConditions = super.checkFinalConditions(pm); finalConditions = super.checkFinalConditions(pm);
final IASTName astMethodName = new CPPASTName(info.getMethodName().toCharArray()); final IASTName astMethodName = new CPPASTName(info.getMethodName().toCharArray());
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); MethodContext context =
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
if (context.getType() == ContextType.METHOD && !context.isInline()) { if (context.getType() == ContextType.METHOD && !context.isInline()) {
ICPPASTCompositeTypeSpecifier classDeclaration = ICPPASTCompositeTypeSpecifier classDeclaration =
@ -307,8 +291,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
lockIndex(); lockIndex();
try { try {
final IASTName astMethodName = new CPPASTName(info.getMethodName().toCharArray()); final IASTName astMethodName = new CPPASTName(info.getMethodName().toCharArray());
MethodContext context =
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
// Create Declaration in Class // Create Declaration in Class
if (context.getType() == ContextType.METHOD && !context.isInline()) { if (context.getType() == ContextType.METHOD && !context.isInline()) {
@ -349,7 +333,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
firstNodeToWrite.getTranslationUnit()); firstNodeToWrite.getTranslationUnit());
TextEditGroup editGroup = new TextEditGroup(title); TextEditGroup editGroup = new TextEditGroup(title);
if (methodCall instanceof IASTDeclaration){ if (methodCall instanceof IASTDeclaration){
CPPASTDeclarationStatement declarationStatement = new CPPASTDeclarationStatement((IASTDeclaration) methodCall); CPPASTDeclarationStatement declarationStatement =
new CPPASTDeclarationStatement((IASTDeclaration) methodCall);
methodCall = declarationStatement; methodCall = declarationStatement;
} }
insertCallintoTree(methodCall, container.getNodesToWrite(), rewriter, editGroup); insertCallintoTree(methodCall, container.getNodesToWrite(), rewriter, editGroup);
@ -386,7 +371,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
} }
private IASTBinaryExpression getRootBinExp(IASTBinaryExpression binExp, List<IASTNode> nodeList) { private IASTBinaryExpression getRootBinExp(IASTBinaryExpression binExp, List<IASTNode> nodeList) {
while (binExp.getParent() instanceof IASTBinaryExpression && nodeList.contains(((IASTBinaryExpression) binExp.getParent()).getOperand2())) { while (binExp.getParent() instanceof IASTBinaryExpression &&
nodeList.contains(((IASTBinaryExpression) binExp.getParent()).getOperand2())) {
binExp = (IASTBinaryExpression) binExp.getParent(); binExp = (IASTBinaryExpression) binExp.getParent();
} }
return binExp; return binExp;
@ -503,7 +489,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
protected boolean isStatementInTrail(IASTStatement stmt, final List<IASTNode> trail, IIndex index) { protected boolean isStatementInTrail(IASTStatement stmt, final List<IASTNode> trail, IIndex index) {
final Container<Boolean> same = new Container<Boolean>(Boolean.TRUE); final Container<Boolean> same = new Container<Boolean>(Boolean.TRUE);
final TrailNodeEqualityChecker equalityChecker = new TrailNodeEqualityChecker(names, namesCounter, index); final TrailNodeEqualityChecker equalityChecker =
new TrailNodeEqualityChecker(names, namesCounter, index);
stmt.accept(new CPPASTAllVisitor() { stmt.accept(new CPPASTAllVisitor() {
@Override @Override
@ -541,8 +528,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
private boolean isMethodAllreadyDefined(IASTSimpleDeclaration methodDeclaration, private boolean isMethodAllreadyDefined(IASTSimpleDeclaration methodDeclaration,
ICPPASTCompositeTypeSpecifier classDeclaration, IIndex index) { ICPPASTCompositeTypeSpecifier classDeclaration, IIndex index) {
TrailNodeEqualityChecker equalityChecker = new TrailNodeEqualityChecker( TrailNodeEqualityChecker equalityChecker =
names, namesCounter, index); new TrailNodeEqualityChecker(names, namesCounter, index);
IBinding bind = classDeclaration.getName().resolveBinding(); IBinding bind = classDeclaration.getName().resolveBinding();
IASTStandardFunctionDeclarator declarator = IASTStandardFunctionDeclarator declarator =
@ -589,7 +576,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
} }
private void addMethod(IASTName astMethodName, MethodContext context, ASTRewrite rewriter, private void addMethod(IASTName astMethodName, MethodContext context, ASTRewrite rewriter,
IASTNode insertpoint, TextEditGroup group) { IASTNode insertPoint, TextEditGroup group) {
ICPPASTQualifiedName qname = new CPPASTQualifiedName(); ICPPASTQualifiedName qname = new CPPASTQualifiedName();
if (context.getType() == ContextType.METHOD) { if (context.getType() == ContextType.METHOD) {
if (context.getMethodQName() != null) { if (context.getMethodQName() != null) {
@ -616,19 +603,19 @@ public class ExtractFunctionRefactoring extends CRefactoring {
func.setBody(compound); func.setBody(compound);
ASTRewrite subRW; ASTRewrite subRW;
if (insertpoint.getParent() instanceof ICPPASTTemplateDeclaration) { if (insertPoint.getParent() instanceof ICPPASTTemplateDeclaration) {
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration(); CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
templateDeclaration.setParent(ast); templateDeclaration.setParent(ast);
for (ICPPASTTemplateParameter param : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) { for (ICPPASTTemplateParameter param : ((ICPPASTTemplateDeclaration) insertPoint.getParent()).getTemplateParameters()) {
templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations)); templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations));
} }
templateDeclaration.setDeclaration(func); templateDeclaration.setDeclaration(func);
subRW = rewriter.insertBefore(insertpoint.getParent().getParent(), insertpoint.getParent(), subRW = rewriter.insertBefore(insertPoint.getParent().getParent(), insertPoint.getParent(),
templateDeclaration, group); templateDeclaration, group);
} else { } else {
subRW = rewriter.insertBefore(insertpoint.getParent(), insertpoint, func, group); subRW = rewriter.insertBefore(insertPoint.getParent(), insertPoint, func, group);
} }
extractedFunctionConstructionHelper.constructMethodBody(compound, extractedFunctionConstructionHelper.constructMethodBody(compound,

View file

@ -92,13 +92,11 @@ public abstract class ExtractedFunctionConstructionHelper {
} }
public List<IASTParameterDeclaration> getParameterDeclarations( public List<IASTParameterDeclaration> getParameterDeclarations(
Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) { Collection<NameInformation> parameterNames, INodeFactory nodeFactory) {
List<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>(); List<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>(parameterNames.size());
for (NameInformation name : allUsedNames) { for (NameInformation name : parameterNames) {
if (!name.isDeclaredInSelection()) {
result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory)); result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory));
} }
}
return result; return result;
} }
} }

View file

@ -8,6 +8,7 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction; package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -63,7 +64,7 @@ final class SimilarFinderVisitor extends ASTVisitor {
if (statementCount == statements.size()) { if (statementCount == statements.size()) {
// Found similar code // Found similar code
boolean similarOnReturnWays = true; boolean similarOnReturnWays = true;
for (NameInformation nameInfo : similarContainer.getNamesUsedAfter()) { for (NameInformation nameInfo : similarContainer.getParameterCandidates()) {
if (refactoring.names.containsKey(nameInfo.getDeclaration().getRawSignature())) { if (refactoring.names.containsKey(nameInfo.getDeclaration().getRawSignature())) {
Integer nameOrderNumber = refactoring.names.get(nameInfo.getDeclaration().getRawSignature()); Integer nameOrderNumber = refactoring.names.get(nameInfo.getDeclaration().getRawSignature());
if (refactoring.nameTrail.containsValue(nameOrderNumber)) { if (refactoring.nameTrail.containsValue(nameOrderNumber)) {
@ -72,12 +73,15 @@ final class SimilarFinderVisitor extends ASTVisitor {
for (Entry<String, Integer> entry : refactoring.nameTrail.entrySet()) { for (Entry<String, Integer> entry : refactoring.nameTrail.entrySet()) {
if (entry.getValue().equals(nameOrderNumber)) { if (entry.getValue().equals(nameOrderNumber)) {
orgName = entry.getKey(); orgName = entry.getKey();
break;
} }
} }
if (orgName != null) { if (orgName != null) {
for (NameInformation orgNameInfo : refactoring.container.getNamesUsedAfterChoosenByUser()) { for (NameInformation orgNameInfo : refactoring.container.getParameterCandidates()) {
if (orgName.equals(orgNameInfo.getDeclaration().getRawSignature())) { if (orgName.equals(orgNameInfo.getDeclaration().getRawSignature()) &&
(orgNameInfo.isOutput() || !nameInfo.isOutput())) {
found = true; found = true;
break;
} }
} }
} }
@ -90,9 +94,8 @@ final class SimilarFinderVisitor extends ASTVisitor {
} }
if (similarOnReturnWays) { if (similarOnReturnWays) {
IASTNode call = refactoring.getMethodCall(name, IASTNode call = refactoring.getMethodCall(name, refactoring.nameTrail,
refactoring.nameTrail, refactoring.names, refactoring.names, refactoring.container, similarContainer);
refactoring.container, similarContainer);
ASTRewrite rewrite = ASTRewrite rewrite =
collector.rewriterForTranslationUnit(stmtToReplace.get(0).getTranslationUnit()); collector.rewriterForTranslationUnit(stmtToReplace.get(0).getTranslationUnit());
TextEditGroup editGroup = new TextEditGroup(Messages.SimilarFinderVisitor_replaceDuplicateCode); TextEditGroup editGroup = new TextEditGroup(Messages.SimilarFinderVisitor_replaceDuplicateCode);

View file

@ -135,7 +135,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
sm.worked(1); sm.worked(1);
container.getNamesUsedAfter();
info.addNamesToUsedNames(findAllDeclaredNames()); info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1); sm.worked(1);