mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Converted Extract Local Variable tests to the new framework.
This commit is contained in:
parent
476364f0a6
commit
546389bc1e
11 changed files with 546 additions and 737 deletions
|
@ -1,622 +0,0 @@
|
||||||
//!ExtractLocalVariableRefactoringTest int
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
return /*$*/42/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
int i = 42;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest char
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
return /*$*/'c'/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
char temp = 'c';
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest float
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
float foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
float foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
float A::foo() {
|
|
||||||
return /*$*/42.0f/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
float A::foo() {
|
|
||||||
float f = 42.0f;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest double
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
float foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
float foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
float A::foo() {
|
|
||||||
return /*$*/42.0/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
float A::foo() {
|
|
||||||
double f = 42.0;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest parentheses
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
return /*$*/(42)/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
int i = 42;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest proposed name in scope
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.h
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//=
|
|
||||||
#ifndef A_H_
|
|
||||||
#define A_H_
|
|
||||||
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A();
|
|
||||||
virtual ~A();
|
|
||||||
int foo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*A_H_*/
|
|
||||||
|
|
||||||
//@A.cpp
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
int x = 3;
|
|
||||||
return /*$*/(x + 2)/*$$*/ * 15;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
#include "A.h"
|
|
||||||
|
|
||||||
A::A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
A::~A() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int A::foo() {
|
|
||||||
int x = 3;
|
|
||||||
int i = x + 2;
|
|
||||||
return i * 15;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug #277065 extract local variable fails to extract from for loop
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
void foo() {
|
|
||||||
for (int n = /*$*/5 + 2/*$$*/; n < 10; ++n)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
void foo() {
|
|
||||||
int i = 5 + 2;
|
|
||||||
for (int n = i; n < 10; ++n)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest expression
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
void foo() {
|
|
||||||
int a = 0;
|
|
||||||
float b = 0.1f;
|
|
||||||
double c = /*$*/(a + b)/*$$*/ * 0.2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
void foo() {
|
|
||||||
int a = 0;
|
|
||||||
float b = 0.1f;
|
|
||||||
float a0 = a + b;
|
|
||||||
double c = a0 * 0.2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest pointer
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
void foo() {
|
|
||||||
int a[2];
|
|
||||||
int b = */*$*/(a + 1)/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
void foo() {
|
|
||||||
int a[2];
|
|
||||||
int* i = a + 1;
|
|
||||||
int b = *i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest qualifiers
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
const volatile int* k;
|
|
||||||
|
|
||||||
void foo() {
|
|
||||||
/*$*/k;/*$$*/
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
const volatile int* k;
|
|
||||||
|
|
||||||
void foo() {
|
|
||||||
const volatile int* k0 = k;
|
|
||||||
k0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!ExtractLocalVariableRefactoringTest overloaded operators
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
class K {
|
|
||||||
public:
|
|
||||||
bool operator+(int b) { return true; }
|
|
||||||
float operator+(unsigned u) { return 1.0f; }
|
|
||||||
};
|
|
||||||
void foo() {
|
|
||||||
K k;
|
|
||||||
/*$*/k+3u/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
class K {
|
|
||||||
public:
|
|
||||||
bool operator+(int b) { return true; }
|
|
||||||
float operator+(unsigned u) { return 1.0f; }
|
|
||||||
};
|
|
||||||
void foo() {
|
|
||||||
K k;
|
|
||||||
float i = k + 3u;
|
|
||||||
i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 318784 DeclarationGenerator fails for some cases
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
void func() {
|
|
||||||
int* (*a)[2];
|
|
||||||
/*$*/a/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
void func() {
|
|
||||||
int* (*a)[2];
|
|
||||||
int* (*a0)[2] = a;
|
|
||||||
a0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 331963 Extract local variable doesn't put template type parameters
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class Foo {
|
|
||||||
};
|
|
||||||
|
|
||||||
Foo<int> getFoo();
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
/*$*/getFoo()/*$$*/;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class Foo {
|
|
||||||
};
|
|
||||||
|
|
||||||
Foo<int> getFoo();
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Foo<int> foo = getFoo();
|
|
||||||
foo;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 331963 Extract local variable doesn't put template type parameters Namespace
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
namespace bar {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class Foo {
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bar::Foo<int> getFoo();
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
/*$*/getFoo()/*$$*/;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
namespace bar {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class Foo {
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bar::Foo<int> getFoo();
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
bar::Foo<int> foo = getFoo();
|
|
||||||
foo;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 330693 Improve suggested variable name in Extract Local Variable
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
int getVarWithLongName();
|
|
||||||
};
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
Foo f;
|
|
||||||
/*$*/f.getVarWithLongName()/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
int getVarWithLongName();
|
|
||||||
};
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
Foo f;
|
|
||||||
int varWithLongName = f.getVarWithLongName();
|
|
||||||
varWithLongName;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 330693 Improve suggested variable name in Extract Local Variable: name == prefix
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
int get();
|
|
||||||
};
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
Foo f;
|
|
||||||
/*$*/f.get()/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
int get();
|
|
||||||
};
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
Foo f;
|
|
||||||
int get = f.get();
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 335202 Suggested name is wrong for nested function calls - outer function call
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
int getA() {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
int getB(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
/*$*/getB(getA())/*$$*/;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
int getA() {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
int getB(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
int b = getB(getA());
|
|
||||||
b;
|
|
||||||
}
|
|
||||||
|
|
||||||
//!Bug 335202 Suggested name is wrong for nested function calls - inner function call
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
|
||||||
//@A.cpp
|
|
||||||
|
|
||||||
int getA() {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
int getB(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getC(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
getB(/*$*/getC(getA())/*$$*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
|
|
||||||
int getA() {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
int getB(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getC(int a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar() {
|
|
||||||
int c = getC(getA());
|
|
||||||
getB(c);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
//!extract local variable from for loop
|
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
|
||||||
//@main.cpp
|
|
||||||
void foo() {
|
|
||||||
for (int n = 5 + 2; n < 10; ++n)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
//=
|
|
||||||
void foo() {
|
|
||||||
int i = 5 + 2;
|
|
||||||
for (int n = i; n < 10; ++n)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
//@refScript.xml
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<session version="1.0">
|
|
||||||
<refactoring comment="Extract 5 + 2" description="Extract Local Variable Refactoring"
|
|
||||||
fileName="file:$$projectPath$$/main.cpp" flags="4"
|
|
||||||
id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"
|
|
||||||
name="i" project="RegressionTestProject" selection="27,5"/>
|
|
||||||
</session>
|
|
|
@ -18,7 +18,7 @@ import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest;
|
import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest;
|
import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableTestSuite;
|
import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest;
|
import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodTestSuite;
|
import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodTestSuite;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodTestSuite;
|
import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodTestSuite;
|
||||||
|
@ -40,7 +40,7 @@ public class RefactoringTestSuite extends TestSuite {
|
||||||
suite.addTest(HideMethodTestSuite.suite());
|
suite.addTest(HideMethodTestSuite.suite());
|
||||||
suite.addTest(GenerateGettersAndSettersTest.suite());
|
suite.addTest(GenerateGettersAndSettersTest.suite());
|
||||||
suite.addTest(ImplementMethodTestSuite.suite());
|
suite.addTest(ImplementMethodTestSuite.suite());
|
||||||
suite.addTest(ExtractLocalVariableTestSuite.suite());
|
suite.addTest(ExtractLocalVariableRefactoringTest.suite());
|
||||||
suite.addTest(ToogleRefactoringTest.suite());
|
suite.addTest(ToogleRefactoringTest.suite());
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,48 +7,537 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Tom Ball (Google) - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
|
package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import junit.framework.Test;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
|
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring;
|
import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test harness for Extract Local Variable refactoring tests.
|
* Tests for Extract Local Variable refactoring.
|
||||||
*
|
|
||||||
* @author Tom Ball
|
|
||||||
*/
|
*/
|
||||||
public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
|
public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
|
||||||
protected String variableName;
|
private String extractedVariableName;
|
||||||
|
private ExtractLocalVariableRefactoring refactoring;
|
||||||
|
|
||||||
public ExtractLocalVariableRefactoringTest(String name, Collection<TestSourceFile> files) {
|
public ExtractLocalVariableRefactoringTest() {
|
||||||
super(name, files);
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtractLocalVariableRefactoringTest(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return suite(ExtractLocalVariableRefactoringTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void runTest() throws Throwable {
|
protected Refactoring createRefactoring() {
|
||||||
IFile file = project.getFile(fileName);
|
refactoring = new ExtractLocalVariableRefactoring(getSelectedTranslationUnit(),
|
||||||
ICElement element = CoreModel.getDefault().create(file);
|
getSelection(), getCProject());
|
||||||
ExtractLocalVariableRefactoring refactoring =
|
return refactoring;
|
||||||
new ExtractLocalVariableRefactoring(element, selection, cproject);
|
|
||||||
refactoring.getRefactoringInfo().setName(variableName);
|
|
||||||
executeRefactoring(refactoring);
|
|
||||||
compareFiles(fileMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureRefactoring(Properties refactoringProperties) {
|
protected void simulateUserInput() {
|
||||||
variableName = refactoringProperties.getProperty("variablename", "temp"); //$NON-NLS-1$ //$NON-NLS-2$
|
if (extractedVariableName != null)
|
||||||
|
refactoring.getRefactoringInfo().setName(extractedVariableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//int foo() {
|
||||||
|
// return /*$*/42/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//int foo() {
|
||||||
|
// int i = 42;
|
||||||
|
// return i;
|
||||||
|
//}
|
||||||
|
public void testIntLiteral() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//int foo() {
|
||||||
|
// return /*$*/'c'/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//int foo() {
|
||||||
|
// char c = 'c';
|
||||||
|
// return c;
|
||||||
|
//}
|
||||||
|
public void testCharLiteral() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//const char* foo() {
|
||||||
|
// return /*$*/"Hello World!"/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//const char* foo() {
|
||||||
|
// const char* helloWorld = "Hello World!";
|
||||||
|
// return helloWorld;
|
||||||
|
//}
|
||||||
|
public void testStringLiteral() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//double foo() {
|
||||||
|
// return /*$*/42.0f/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//double foo() {
|
||||||
|
// float f = 42.0f;
|
||||||
|
// return f;
|
||||||
|
//}
|
||||||
|
public void testFloatLiteral() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//double foo() {
|
||||||
|
// return /*$*/42./*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//double foo() {
|
||||||
|
// double f = 42.;
|
||||||
|
// return f;
|
||||||
|
//}
|
||||||
|
public void testDoubleLiteral() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.h
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//====================
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//A::A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//A::~A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int A::foo() {
|
||||||
|
// return /*$*/(42)/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//A::A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//A::~A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int A::foo() {
|
||||||
|
// int i = 42;
|
||||||
|
// return i;
|
||||||
|
//}
|
||||||
|
public void testParentheses() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.h
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//====================
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//A::A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//A::~A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int A::foo() {
|
||||||
|
// int x = 3;
|
||||||
|
// return /*$*/(x + 2)/*$$*/ * 15;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//A::A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//A::~A() {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int A::foo() {
|
||||||
|
// int x = 3;
|
||||||
|
// int i = x + 2;
|
||||||
|
// return i * 15;
|
||||||
|
//}
|
||||||
|
public void testSuggestedNameInScope() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//void foo() {
|
||||||
|
// for (int n = /*$*/5 + 2/*$$*/; n < 10; ++n)
|
||||||
|
// ;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void foo() {
|
||||||
|
// int i = 5 + 2;
|
||||||
|
// for (int n = i; n < 10; ++n)
|
||||||
|
// ;
|
||||||
|
//}
|
||||||
|
public void testForStatement_Bug277065() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//void foo() {
|
||||||
|
// int a = 0;
|
||||||
|
// float b = 0.1f;
|
||||||
|
// double c = /*$*/(a + b)/*$$*/ * 0.2;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void foo() {
|
||||||
|
// int a = 0;
|
||||||
|
// float b = 0.1f;
|
||||||
|
// float a0 = a + b;
|
||||||
|
// double c = a0 * 0.2;
|
||||||
|
//}
|
||||||
|
public void testExpression() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//void foo() {
|
||||||
|
// int a[2];
|
||||||
|
// int b = */*$*/(a + 1)/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void foo() {
|
||||||
|
// int a[2];
|
||||||
|
// int* i = a + 1;
|
||||||
|
// int b = *i;
|
||||||
|
//}
|
||||||
|
public void testPointer() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//const volatile int* k;
|
||||||
|
//
|
||||||
|
//void foo() {
|
||||||
|
// /*$*/k;/*$$*/
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//const volatile int* k;
|
||||||
|
//
|
||||||
|
//void foo() {
|
||||||
|
// const volatile int* k0 = k;
|
||||||
|
// k0;
|
||||||
|
//}
|
||||||
|
public void testQualifiers() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//class K {
|
||||||
|
//public:
|
||||||
|
// bool operator+(int b) { return true; }
|
||||||
|
// float operator+(unsigned u) { return 1.0f; }
|
||||||
|
//};
|
||||||
|
//void foo() {
|
||||||
|
// K k;
|
||||||
|
// /*$*/k+3u/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//class K {
|
||||||
|
//public:
|
||||||
|
// bool operator+(int b) { return true; }
|
||||||
|
// float operator+(unsigned u) { return 1.0f; }
|
||||||
|
//};
|
||||||
|
//void foo() {
|
||||||
|
// K k;
|
||||||
|
// float i = k + 3u;
|
||||||
|
// i;
|
||||||
|
//}
|
||||||
|
public void testOverloadedOperators() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//void func() {
|
||||||
|
// int* (*a)[2];
|
||||||
|
// /*$*/a/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//void func() {
|
||||||
|
// int* (*a)[2];
|
||||||
|
// int* (*a0)[2] = a;
|
||||||
|
// a0;
|
||||||
|
//}
|
||||||
|
public void testArrayOfFunctionPointers_Bug318784() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//template<class T>
|
||||||
|
//class Foo {
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//Foo<int> getFoo();
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// /*$*/getFoo()/*$$*/;
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//template<class T>
|
||||||
|
//class Foo {
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//Foo<int> getFoo();
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// Foo<int> foo = getFoo();
|
||||||
|
// foo;
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
public void testTemplateTypeParameters_Bug331963() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//namespace bar {
|
||||||
|
//
|
||||||
|
//template<class T>
|
||||||
|
//class Foo {
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//bar::Foo<int> getFoo();
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// /*$*/getFoo()/*$$*/;
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//namespace bar {
|
||||||
|
//
|
||||||
|
//template<class T>
|
||||||
|
//class Foo {
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//bar::Foo<int> getFoo();
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// bar::Foo<int> foo = getFoo();
|
||||||
|
// foo;
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
public void testTemplateTypeParametersWithNamespace_Bug331963() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//struct Foo {
|
||||||
|
// int getVarWithLongName();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// Foo f;
|
||||||
|
// /*$*/f.getVarWithLongName()/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//struct Foo {
|
||||||
|
// int getVarWithLongName();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// Foo f;
|
||||||
|
// int varWithLongName = f.getVarWithLongName();
|
||||||
|
// varWithLongName;
|
||||||
|
//}
|
||||||
|
public void testSuggestedName_Bug330693_1() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//struct Foo {
|
||||||
|
// int get();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// Foo f;
|
||||||
|
// /*$*/f.get()/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//struct Foo {
|
||||||
|
// int get();
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// Foo f;
|
||||||
|
// int get = f.get();
|
||||||
|
// get;
|
||||||
|
//}
|
||||||
|
public void testSuggestedName_Bug330693_2() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//int getA() {
|
||||||
|
// return 0;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//int getB(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// /*$*/getB(getA())/*$$*/;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//int getA() {
|
||||||
|
// return 0;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//int getB(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// int b = getB(getA());
|
||||||
|
// b;
|
||||||
|
//}
|
||||||
|
public void testSuggestedName_Bug335202_1() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.cpp
|
||||||
|
//
|
||||||
|
//int getA() {
|
||||||
|
// return 0;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//int getB(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int getC(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// getB(/*$*/getC(getA())/*$$*/);
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//
|
||||||
|
//int getA() {
|
||||||
|
// return 0;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//int getB(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int getC(int a) {
|
||||||
|
// return a;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void bar() {
|
||||||
|
// int c = getC(getA());
|
||||||
|
// getB(c);
|
||||||
|
//}
|
||||||
|
public void testSuggestedName_Bug335202_2() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//main.cpp
|
||||||
|
//void foo() {
|
||||||
|
// for (int n = 5 + 2; n < 10; ++n)
|
||||||
|
// ;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void foo() {
|
||||||
|
// int i = 5 + 2;
|
||||||
|
// for (int n = i; n < 10; ++n)
|
||||||
|
// ;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//refScript.xml
|
||||||
|
//<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
//<session version="1.0">
|
||||||
|
//<refactoring comment="Extract 5 + 2" description="Extract Local Variable Refactoring"
|
||||||
|
// fileName="file:${projectPath}/main.cpp" flags="4"
|
||||||
|
// id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"
|
||||||
|
// name="i" project="RegressionTestProject" selection="27,5"/>
|
||||||
|
//</session>
|
||||||
|
public void testLocalVariableFromForLoop() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences and others
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test suite to run just the Extract Local Variable unit tests.
|
|
||||||
*
|
|
||||||
* @author Tom Ball
|
|
||||||
*/
|
|
||||||
public class ExtractLocalVariableTestSuite extends TestSuite {
|
|
||||||
@SuppressWarnings("nls")
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
TestSuite suite = new ExtractLocalVariableTestSuite();
|
|
||||||
suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringTests",
|
|
||||||
"resources/refactoring/ExtractLocalVariable.rts"));
|
|
||||||
suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringHistoryTests",
|
|
||||||
"resources/refactoring/ExtractLocalVariableHistory.rts"));
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -8,17 +8,19 @@
|
||||||
*
|
*
|
||||||
* 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.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associate a name with a visibility and holds a list of used names.
|
* Associate a name with a visibility and holds a list of used names.
|
||||||
*/
|
*/
|
||||||
public class NameNVisibilityInformation {
|
public class NameAndVisibilityInformation {
|
||||||
private String name = ""; //$NON-NLS-1$
|
private String name = ""; //$NON-NLS-1$
|
||||||
private VisibilityEnum visibility = VisibilityEnum.v_public;
|
private VisibilityEnum visibility = VisibilityEnum.v_public;
|
||||||
private final ArrayList<String> usedNames = new ArrayList<String>();
|
private final ArrayList<String> usedNames = new ArrayList<String>();
|
||||||
|
@ -39,7 +41,7 @@ public class NameNVisibilityInformation {
|
||||||
this.visibility = visibility;
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUsedNames(){
|
public List<String> getUsedNames(){
|
||||||
return usedNames;
|
return usedNames;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.swt.widgets.Button;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
|
@ -37,11 +37,11 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
public abstract class ExtractInputPage extends UserInputWizardPage {
|
public abstract class ExtractInputPage extends UserInputWizardPage {
|
||||||
|
|
||||||
protected NameAndVisibilityComposite control;
|
protected NameAndVisibilityComposite control;
|
||||||
protected NameNVisibilityInformation info;
|
protected NameAndVisibilityInformation info;
|
||||||
protected String label = Messages.ExtractInputPage_ReplaceInSubclass;
|
protected String label = Messages.ExtractInputPage_ReplaceInSubclass;
|
||||||
protected String errorLabel = Messages.ExtractInputPage_EnterName;
|
protected String errorLabel = Messages.ExtractInputPage_EnterName;
|
||||||
|
|
||||||
public ExtractInputPage(String name, NameNVisibilityInformation info) {
|
public ExtractInputPage(String name, NameAndVisibilityInformation info) {
|
||||||
super(name);
|
super(name);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emanuel Graf IFS
|
* @author Emanuel Graf IFS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ExtractConstantInfo extends NameNVisibilityInformation{
|
public class ExtractConstantInfo extends NameAndVisibilityInformation{
|
||||||
|
|
||||||
private MethodContext mContext;
|
private MethodContext mContext;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -8,27 +8,27 @@
|
||||||
*
|
*
|
||||||
* 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.extractconstant;
|
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage;
|
import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage;
|
||||||
|
|
||||||
public class InputPage extends ExtractInputPage {
|
public class InputPage extends ExtractInputPage {
|
||||||
|
private final List<String> usedNames;
|
||||||
private final ArrayList<String> usedNames;
|
|
||||||
private boolean showVisibilityPane;
|
private boolean showVisibilityPane;
|
||||||
|
|
||||||
public InputPage(String name, NameNVisibilityInformation info) {
|
public InputPage(String name, NameAndVisibilityInformation info) {
|
||||||
this(name, info, true);
|
this(name, info, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputPage(String name, NameNVisibilityInformation info, boolean showVisibilityPane) {
|
public InputPage(String name, NameAndVisibilityInformation info, boolean showVisibilityPane) {
|
||||||
super(name, info);
|
super(name, info);
|
||||||
label = Messages.InputPage_ConstName;
|
label = Messages.InputPage_ConstName;
|
||||||
errorLabel = Messages.InputPage_EnterContName;
|
errorLabel = Messages.InputPage_EnterContName;
|
||||||
|
@ -36,8 +36,6 @@ public class InputPage extends ExtractInputPage {
|
||||||
this.showVisibilityPane = showVisibilityPane;
|
this.showVisibilityPane = showVisibilityPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
super.createControl(parent);
|
super.createControl(parent);
|
||||||
|
|
|
@ -68,9 +68,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NodeContainer;
|
import org.eclipse.cdt.internal.ui.refactoring.NodeContainer;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
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;
|
||||||
|
@ -88,12 +88,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 {
|
||||||
"org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$
|
"org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$
|
||||||
|
|
||||||
private IASTExpression target;
|
private IASTExpression target;
|
||||||
private final NameNVisibilityInformation info;
|
private final NameAndVisibilityInformation info;
|
||||||
private NodeContainer container;
|
private NodeContainer container;
|
||||||
|
|
||||||
public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) {
|
public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) {
|
||||||
super(element, selection, project);
|
super(element, selection, project);
|
||||||
info = new NameNVisibilityInformation();
|
info = new NameAndVisibilityInformation();
|
||||||
name = Messages.ExtractLocalVariable;
|
name = Messages.ExtractLocalVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,10 +383,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 {
|
||||||
if (expression instanceof CPPASTLiteralExpression) {
|
if (expression instanceof CPPASTLiteralExpression) {
|
||||||
CPPASTLiteralExpression literal = (CPPASTLiteralExpression) expression;
|
CPPASTLiteralExpression literal = (CPPASTLiteralExpression) expression;
|
||||||
String name = null;
|
String name = null;
|
||||||
char[] value = literal.getValue();
|
|
||||||
switch (literal.getKind()) {
|
switch (literal.getKind()) {
|
||||||
case IASTLiteralExpression.lk_char_constant:
|
case IASTLiteralExpression.lk_char_constant:
|
||||||
name = Character.toString(value[0]);
|
name = "c"; //$NON-NLS-1$
|
||||||
break;
|
break;
|
||||||
case IASTLiteralExpression.lk_float_constant:
|
case IASTLiteralExpression.lk_float_constant:
|
||||||
name = "f"; //$NON-NLS-1$
|
name = "f"; //$NON-NLS-1$
|
||||||
|
@ -511,13 +510,13 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 {
|
||||||
|
|
||||||
private Map<String, String> getArgumentMap() {
|
private Map<String, String> getArgumentMap() {
|
||||||
Map<String, String> arguments = new HashMap<String, String>();
|
Map<String, String> arguments = new HashMap<String, String>();
|
||||||
arguments.put(CRefactoringDescription.FILE_NAME, tu.getLocationURI().toString());
|
arguments.put(CRefactoringDescriptor.FILE_NAME, tu.getLocationURI().toString());
|
||||||
arguments.put(CRefactoringDescription.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$
|
arguments.put(CRefactoringDescriptor.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$
|
||||||
arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName());
|
arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName());
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NameNVisibilityInformation getRefactoringInfo() {
|
public NameAndVisibilityInformation getRefactoringInfo() {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.dialogs.LabeledTextField;
|
import org.eclipse.cdt.internal.ui.refactoring.dialogs.LabeledTextField;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||||
|
@ -35,10 +35,10 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||||
*/
|
*/
|
||||||
public class InputPage extends UserInputWizardPage {
|
public class InputPage extends UserInputWizardPage {
|
||||||
private String label = Messages.VariableName;
|
private String label = Messages.VariableName;
|
||||||
private final NameNVisibilityInformation info;
|
private final NameAndVisibilityInformation info;
|
||||||
private InputForm control;
|
private InputForm control;
|
||||||
|
|
||||||
public InputPage(String name, NameNVisibilityInformation info) {
|
public InputPage(String name, NameAndVisibilityInformation info) {
|
||||||
super(name);
|
super(name);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue