Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-01-17 01:10:28 -0500
committerSergey Prigogin2012-01-17 01:19:59 -0500
commitd184e414d04125c66d85cf0c55e6b921d4d7c420 (patch)
treed4055286fd1b794761d321427c96fc565cfeac89
parent9b5c46e407cc2416112c9cca2138cd29d6043116 (diff)
downloadorg.eclipse.cdt-d184e414d04125c66d85cf0c55e6b921d4d7c420.tar.gz
org.eclipse.cdt-d184e414d04125c66d85cf0c55e6b921d4d7c420.tar.xz
org.eclipse.cdt-d184e414d04125c66d85cf0c55e6b921d4d7c420.zip
Fixed unnecessary passing parameters by reference.
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts4
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts224
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts59
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts18
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java25
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java12
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java132
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java13
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java20
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java75
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/SimilarFinderVisitor.java15
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java1
13 files changed, 228 insertions, 380 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts
index 283b5f3c24..1f6f14fa15 100644
--- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts
@@ -662,11 +662,9 @@ void foo() {
}
//! 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
@@ -681,7 +679,7 @@ int main() {
#define five 5
#define ADD(a, b) a + b
-int bar(int& i) {
+int bar(int i) {
return ADD(i, five);
}
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts
index 368414c054..7e1a136079 100644
--- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts
@@ -1,4 +1,4 @@
-//!ExtractFunctionRefactoringTest variable defined in scope
+//!Extract function with variable defined in scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -74,7 +74,7 @@ int A::foo() {
int A::help() {
return 42;
}
-//!ExtractFunctionRefactoringTest with comment
+//!Extract function with comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -156,10 +156,8 @@ int A::help() {
filename=A.cpp
methodname=exp
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
//@main.cpp
int main() {
@@ -186,10 +184,8 @@ int main() {
filename=main.cpp
methodname=exp
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
//@main.cpp
int main() {
@@ -213,10 +209,8 @@ int main() {
filename=main.cpp
methodname=exp
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
//@.config
fatalerror=true
@@ -259,7 +253,7 @@ int A::help() {
return 42;
}
-//!ExtractFunctionRefactoringTest with named typed field
+//!Extract function with named typed field
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -352,7 +346,7 @@ public:
#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
//@A.h
#ifndef A_H_
@@ -445,7 +439,7 @@ public:
#endif /*B_H_*/
-//!ExtractFunctionRefactoringTest with ObjectStyleMacro
+//!Extract function with ObjectStyleMacro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -530,7 +524,7 @@ int A::help() {
return 42;
}
-//!ExtractFunctionRefactoringTest with FunctionStyleMacro
+//!Extract function with FunctionStyleMacro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -615,7 +609,7 @@ int A::help() {
return 42;
}
-//!ExtractMethod with Pointer
+//!Extract method with pointer
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -645,7 +639,7 @@ public:
private:
int help();
- void exp(int*& i);
+ void exp(int* i);
};
#endif /*A_H_*/
@@ -679,7 +673,7 @@ A::A() {
A::~A() {
}
-void A::exp(int*& i) {
+void A::exp(int* i) {
++*i;
help();
}
@@ -694,7 +688,7 @@ int A::help() {
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
//@A.h
#ifndef A_H_
@@ -711,7 +705,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -724,11 +717,10 @@ public:
private:
int help();
- void exp(int*& i);
+ void exp(int* i);
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -749,7 +741,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -759,7 +750,7 @@ A::A() {
A::~A() {
}
-void A::exp(int*& i) {
+void A::exp(int* i) {
++*i;
help();
}
@@ -774,8 +765,7 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!ExtractMethod with Pointer and Comment
+//!Extract method with pointer and comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h
#ifndef A_H_
@@ -792,7 +782,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -805,11 +794,10 @@ public:
private:
int help();
- void exp(int*& i);
+ void exp(int* i);
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -830,7 +818,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -840,7 +827,7 @@ A::A() {
A::~A() {
}
-void A::exp(int*& i) {
+void A::exp(int* i) {
++*i;
help();
}
@@ -855,12 +842,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!ExtractFunctionRefactoringTest with Return Value
+//!Extract function with return value
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -876,7 +862,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -893,7 +878,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -913,7 +897,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -938,12 +921,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!ExtractFunctionRefactoringTest with Return Value and Ref Parameter
+//!Extract function with return value and ref parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -959,7 +941,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -972,11 +953,10 @@ public:
private:
int help();
- int exp(int i, int& b);
+ int exp(int i, int b);
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -999,7 +979,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1009,7 +988,7 @@ A::A() {
A::~A() {
}
-int A::exp(int i, int& b) {
+int A::exp(int i, int b) {
++i;
i = i + b;
help();
@@ -1027,12 +1006,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!ExtractFunctionRefactoringTest with Return Value and Ref Parameter and some more not used aferwards
+//!Extract function with return value and ref parameter and some more not used afterwards
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -1048,7 +1026,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1061,11 +1038,10 @@ public:
private:
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_*/
-
//@A.cpp
#include "A.h"
@@ -1091,7 +1067,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1101,7 +1076,7 @@ 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;
b->hello(y);
i = i + x;
@@ -1122,12 +1097,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter and some more not used aferwards
+//!Extract function 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
+returnvalue=x
//@A.h
#ifndef A_H_
#define A_H_
@@ -1145,7 +1119,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1164,7 +1137,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -1190,7 +1162,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1221,7 +1192,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//@B.h
#ifndef B_H_
#define B_H_
@@ -1234,12 +1204,11 @@ public:
};
#endif /*B_H_*/
-
-//!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter
+//!Extract function with return value and a lot ref parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -1257,7 +1226,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1272,11 +1240,10 @@ public:
private:
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_*/
-
//@A.cpp
#include "A.h"
@@ -1303,7 +1270,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1313,7 +1279,7 @@ 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;
b->hello(y);
i = i + x;
@@ -1335,7 +1301,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//@B.h
#ifndef B_H_
#define B_H_
@@ -1348,12 +1313,11 @@ public:
};
#endif /*B_H_*/
-
-//!ExtractFunctionRefactoringTest with Return Value take the second and Ref Parameter
+//!Extract function with return value take the second and ref parameter
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
returnparameterindex=1
-returnvalue=true
+returnvalue=b
//@A.h
#ifndef A_H_
#define A_H_
@@ -1371,7 +1335,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1386,11 +1349,10 @@ public:
private:
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_*/
-
//@A.cpp
#include "A.h"
@@ -1417,7 +1379,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1427,7 +1388,7 @@ 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;
b->hello(y);
i = i + x;
@@ -1449,7 +1410,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//@B.h
#ifndef B_H_
#define B_H_
@@ -1462,9 +1422,13 @@ public:
};
#endif /*B_H_*/
-
-//!ExtractFunctionRefactoringTest protected visibility
+//!Extract function with protected visibility
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
+//@.config
+filename=A.cpp
+methodname=exp
+replaceduplicates=false
+visibility=protected
//@A.h
#ifndef A_H_
#define A_H_
@@ -1540,16 +1504,13 @@ int A::foo() {
int A::help() {
return 42;
}
+//!Extract function with public visibility
+//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.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
+visibility=public
//@A.h
#ifndef A_H_
#define A_H_
@@ -1565,7 +1526,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1582,7 +1542,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -1602,7 +1561,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1626,17 +1584,12 @@ int A::foo() {
int A::help() {
return 42;
}
-
+//!Extract function with const Method Bug # 46
+//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.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_
@@ -1652,7 +1605,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -1669,7 +1621,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -1689,7 +1640,6 @@ int A::foo() const {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -1713,14 +1663,6 @@ int A::foo() const {
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
@@ -1767,7 +1709,7 @@ void function() {
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
//@.config
filename=Test.cpp
@@ -1802,7 +1744,7 @@ void testFuerRainer() {
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
//@.config
filename=Test.cpp
@@ -1833,7 +1775,7 @@ void testFuerRainer() {
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
//@.config
filename=Test.cpp
@@ -1873,9 +1815,6 @@ int main() {
//!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_
@@ -2016,7 +1955,6 @@ void Test::test() {
filename=Test.cpp
methodname=startTag
//@testString.h
-
namespace test {
class string {
@@ -2031,7 +1969,6 @@ public:
};
}
-
//@Test.cpp
#include "testString.h"
@@ -2044,11 +1981,10 @@ test::string toXML() {
int main() {
return 0;
}
-
//=
#include "testString.h"
-test::string startTag(test::string& name) {
+test::string startTag(test::string name) {
return "<" + name + ">";
}
@@ -2061,7 +1997,6 @@ test::string toXML() {
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
@@ -2080,13 +2015,11 @@ public:
string2 operator+(const string2& rhs) { return rhs; }
string2(char* cp) {}
string2() {};
-
};
typedef string2 string;
}
-
//@Test.cpp
#include "testString.h"
@@ -2099,11 +2032,10 @@ test::string toXML() {
int main() {
return 0;
}
-
//=
#include "testString.h"
-test::string startTag(test::string& name) {
+test::string startTag(test::string name) {
return "<" + name + ">";
}
@@ -2116,7 +2048,6 @@ test::string toXML() {
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
@@ -2219,7 +2150,7 @@ test::string toXML() {
int main() {
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
//@.config
filename=main.cpp
@@ -2349,7 +2280,7 @@ int Test::calculateStuff() {
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
//@.config
filename=main.cpp
@@ -2390,7 +2321,7 @@ int main() {
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
//@.config
filename=main.c
@@ -2401,9 +2332,8 @@ int main() {
/*$*/b=a*2;/*$$*/
return a;
}
-
//=
-void exp(int b, int* a) {
+void exp(int b, int a) {
b = a * 2;
}
@@ -2412,9 +2342,14 @@ int main() {
exp(b, a);
return a;
}
-
-//!ExtractFunctionRefactoringTest virtual
+//!Extract function with virtual
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
+//@.config
+filename=A.cpp
+methodname=exp
+replaceduplicates=false
+virtual=true
+visibility=public
//@A.h
#ifndef A_H_
#define A_H_
@@ -2430,7 +2365,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -2447,7 +2381,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -2468,7 +2401,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -2494,18 +2426,12 @@ int A::foo() {
int A::help() {
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
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
+//@.config
+filename=main.c
+methodname=test
+replaceduplicates=false
//@main.c
int main() {
int a, b;
@@ -2522,14 +2448,12 @@ int main() {
test(a, b);
return a;
}
+//!Handling of blank lines
+//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=main.c
-methodname=test
+methodname=fib
replaceduplicates=false
-returnvalue=false
-
-//!Handling of blank lines
-//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@main.c
int main() {
int f;
@@ -2561,7 +2485,3 @@ int main() {
int b = fib();
f = b;
}
-//@.config
-filename=main.c
-methodname=fib
-replaceduplicates=false
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts
index 3967ebcda7..078efe5bce 100644
--- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts
@@ -1,4 +1,4 @@
-//!ExtractFunctionRefactoringTest with duplicates
+//!Extract method with duplicates
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
@@ -84,7 +84,7 @@ int A::help() {
return 42;
}
-//!ExtractFunctionRefactoringTest duplicates with different Names
+//!Extract method duplicates with different Names
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
@@ -170,11 +170,11 @@ int A::help() {
return 42;
}
-//!ExtractFunctionRefactoringTest duplicate with field
+//!Extract method duplicate with field
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=j
//@A.h
#ifndef A_H_
#define A_H_
@@ -267,11 +267,11 @@ int A::help() {
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
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=j
//@A.h
#ifndef A_H_
#define A_H_
@@ -366,11 +366,11 @@ void A::foo() {
int A::help() {
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
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -465,7 +465,7 @@ int A::help() {
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
//@.config
replaceduplicates=true
@@ -558,7 +558,7 @@ int A::help() {
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
//@.config
replaceduplicates=true
@@ -645,11 +645,11 @@ int A::help() {
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
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -667,7 +667,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -682,11 +681,10 @@ public:
private:
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_*/
-
//@A.cpp
#include "A.h"
@@ -724,7 +722,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -742,7 +739,7 @@ A::~A() {
i++;
}
-int A::exp(int i, B*& b, int& y, float& x) {
+int A::exp(int i, B* b, int y, float x) {
++i;
b->hello(y);
i = i + x;
@@ -764,13 +761,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
//@B.h
#ifndef B_H_
#define B_H_
-class B
-{
+class B {
public:
B();
virtual ~B();
@@ -778,12 +773,11 @@ public:
};
#endif /*B_H_*/
-
-//!ExtractFunctionRefactoringTest with Return Value and a lot Ref Parameter and a method call, duplicate is not similar
+//!Extract method with return value and a lot ref parameter and a method call, duplicate is similar
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
-returnvalue=true
+returnvalue=i
//@A.h
#ifndef A_H_
#define A_H_
@@ -801,7 +795,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -816,11 +809,10 @@ public:
private:
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_*/
-
//@A.cpp
#include "A.h"
@@ -857,7 +849,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -869,16 +860,13 @@ A::~A() {
float x = i;
B* b = new B();
int y = x + i;
- ++i;
- b->hello(y);
- i = i + x;
- help();
+ i = exp(i, b, y, x);
b->hello(y);
++x;
i++;
}
-int A::exp(int i, B*& b, int& y, float x) {
+int A::exp(int i, B* b, int y, float x) {
++i;
b->hello(y);
i = i + x;
@@ -899,13 +887,11 @@ int A::foo() {
int A::help() {
return 42;
}
-
//@B.h
#ifndef B_H_
#define B_H_
-class B
-{
+class B {
public:
B();
virtual ~B();
@@ -913,8 +899,7 @@ public:
};
#endif /*B_H_*/
-
-//!ExtractFunctionRefactoringTest with duplicates and comments
+//!Extract method with duplicates and comments
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
replaceduplicates=true
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts
index 23d300881a..34f789a380 100644
--- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts
@@ -83,11 +83,10 @@ int A::help() {
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
//@.config
-returnvalue=true
-returnparameterindex=1
+returnvalue=b
//@A.h
#ifndef A_H_
#define A_H_
@@ -103,7 +102,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -120,7 +118,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -145,7 +142,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -175,12 +171,10 @@ int A::foo() {
int A::help() {
return 42;
}
-
-//!Extract Method Methodlength with more than 1 Macrocall Bug
+//!Extract method with multiple macros
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
-returnvalue=true
-returnparameterindex=0
+returnvalue=bb
replaceduplicates=true
//@A.h
#ifndef A_H_
@@ -197,7 +191,6 @@ private:
};
#endif /*A_H_*/
-
//=
#ifndef A_H_
#define A_H_
@@ -214,7 +207,6 @@ private:
};
#endif /*A_H_*/
-
//@A.cpp
#include "A.h"
@@ -239,7 +231,6 @@ int A::foo() {
int A::help() {
return 42;
}
-
//=
#include "A.h"
@@ -269,4 +260,3 @@ int A::foo() {
int A::help() {
return 42;
}
-
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
index 737b58108f..020a2bcc54 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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 {
protected String methodName;
protected boolean replaceDuplicates;
- protected boolean returnValue;
+ protected String returnValue;
protected int returnParameterIndex;
protected boolean fatalError;
private VisibilityEnum visibility;
@@ -74,29 +75,25 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
info.setMethodName(methodName);
info.setReplaceDuplicates(replaceDuplicates);
if (info.getMandatoryReturnVariable() == null) {
- if (returnValue) {
- info.setReturnVariable(info.getNamesUsedAfter().get(returnParameterIndex));
- info.getNamesUsedAfter().get(returnParameterIndex).setUserSetIsReference(false);
+ if (returnValue != null) {
+ for (NameInformation nameInfo : info.getParameterCandidates()) {
+ if (returnValue.equals(String.valueOf(nameInfo.getName().getSimpleID()))) {
+ info.setReturnVariable(nameInfo);
+ nameInfo.setUserSetIsReference(false);
+ break;
+ }
+ }
}
- } else {
- info.setReturnVariable(info.getMandatoryReturnVariable());
}
info.setVisibility(visibility);
info.setVirtual(virtual);
-
- for (NameInformation name : info.getNamesUsedAfter()) {
- if (!name.isUserSetIsReturnValue()) {
- name.setUserSetIsReference(name.isOutput());
- }
- }
}
@Override
protected void configureRefactoring(Properties refactoringProperties) {
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$
- returnValue = Boolean.valueOf(refactoringProperties.getProperty("returnvalue", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$
- returnParameterIndex = new Integer(refactoringProperties.getProperty("returnparameterindex", "0")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+ returnValue = refactoringProperties.getProperty("returnvalue", null); //$NON-NLS-1$
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$
virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java
index 46d16bd045..42d36bc051 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java
@@ -24,12 +24,12 @@ public class ExtractFunctionTestSuite extends TestSuite {
@SuppressWarnings("nls")
public static Test suite() throws Exception {
TestSuite suite = new ExtractFunctionTestSuite();
- suite.addTest(RefactoringTester.suite("ExtractMethodRefactoringTests", "resources/refactoring/ExtractMethod.rts"));
- suite.addTest(RefactoringTester.suite("Extract Expression", "resources/refactoring/ExtractExpression.rts"));
- suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.rts"));
- suite.addTest(RefactoringTester.suite("Extract Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts"));
- suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts"));
- suite.addTest(RefactoringTester.suite("Extract Function Duplicates Test", "resources/refactoring/ExtractMethodDuplicates.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractMethod.rts", "resources/refactoring/ExtractMethod.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractExpression.rts", "resources/refactoring/ExtractExpression.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessor.rts", "resources/refactoring/ExtractMethodPreprocessor.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractFunctionTemplates.rts", "resources/refactoring/ExtractFunctionTemplates.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractMethodHistory.rts", "resources/refactoring/ExtractMethodHistory.rts"));
+ suite.addTest(RefactoringTester.suite("ExtractFunctionDuplicates.rts", "resources/refactoring/ExtractMethodDuplicates.rts"));
return suite;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java
index 419307f18b..feff003ae4 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java
@@ -8,10 +8,12 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
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.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.pdom.dom.PDOMName;
public class NodeContainer {
public final NameInformation NULL_NAME_INFORMATION = new NameInformation(new CPPASTName());
private final List<IASTNode> nodes;
private List<NameInformation> names;
+ private List<NameInformation> interfaceNames;
public class NameInformation {
private IASTName name;
@@ -214,8 +219,8 @@ public class NodeContainer {
return isOutput;
}
- public void setOutput(boolean output) {
- this.isOutput = output;
+ public void setOutput(boolean isOutput) {
+ this.isOutput = isOutput;
}
public boolean isReturnValue() {
@@ -334,96 +339,85 @@ public class NodeContainer {
IASTName name = nameInfo.getName();
IASTTranslationUnit unit = name.getTranslationUnit();
- IASTName[] decls = unit.getDeclarationsInAST(name.resolveBinding());
- for (IASTName declaration : decls) {
- nameInfo.setDeclaration(declaration);
- }
- if (nameInfo.isReferencedAfterSelection()) {
- nameInfo.setOutput(true);
+ IASTName[] nameDeclarations = unit.getDeclarationsInAST(name.resolveBinding());
+ if (nameDeclarations.length != 0) {
+ nameInfo.setDeclaration(nameDeclarations[nameDeclarations.length - 1]);
}
}
}
- /*
- * Returns all local names in the selection which are referenced after the selection.
+ /**
+ * Returns names that are either parameter or return value candidates.
*/
- 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);
+ private List<NameInformation> getInterfaceNames() {
+ if (interfaceNames == null) {
+ findAllNames();
+
+ Set<IASTName> declarations = new HashSet<IASTName>();
+ interfaceNames = new ArrayList<NameInformation>();
+
+ for (NameInformation nameInfo : names) {
+ if (declarations.add(nameInfo.getDeclaration())) {
+ if (nameInfo.isDeclaredInSelection()) {
+ if (nameInfo.isReferencedAfterSelection()) {
+ nameInfo.setReturnValue(true);
+ 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;
}
- public List<NameInformation> getNamesUsedAfterChoosenByUser() {
- findAllNames();
-
- Set<IASTName> declarations = new HashSet<IASTName>();
- List<NameInformation> usedAfter = new ArrayList<NameInformation>();
+ private List<NameInformation> getInterfaceNames(boolean isReturnValue) {
+ List<NameInformation> selectedNames = null;
- for (NameInformation nameInfo : names) {
- if (declarations.add(nameInfo.getDeclaration())) {
- if (nameInfo.isUserSetIsReference() || nameInfo.isUserSetIsReturnValue()) {
- usedAfter.add(nameInfo);
+ for (NameInformation nameInfo : getInterfaceNames()) {
+ if (nameInfo.isReturnValue() == isReturnValue) {
+ if (selectedNames == null) {
+ selectedNames = new ArrayList<NameInformation>();
}
+ selectedNames.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);
- }
- }
- }
+ if (selectedNames == null) {
+ selectedNames = Collections.emptyList();
}
+ return selectedNames;
+ }
- return usedAfter;
+ /**
+ * Returns names that are candidates to be used as function parameters.
+ */
+ public List<NameInformation> getParameterCandidates() {
+ return getInterfaceNames(false);
}
+
/**
- * Returns all variables declared in the selection, which will are referenced after
- * the selection.
+ * 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() {
- Set<IASTName> declarations = new HashSet<IASTName>();
- List<NameInformation> usedAfter = new ArrayList<NameInformation>();
-
- for (NameInformation nameInfo : names) {
- if (nameInfo.isDeclaredInSelection() && nameInfo.isReferencedAfterSelection() &&
- declarations.add(nameInfo.getDeclaration())) {
- usedAfter.add(nameInfo);
- // It's a return value candidate, set return value to true and reference to false
- nameInfo.setReturnValue(true);
- nameInfo.setOutput(false);
- }
- }
-
- return usedAfter;
+ return getInterfaceNames(true);
}
-
+
public List<IASTNode> getNodesToWrite() {
return nodes;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java
index 19b8017912..81cfb2db0d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java
@@ -50,11 +50,6 @@ public class ChooserComposite extends Composite {
GridLayout layout = new GridLayout();
setLayout(layout);
- boolean hasNoPredefinedReturnValue = true;
- if (info.getMandatoryReturnVariable() != null) {
- hasNoPredefinedReturnValue = false;
- }
-
final ArrayList<Button> returnButtons = 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);
returnButton.setSelection(name.isReturnValue());
name.setUserSetIsReference(name.isOutput());
- returnButton.setEnabled(hasNoPredefinedReturnValue);
+ returnButton.setEnabled(info.getMandatoryReturnVariable() == null);
returnButton.setBackground(table.getBackground());
returnButton.addSelectionListener(new SelectionListener() {
@Override
@@ -182,7 +177,7 @@ public class ChooserComposite extends Composite {
if (!info.isExtractExpression()) {
voidReturn = new Button(parent, SWT.CHECK | SWT.LEFT);
voidReturn.setText(Messages.ChooserComposite_NoReturnValue);
- voidReturn.setEnabled(hasNoPredefinedReturnValue);
+ voidReturn.setEnabled(info.getMandatoryReturnVariable() == null);
voidReturn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
@@ -213,9 +208,9 @@ public class ChooserComposite extends Composite {
column.setWidth(100);
}
- void onVisibilityOrReturnChange(List<NameInformation> name) {
+ void onVisibilityOrReturnChange(List<NameInformation> names) {
String variableUsedAfterBlock = null;
- for (NameInformation information : name) {
+ for (NameInformation information : names) {
if (information.isReferencedAfterSelection() &&
!(information.isUserSetIsReference() || information.isUserSetIsReturnValue())) {
variableUsedAfterBlock = information.getName().toString();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java
index b9ed2b854e..31cee12740 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
-import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
@@ -24,7 +23,6 @@ public class ExtractFunctionInformation {
private VisibilityEnum visibility = VisibilityEnum.v_private;
private String methodName;
private boolean replaceDuplicates;
- private List<NameInformation> namesUsedAfter;
private List<NameInformation> parameterCandidates;
private NameInformation mandatoryReturnVariable;
private NameInformation returnVariable;
@@ -62,23 +60,6 @@ public class ExtractFunctionInformation {
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() {
return returnVariable;
}
@@ -96,6 +77,7 @@ public class ExtractFunctionInformation {
public void setMandatoryReturnVariable(NameInformation variable) {
this.mandatoryReturnVariable = variable;
+ this.returnVariable = variable;
}
public List<NameInformation> getParameterCandidates() {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
index 58c69dc8ed..394474a1e0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
@@ -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.CPPASTTemplateDeclaration;
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.CRefactoringDescription;
@@ -109,7 +107,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
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 char[] ZERO= "0".toCharArray(); //$NON-NLS-1$
@@ -122,7 +121,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
final Container<Integer> trailPos;
private final Container<Integer> returnNumber;
- protected boolean hasNameResolvingForSimilarError = false;
+ protected boolean hasNameResolvingForSimilarError;
HashMap<String, Integer> nameTrail;
@@ -159,27 +158,24 @@ public class ExtractFunctionRefactoring extends CRefactoring {
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
+ if (container.isEmpty()) {
+ initStatus.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
+ sm.done();
+ return initStatus;
+ }
+
checkForNonExtractableStatements(container, initStatus);
sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
- markWriteAccess();
+ info.setParameterCandidates(container.getParameterCandidates());
sm.worked(1);
if (isProgressMonitorCanceld(sm, 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();
if (returnValueCandidates.size() > 1) {
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
@@ -194,19 +190,15 @@ public class ExtractFunctionRefactoring extends CRefactoring {
info.setExtractExpression(isExtractExpression);
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);
if (info.getMandatoryReturnVariable() != null) {
info.getMandatoryReturnVariable().setUserSetIsReturnValue(true);
}
- for (int i = 0; i < info.getParameterCandidates().size(); i++) {
- if (!info.getParameterCandidates().get(i).isDeclaredInSelection()) {
- NameInformation name = info.getParameterCandidates().get(i);
- if (!name.isReturnValue()) {
- name.setUserSetIsReference(name.isOutput());
- }
- }
+ for (NameInformation name : info.getParameterCandidates()) {
+ name.setUserSetIsReference(name.isOutput());
}
sm.done();
} finally {
@@ -218,15 +210,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
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) {
NonExtractableStmtFinder finder = new NonExtractableStmtFinder();
for (IASTNode node : cont.getNodesToWrite()) {
@@ -273,7 +256,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
finalConditions = super.checkFinalConditions(pm);
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()) {
ICPPASTCompositeTypeSpecifier classDeclaration =
@@ -307,8 +291,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
lockIndex();
try {
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());
// Create Declaration in Class
if (context.getType() == ContextType.METHOD && !context.isInline()) {
@@ -349,7 +333,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
firstNodeToWrite.getTranslationUnit());
TextEditGroup editGroup = new TextEditGroup(title);
if (methodCall instanceof IASTDeclaration){
- CPPASTDeclarationStatement declarationStatement = new CPPASTDeclarationStatement((IASTDeclaration) methodCall);
+ CPPASTDeclarationStatement declarationStatement =
+ new CPPASTDeclarationStatement((IASTDeclaration) methodCall);
methodCall = declarationStatement;
}
insertCallintoTree(methodCall, container.getNodesToWrite(), rewriter, editGroup);
@@ -386,7 +371,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
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();
}
return binExp;
@@ -503,7 +489,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
protected boolean isStatementInTrail(IASTStatement stmt, final List<IASTNode> trail, IIndex index) {
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() {
@Override
@@ -541,8 +528,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
private boolean isMethodAllreadyDefined(IASTSimpleDeclaration methodDeclaration,
ICPPASTCompositeTypeSpecifier classDeclaration, IIndex index) {
- TrailNodeEqualityChecker equalityChecker = new TrailNodeEqualityChecker(
- names, namesCounter, index);
+ TrailNodeEqualityChecker equalityChecker =
+ new TrailNodeEqualityChecker(names, namesCounter, index);
IBinding bind = classDeclaration.getName().resolveBinding();
IASTStandardFunctionDeclarator declarator =
@@ -589,7 +576,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
private void addMethod(IASTName astMethodName, MethodContext context, ASTRewrite rewriter,
- IASTNode insertpoint, TextEditGroup group) {
+ IASTNode insertPoint, TextEditGroup group) {
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
if (context.getType() == ContextType.METHOD) {
if (context.getMethodQName() != null) {
@@ -616,19 +603,19 @@ public class ExtractFunctionRefactoring extends CRefactoring {
func.setBody(compound);
ASTRewrite subRW;
- if (insertpoint.getParent() instanceof ICPPASTTemplateDeclaration) {
+ if (insertPoint.getParent() instanceof ICPPASTTemplateDeclaration) {
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
templateDeclaration.setParent(ast);
- for (ICPPASTTemplateParameter param : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) {
+ for (ICPPASTTemplateParameter param : ((ICPPASTTemplateDeclaration) insertPoint.getParent()).getTemplateParameters()) {
templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations));
}
templateDeclaration.setDeclaration(func);
- subRW = rewriter.insertBefore(insertpoint.getParent().getParent(), insertpoint.getParent(),
+ subRW = rewriter.insertBefore(insertPoint.getParent().getParent(), insertPoint.getParent(),
templateDeclaration, group);
} else {
- subRW = rewriter.insertBefore(insertpoint.getParent(), insertpoint, func, group);
+ subRW = rewriter.insertBefore(insertPoint.getParent(), insertPoint, func, group);
}
extractedFunctionConstructionHelper.constructMethodBody(compound,
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java
index 2e0dd7773c..cb9d3e2a09 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java
@@ -92,12 +92,10 @@ public abstract class ExtractedFunctionConstructionHelper {
}
public List<IASTParameterDeclaration> getParameterDeclarations(
- Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
- List<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>();
- for (NameInformation name : allUsedNames) {
- if (!name.isDeclaredInSelection()) {
- result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory));
- }
+ Collection<NameInformation> parameterNames, INodeFactory nodeFactory) {
+ List<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>(parameterNames.size());
+ for (NameInformation name : parameterNames) {
+ result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory));
}
return result;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/SimilarFinderVisitor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/SimilarFinderVisitor.java
index cd62fc2795..100ec096d4 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/SimilarFinderVisitor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/SimilarFinderVisitor.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@@ -63,7 +64,7 @@ final class SimilarFinderVisitor extends ASTVisitor {
if (statementCount == statements.size()) {
// Found similar code
boolean similarOnReturnWays = true;
- for (NameInformation nameInfo : similarContainer.getNamesUsedAfter()) {
+ for (NameInformation nameInfo : similarContainer.getParameterCandidates()) {
if (refactoring.names.containsKey(nameInfo.getDeclaration().getRawSignature())) {
Integer nameOrderNumber = refactoring.names.get(nameInfo.getDeclaration().getRawSignature());
if (refactoring.nameTrail.containsValue(nameOrderNumber)) {
@@ -72,12 +73,15 @@ final class SimilarFinderVisitor extends ASTVisitor {
for (Entry<String, Integer> entry : refactoring.nameTrail.entrySet()) {
if (entry.getValue().equals(nameOrderNumber)) {
orgName = entry.getKey();
+ break;
}
}
if (orgName != null) {
- for (NameInformation orgNameInfo : refactoring.container.getNamesUsedAfterChoosenByUser()) {
- if (orgName.equals(orgNameInfo.getDeclaration().getRawSignature())) {
+ for (NameInformation orgNameInfo : refactoring.container.getParameterCandidates()) {
+ if (orgName.equals(orgNameInfo.getDeclaration().getRawSignature()) &&
+ (orgNameInfo.isOutput() || !nameInfo.isOutput())) {
found = true;
+ break;
}
}
}
@@ -90,9 +94,8 @@ final class SimilarFinderVisitor extends ASTVisitor {
}
if (similarOnReturnWays) {
- IASTNode call = refactoring.getMethodCall(name,
- refactoring.nameTrail, refactoring.names,
- refactoring.container, similarContainer);
+ IASTNode call = refactoring.getMethodCall(name, refactoring.nameTrail,
+ refactoring.names, refactoring.container, similarContainer);
ASTRewrite rewrite =
collector.rewriterForTranslationUnit(stmtToReplace.get(0).getTranslationUnit());
TextEditGroup editGroup = new TextEditGroup(Messages.SimilarFinderVisitor_replaceDuplicateCode);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java
index 402c76fdbb..87f2d8f373 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java
@@ -135,7 +135,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
sm.worked(1);
- container.getNamesUsedAfter();
info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1);

Back to the top