1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

Bug 347712 - Use shared AST in ExtractLocalVariableRefactoring.

This commit is contained in:
Sergey Prigogin 2012-02-15 15:41:26 -08:00
parent 7ce1c8fa8b
commit 3453fa6fcd
72 changed files with 5993 additions and 5935 deletions

View file

@ -395,7 +395,8 @@ public class StatementWriter extends NodeWriter {
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
return compoundStatement.getStatements();
}
// TODO(sprigogin): Rename second parameter
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
if (statement instanceof IASTCompoundStatement) {
//TODO hsr existiert noch eine methode

View file

@ -590,6 +590,10 @@ public class ChangeGenerator extends ASTVisitor {
}
}
newNode.accept(writer);
// TODO(sprigogin): Temporary workaround for invalid handling of line breaks in StatementWriter
if (!writer.toString().endsWith("\n")) //$NON-NLS-1$
writer.newLine();
}
if (prevNode != null) {
IASTNode nextNode = getNextSiblingOrPreprocessorNode(prevNode);

View file

@ -1,518 +0,0 @@
//!ExtractConstantInt
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
static const int theAnswer = 42;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
return /*$*/42/*$$*/; //Hello
}
void A::bar() {
int a = 42;
int b = 42;
}
//=
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
return theAnswer; //Hello
}
void A::bar() {
int a = theAnswer;
int b = theAnswer;
}
//!ExtractConstantInt 2
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
static const int theAnswer = 42;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
//Hallo
return /*$*/42/*$$*/;
}
void A::bar() {
int a = 42;
int b = 42;
}
//=
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
//Hallo
return theAnswer;
}
void A::bar() {
int a = theAnswer;
int b = theAnswer;
}
//!ExtractConstantFloat
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
float foo();
void bar();
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
float foo();
void bar();
static const float theAnswer = 42.0f;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
float A::foo() {
return /*$*/42.0f/*$$*/;
}
void A::bar() {
float a = 42.0f;
float b = 42.0f;
}
//=
#include "A.h"
A::A() {
}
A::~A() {
}
float A::foo() {
return theAnswer;
}
void A::bar() {
float a = theAnswer;
float b = theAnswer;
}
//!ExtractConstantDouble
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
double foo();
void bar();
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
double foo();
void bar();
static const double theAnswer = 42.0;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
double A::foo() {
return /*$*/42.0/*$$*/;
}
void A::bar() {
double a = 42.0;
double b = 42.0;
}
//=
#include "A.h"
A::A() {
}
A::~A() {
}
double A::foo() {
return theAnswer;
}
void A::bar() {
double a = theAnswer;
double b = theAnswer;
}
//!ExtractConstantStaticInt
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
static const int a = 42;
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
static const int a = 42;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
return 42;
}
int bar() {
return /*$*/42/*$$*/;
}
//=
#include "A.h"
namespace {
const int theAnswer = 42;
}
A::A() {
}
A::~A() {
}
int A::foo() {
return theAnswer;
}
int bar() {
return theAnswer;
}
//!replaceNumberProtected
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
visibility=protected
//@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();
protected:
static const int theAnswer = 42;
};
#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() {
return theAnswer;
}
//!replaceNumberPrivate
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
visibility=private
//@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();
private:
static const int theAnswer = 42;
};
#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() {
return theAnswer;
}
//!Bug 246062 - Extracting a constant from an inlined method
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
filename=A.h
//@A.h
class X {
void method() {
int a = /*$*/42/*$$*/;
}
};
//=
class X {
public:
static const int theAnswer = 42;
private:
void method() {
int a = theAnswer;
}
};
//!Extract constant string
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
visibility=private
filename=A.h
//@A.h
class X {
void method() {
char* a = /*$*/"sometext"/*$$*/;
}
void method2() {
const char* b = "sometext";
}
};
//=
class X {
void method() {
char* a = theAnswer;
}
void method2() {
const char* b = theAnswer;
}
static const char* theAnswer = "sometext";
};
//!ExtractConstantWideString
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config
visibility=private
filename=A.h
//@A.h
class X {
void method() {
wchar_t* a = /*$*/L"sometext"/*$$*/;
}
void method2() {
const wchar_t* b = L"sometext";
const char* c = "sometext";
}
};
//=
class X {
void method() {
wchar_t* a = theAnswer;
}
void method2() {
const wchar_t* b = theAnswer;
const char* c = "sometext";
}
static const wchar_t* theAnswer = L"sometext";
};

View file

@ -1,197 +0,0 @@
//!ExtractConstantInt
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@A.h
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
class A {
public:
A();
virtual ~A();
int foo();
void bar();
static const int theAnswer = 42;
};
#endif /*A_H_*/
//@A.cpp
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
return 42; // Hello
}
void A::bar() {
int a = 42;
int b = 42;
}
//=
#include "A.h"
A::A() {
}
A::~A() {
}
int A::foo() {
return theAnswer; // Hello
}
void A::bar() {
int a = theAnswer;
int b = theAnswer;
}
//@refScript.xml
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
fileName="file:$$projectPath$$/A.cpp" flags="4"
id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="theAnswer"
project="RegressionTestProject" selection="64,2" visibility="public"/>
</session>
//!replaceNumberProtected
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@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();
protected:
static const int theAnswer = 42;
};
#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() {
return theAnswer;
}
//@refScript.xml
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
fileName="file:$$projectPath$$/A.cpp" flags="4"
id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="theAnswer"
project="RegressionTestProject" selection="64,2" visibility="protected"/>
</session>
//!replaceNumberPrivate
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@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();
private:
static const int theAnswer = 42;
};
#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() {
return theAnswer;
}
//@refScript.xml
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
fileName="file:$$projectPath$$/A.cpp" flags="4"
id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="theAnswer"
project="RegressionTestProject" selection="64,2" visibility="private"/>
</session>

View file

@ -1361,7 +1361,7 @@ private:
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config
filename=A.cpp
fatalerrors=1
fatalerror=true
//@A.cpp
int /*$*/main/*$$*/() {
int i = 2;

View file

@ -1,44 +0,0 @@
//!FreeFunctionFromHeaderToImpl
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
newfilecreation=true
newfiles=A.cpp
//@A.h
void /*$*/freefunction/*$$*/() {
return;
}
//=
void freefunction();
//@A.cpp
//=
#include "A.h"
void freefunction() {
return;
}
//!FreeFunctionFromImplToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
newfilecreation=true
newfiles=A.h
//@A.cpp
void /*$*/freefunction/*$$*/() {
return;
}
//=
#include "A.h"
//@A.h
//=
void freefunction() {
return;
}

View file

@ -1,186 +0,0 @@
//!ClassToHeaderBodyComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/() {
// return comment
return;
}
};
//=
class A {
void member();
};
inline void A::member() {
// return comment
return;
}
//!ClassToHeaderTopCommentOrder
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
// First Top Comment
// Second Top Comment
void /*$*/member/*$$*/() {
return;
}
};
//=
class A {
// First Top Comment
// Second Top Comment
void member();
};
inline void A::member() {
return;
}
//!ClassToHeaderCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/() try
{
return;
}
catch (int i) {
// catch comment
}
};
//=
class A {
void member();
};
inline void A::member()
try {
return;
}
catch (int i) {
// catch comment
}
//!ClassToHeaderTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
// Top comment
void /*$*/member/*$$*/() {
return;
}
};
//=
class A {
// Top comment
void member();
};
inline void A::member() {
return;
}
//!ClassToHeaderTemplateTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
// Top comment
template<typename T>
T /*$*/member/*$$*/() {
return T();
}
};
//=
class A {
// Top comment
template<typename T>
T member();
};
// Top comment
template<typename T>
inline T A::member() {
return T();
}
//!ClassToHeaderTrailingComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/() {
return;
} // Trailing comment
};
//=
class A {
void member();
};
inline void A::member() {
return;
} // Trailing comment
//!ClassToHeaderTrailingCommentWithTryBlock
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/()
try {
return;
}
catch (int e) {
} // Trailing comment
};
//=
class A {
void member();
};
inline void A::member()
try {
return;
}
catch (int e) {
}
// Trailing comment
//!ClassToHeaderTrailingMultipleCommentsInTryBlock
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
int /*$*/member/*$$*/()
try {
// aans
} /* one */ catch (int i) {
// zwaa
} /* two */ catch (int j) {
// draa
} /* three */
};
//=
class A {
int member();
};
inline int A::member()
try {
// aans
} /* one */
catch (int i) {
// zwaa
}
/* two */catch (int j) {
// draa
}
/* three */

View file

@ -1,141 +0,0 @@
//!HeaderToClassBodyComment1
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T>
class A {
T /*$*/member/*$$*/();
};
template<typename T>
inline T A<T>::member() {
// body comment
return T();
}
//=
template<typename T>
class A {
T member() {
// body comment
return T();
}
};
//!HeaderToClassRetainTopComments
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T>
class A {
// First comment
// Second comment
T /*$*/member/*$$*/();
};
// Third comment
// Fourth comment
template<typename T>
inline T A<T>::member() {
return T();
}
//=
template<typename T>
class A {
// First comment
// Second comment
// Third comment
// Fourth comment
T member() {
return T();
}
};
//!HeaderToClassTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T>
class A {
T /*$*/member/*$$*/();
};
template<typename T>
inline T A<T>::member()
try {
// body comment
return T();
}
catch (int e) {
// Catch 1
}
catch (int e) {
// Catch 2
}
//=
template<typename T>
class A {
T member()
try {
// body comment
return T();
}
catch (int e) {
// Catch 1
}
catch (int e) {
// Catch 2
}
};
//!HeaderToClassMultiTemplateComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename S, typename T>
class A {
// Top Comment
template<typename U, typename V>
T /*$*/member/*$$*/();
};
// 2nd Top Comment
template<typename S, typename T>
template<typename U, typename V>
inline T A<S, T>::member() {
// body comment
return T();
}
//=
template<typename S, typename T>
class A {
// Top Comment
template<typename U, typename V>
T member() {
// body comment
return T();
}
};
//!HeaderToClassBodyComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T>
class A {
T /*$*/member/*$$*/();
};
// Top comment
template<typename T>
inline T A<T>::member() {
return T();
}
//=
template<typename T>
class A {
// Top comment
T member() {
return T();
}
};

View file

@ -1,109 +0,0 @@
//!HeaderToImplBodyComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/();
};
inline void A::member() {
// body comment
return;
}
//=
class A {
void member();
};
//@A.cpp
#include "A.h"
//=
#include "A.h"
void A::member() {
// body comment
return;
}
//!HeaderToImplTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/();
};
inline void A::member() try {
// body comment
return;
} catch /*1*/ (int e) { /*2*/ }
catch /*3*/ (int e) { /*4*/ }
//=
class A {
void member();
};
//@A.cpp
#include "A.h"
//=
#include "A.h"
void A::member()
try {
// body comment
return;
}
catch (/*1*/int e) {
/*2*/
}
catch (/*3*/int e) {
/*4*/
}
//!HeaderToImplTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void /*$*/member/*$$*/();
};
// Top comment
inline void A::member() {
// body comment
return;
}
//=
class A {
void member();
};
//@A.cpp
#include "A.h"
//=
#include "A.h"
// Top comment
void A::member() {
// body comment
return;
}
//!HeaderToImplFreeFuncTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
// Definition comment
void /*$*/member/*$$*/() {
return;
}
//=
// Definition comment
void member();
//@A.cpp
#include "A.h"
//=
#include "A.h"
// Definition comment
void member() {
return;
}

View file

@ -1,121 +0,0 @@
//!ImplToHeaderBodyComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
void A::/*$*/member/*$$*/() {
// body comment
return;
}
//=
#include "A.h"
//@A.h
class A {
void member();
};
//=
class A {
void member() {
// body comment
return;
}
};
//!ImplToHeaderTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
// Definition comment
void A::/*$*/member/*$$*/() {
return;
}
//=
#include "A.h"
//@A.h
class A {
void member();
};
//=
class A {
// Definition comment
void member() {
return;
}
};
//!ImplToHeaderTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
// Definition comment
void A::/*$*/member/*$$*/() try {
return;
} /*1*/ catch (int e) { /*2*/ } /*3*/ catch (int e) { /*4*/ }
//=
#include "A.h"
//@A.h
class A {
void member();
};
//=
class A {
// Definition comment
void member()
try {
return;
} /*1*/
catch (int e) {
/*2*/
}
/*3*/catch (int e) {
/*4*/
}
};
//!ImplToHeaderBodyCommentWithoutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
void /*$*/member/*$$*/() {
// body comment
return;
}
//=
#include "A.h"
//@A.h
//=
void member() {
// body comment
return;
}
//!ImplToHeaderTopCommentWithoutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
// Top comment
void /*$*/member/*$$*/() {
// body comment
return;
}
//=
#include "A.h"
//@A.h
//=
// Top comment
void member() {
// body comment
return;
}

View file

@ -1,242 +0,0 @@
//!TestConstructorToggleInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
/*$*/A/*$$*/(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y);
~A() {
}
};
inline A::A(int x, int y) :
a(x), b(y) {
}
//!TestConstructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y);
~A() {
}
};
inline A::/*$*/A/*$$*/(int x, int y) :
a(x), b(y) {
}
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y);
~A() {
}
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
A::A(int x, int y) :
a(x), b(y) {
}
//!TestConstructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
A::/*$*/A/*$$*/(int x, int y) :
a(x), b(y) {
}
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
A(int x, int y);
~A() {
}
};
//=
#include <iostream>
class A {
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
//!TestDestructorToggleInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
/*$*/~A/*$$*/() {
}
};
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
~A();
};
inline A::~A() {
}
//!TestDestructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
~A();
};
inline /*$*/A::~A/*$$*/() {
}
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
~A();
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
A::~A() {
}
//!TestDestructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
/*$*/A::~A/*$$*/() {
int x;
int y;
return;
}
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
A(int x, int y) :
a(x), b(y) {
}
~A();
};
//=
#include <iostream>
class A {
A(int x, int y) :
a(x), b(y) {
}
~A() {
int x;
int y;
return;
}
};

View file

@ -1,92 +0,0 @@
//!TestDefaultParameterInitializerInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
void /*$*/member/*$$*/(int a = 0, int b = 0) {
return;
}
};
//=
#include <iostream>
class A {
void member(int a = 0, int b = 0);
};
inline void A::member(int a, int b) {
return;
}
//!TestDefaultParameterInitializerInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
void member(int a = 0, int b = 0);
};
inline void /*$*/A::member/*$$*/(int a, int b) {
return;
}
//=
#include <iostream>
class A {
void member(int a = 0, int b = 0);
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
void A::member(int a, int b) {
return;
}
//!TestDefaultParameterInitializerInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
void A::/*$*/member/*$$*/(int a, int b) {
return;
}
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
void member(int a = 0, int b = 0);
};
//=
#include <iostream>
class A {
void member(int a = 0, int b = 0) {
return;
}
};

View file

@ -1,90 +0,0 @@
//!TestImplementationToClassWithDefintionSelected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
int main() {
return 0;
}
void N::A::/*$*/foo/*$$*/() {
return;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo() {
return;
}
};
}
//!TestImplementationToClassWithDeclarationSelected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void /*$*/foo/*$$*/();
};
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo() {
return;
}
};
}
//@A.cpp
#include "A.h"
int main() {
return 0;
}
void N::A::foo() {
return;
}
//=
#include "A.h"
int main() {
return 0;
}

View file

@ -1,105 +0,0 @@
//!TestNotSupportedVariableSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
fatalerror=true
//@A.h
#include <iostream>
class A {
public:
void foo() {
}
private:
int /*$*/x/*$$*/;
};
//!TestNotSupportedNoDefinition
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
fatalerror=true
//@A.h
#include <iostream>
class A {
public:
void /*$*/foo/*$$*/();
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//!TestNotSupportedNoTranslationunit
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
fatalerror=true
//@A.h
#include <iostream>
class A {
public:
void /*$*/foo/*$$*/();
};
//!TestMultipleDeclarations
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
fatalerror=true
//@A.h
#include <iostream>
class A {
void /*$*/foo/*$$*/();
void foo();
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//!TestMultipledefinitions
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
fatalerror=true
//@A.h
#include <iostream>
class A {
void foo();
void /*$*/foo/*$$*/() {
return;
}
};
void blah() {
}
inline void A::foo() {
return;
}
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//!TestNotSupportedNestedFunctions
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
fatalerror=true
//@A.h
#include <iostream>
class A {
void foo() {
void /*$*/bar/*$$*/() {
}
}
};

View file

@ -1,260 +0,0 @@
//!TestFreeFunctionToggleFromHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
int /*$*/freeFunction/*$$*/(int* a, int& b) {
return 42;
}
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
int freeFunction(int* a, int& b);
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
int freeFunction(int* a, int& b) {
return 42;
}
//!TestFreeFunctionToggleFromImplementationToHeaderWithDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
int main() {
return 0;
}
int /*$*/freeFunction/*$$*/(int* a, int& b) {
return 42;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
int freeFunction(int* a, int& b);
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
int freeFunction(int* a, int& b) {
return 42;
}
//!TestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
int main() {
return 0;
}
int /*$*/freeFunction/*$$*/(int* a, int& b)
try {
return 42;
}
catch (std::exception& e) {
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
//=
#include <iostream>
class A {
private:
int a;
int b;
public:
A(int x, int y) :
a(x), b(y) {
}
~A() {
}
};
int freeFunction(int* a, int& b)
try {
return 42;
}
catch (std::exception& e) {
}
//!TestFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
int /*$*/freeFunction/*$$*/() {
return 42;
}
//=
int freeFunction();
//@A.cpp
#include "A.h"
//=
#include "A.h"
int freeFunction() {
return 42;
}
//!TestQualifiedNameToggle
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
fatalerror=true
//@A.cpp
#include "A.h"
int /*$*/A::freefunction/*$$*/() {
return 42;
}
//=
#include "A.h"
int A::freefunction() {
return 42;
}
//!TestNamespacedFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#ifndef A_H_
#define A_H_
#include <iostream>
namespace N {
void /*$*/freefunction/*$$*/() {
return;
}
}
#endif /* A_H_ */
//=
#ifndef A_H_
#define A_H_
#include <iostream>
namespace N {
void freefunction();
}
#endif /* A_H_ */
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
namespace N {
void freefunction() {
return;
}
}

View file

@ -1,265 +0,0 @@
//!Test simple namespace in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void /*$*/foo/*$$*/() {
return;
}
};
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
inline void A::foo() {
return;
}
}
//!Test simple namespace in header to implementation within namespace definition
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
inline void A::/*$*/foo/*$$*/() {
return;
}
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
}
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
namespace N {
void A::foo() {
return;
}
}
//!Test simple namespace in header to implementation with namespace definition in implementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
inline void A::/*$*/foo/*$$*/() {
return;
}
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
}
//@A.cpp
#include "A.h"
int main() {
return 0;
}
namespace N {
}
//=
#include "A.h"
int main() {
return 0;
}
namespace N {
void A::foo() {
return;
}
}
//!Test simple namespace in header to implementation with namespace qualified name
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
}
inline void /*$*/N::A::foo/*$$*/() {
return;
}
//=
#include <iostream>
#include <exception>
namespace N {
class A {
void foo();
};
}
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
namespace N {
void A::foo() {
return;
}
}
//!TestSimpleNamespaceFromImplementationToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
void /*$*/N::A::foo/*$$*/() {
return;
}
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
namespace N {
class A {
void foo();
};
}
//=
#include <iostream>
namespace N {
class A {
void foo() {
return;
}
};
}
//!TestRemoveEmptyNamespaceFromImplentation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
namespace N {
void /*$*/A::foo/*$$*/() {
return;
}
}
//=
#include "A.h"
//@A.h
#include <iostream>
namespace N {
class A {
void foo();
};
}
//=
#include <iostream>
namespace N {
class A {
void foo() {
return;
}
};
}

View file

@ -1,104 +0,0 @@
//!TestNestedClassInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
class B {
void /*$*/member/*$$*/(int a, int b) {
return;
}
};
};
//=
#include <iostream>
class A {
class B {
void member(int a, int b);
};
};
inline void A::B::member(int a, int b) {
return;
}
//!TestNestedClassInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
class B {
void member(int a, int b);
};
};
inline void A::B::/*$*/member/*$$*/(int a, int b) {
return;
}
//=
#include <iostream>
class A {
class B {
void member(int a, int b);
};
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
void A::B::member(int a, int b) {
return;
}
//!TestNestedClassInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
int main() {
return 0;
}
void A::B::/*$*/member/*$$*/(int a, int b) {
return;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
class B {
void member(int a, int b);
};
};
//=
#include <iostream>
class A {
class B {
void member(int a, int b) {
return;
}
};
};

View file

@ -1,202 +0,0 @@
//!TestCorrectOrderingInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
public:
void func1();
void /*$*/func2/*$$*/() {
}
void func3();
void func4() {
}
};
inline void A::func1() {
}
inline void A::func3() {
}
//=
#include <iostream>
class A {
public:
void func1();
void func2();
void func3();
void func4() {
}
};
inline void A::func1() {
}
inline void A::func2() {
}
inline void A::func3() {
}
//!TestCorrectOrderingInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
public:
void func1();
void func2();
void func3();
void func4() {
}
};
inline void A::/*$*/func2/*$$*/() {
return;
}
//=
#include <iostream>
class A {
public:
void func1();
void func2();
void func3();
void func4() {
}
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
void A::func1() {
return;
}
void A::func3() {
return;
}
//=
#include "A.h"
int main() {
return 0;
}
void A::func1() {
return;
}
void A::func2() {
return;
}
void A::func3() {
return;
}
//!TestCorrectTemplateOrderingInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
template <typename T>
class A {
public:
void func1();
void /*$*/func2/*$$*/() {
}
void func3();
void func4() {
}
};
template<typename T>
inline void A<T>::func1() {
}
template<typename T>
inline void A<T>::func3() {
}
//=
#include <iostream>
template <typename T>
class A {
public:
void func1();
void func2();
void func3();
void func4() {
}
};
template<typename T>
inline void A<T>::func1() {
}
template<typename T>
inline void A<T>::func2() {
}
template<typename T>
inline void A<T>::func3() {
}
//!TestCorrectTemplateOrderingInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
template <typename T>
class A {
public:
void func1();
void func2();
void func3();
void func4() {
}
};
template<typename T>
inline void A<T>::func1() {
}
template<typename T>
inline void A<T>::/*$*/func2/*$$*/() {
}
template<typename T>
inline void A<T>::func3() {
}
//=
#include <iostream>
template <typename T>
class A {
public:
void func1();
void func2() {
}
void func3();
void func4() {
}
};
template<typename T>
inline void A<T>::func1() {
}
template<typename T>
inline void A<T>::func3() {
}

View file

@ -1,128 +0,0 @@
//!Test zero length selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void me/*$*//*$$*/mber() {
return;
}
};
//=
class A {
void member();
};
inline void A::member() {
return;
}
//!Test substring selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void m/*$*/e/*$$*/mber() {
return;
}
};
//=
class A {
void member();
};
inline void A::member() {
return;
}
//!Test body selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void member() {
r/*$*//*$$*/eturn;
}
};
//=
class A {
void member();
};
inline void A::member() {
return;
}
//!Test body selection with confusing name
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void member() {
int /*$*/abcd/*$$*/ = 42;
return;
}
};
//=
class A {
void member();
};
inline void A::member() {
int abcd = 42;
return;
}
//!Test left border selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
/*$*//*$$*/void member() {
return;
}
};
//=
class A {
void member();
};
inline void A::member() {
return;
}
//!Test right border selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
void member() {
return;
}/*$*//*$$*/
};
//=
class A {
void member();
};
inline void A::member() {
return;
}
//!Test overlapping selection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
vo/*$*/id member() {
ret/*$$*/urn;
}
};
//=
class A {
void member();
};
inline void A::member() {
return;
}

View file

@ -1,184 +0,0 @@
//!Test simple function in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
public:
int /*$*/function/*$$*/() {
return 0;
}
private:
int a;
};
//=
#include <iostream>
class A {
public:
int function();
private:
int a;
};
inline int A::function() {
return 0;
}
//!Test simple function in header to implementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
class A {
public:
int function();
private:
int a;
};
inline int A::/*$*/function/*$$*/() {
return 0;
}
//=
#include <iostream>
class A {
public:
int function();
private:
int a;
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
int A::function() {
return 0;
}
//!TestSimpleFunctionInImplementationToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include "A.h"
int A::/*$*/function/*$$*/() {
return 0;
}
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
public:
int function();
private:
int a;
};
//=
#include <iostream>
class A {
public:
int function() {
return 0;
}
private:
int a;
};
//!TestDifferentParameterNames
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=MyClass.cpp
//@MyClass.cpp
#include "MyClass.h"
myClass::/*$*/myClass/*$$*/(int implname) :
fVal(implname) {
}
int main() {
return 0;
}
//=
#include "MyClass.h"
int main() {
return 0;
}
//@MyClass.h
struct myClass {
int fVal;
myClass(int headername);
};
//=
struct myClass {
int fVal;
myClass(int implname) :
fVal(implname) {
}
};
//!TestMissingParameterNames
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=MyClass.cpp
//@MyClass.cpp
#include "MyClass.h"
myClass::/*$*/myClass/*$$*/(int implname) :
fVal(implname) {
}
int main() {
return 0;
}
//=
#include "MyClass.h"
int main() {
return 0;
}
//@MyClass.h
struct myClass {
int fVal;
myClass(int);
};
//=
struct myClass {
int fVal;
myClass(int implname) :
fVal(implname) {
}
};

View file

@ -1,131 +0,0 @@
//!Test template function in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
template <typename T, typename U>
class A {
class B {
T /*$*/member/*$$*/() {
return T();
}
};
};
//=
#include <iostream>
template <typename T, typename U>
class A {
class B {
T member();
};
};
template<typename T, typename U>
inline T A<T, U>::B::member() {
return T();
}
//!Test template function in header to in class
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
template <typename T>
class A {
class B {
T member();
};
};
template<typename T>
inline T A<T>::B::/*$*/member/*$$*/() {
return T();
}
//=
#include <iostream>
template <typename T>
class A {
class B {
T member() {
return T();
}
};
};
//!Test template function in header to in class with template selected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
tem/*$*/plate/*$$*/<typename T>
T foo() {
return T();
}
};
//=
class A {
template<typename T>
T foo();
};
template<typename T>
inline T A::foo() {
return T();
}
//!Test complex template function from in class to in header
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T, typename S>
class A {
public:
template<typename U, typename V>
void /*$*/foo/*$$*/(const U& u, const V& v) {
return;
}
};
//=
template<typename T, typename S>
class A {
public:
template<typename U, typename V>
void foo(const U& u, const V& v);
};
template<typename T, typename S>
template<typename U, typename V>
inline void A<T, S>::foo(const U& u, const V& v) {
return;
}
//!Test complex template function from in header to in class
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
template<typename T, typename S>
class A {
public:
template<typename U, typename V>
void /*$*/foo/*$$*/(const U& u, const V& v);
};
template<typename T, typename S>
template<typename U, typename V>
inline void A<T,S>::foo(const U& u, const V& v) {
return;
}
//=
template<typename T, typename S>
class A {
public:
template<typename U, typename V>
void foo(const U& u, const V& v) {
return;
}
};

View file

@ -1,262 +0,0 @@
//!TestTryCatchFromInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
class A {
void /*$*/member/*$$*/(int a, int b)
try {
return;
}
catch (std::exception& e1){
return;
}
};
//=
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
inline void A::member(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
//!TestTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
inline void /*$*/A::member/*$$*/(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
//=
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
void A::member(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
//!TestTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include <exception>
#include "A.h"
void A::/*$*/member/*$$*/()
try {
return;
}
catch (std::exception& e1) {
return;
}
int main() {
return 0;
}
//=
#include <exception>
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
void member();
};
//=
#include <iostream>
class A {
void member()
try {
return;
}
catch (std::exception& e1) {
return;
}
};
//!TestMultipleTryCatchFromInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
class A {
void /*$*/member/*$$*/(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
};
//=
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
inline void A::member(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
//!TestMultipleTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
inline void /*$*/A::member/*$$*/(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
//=
#include <iostream>
#include <exception>
class A {
void member(int a, int b);
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
void A::member(int a, int b)
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
//!TestMultipleTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.cpp
//@A.cpp
#include <exception>
#include "A.h"
void A::/*$*/member/*$$*/()
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
int main() {
return 0;
}
//=
#include <exception>
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
class A {
void member();
};
//=
#include <iostream>
class A {
void member()
try {
return;
}
catch (std::exception& e1) {
return;
}
catch (std::exception& e2) {
return;
}
};

View file

@ -1,83 +0,0 @@
//!TestRemoveVirtualSpecifierFromClassToInheader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
virtual int /*$*/foo/*$$*/() {
return 0;
}
};
//=
class A {
virtual int foo();
};
inline int A::foo() {
return 0;
}
//!TestVirtualSpecifierFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//%CPP
//@.config
filename=A.h
//@A.h
class A {
virtual int /*$*/foo/*$$*/();
};
inline int A::foo() {
return 0;
}
//=
class A {
virtual int foo();
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}
int A::foo() {
return 0;
}
//!TestVirtualSpecifierFromImplementationToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
filename=A.h
//@A.h
class A {
virtual int /*$*/foo/*$$*/();
};
//=
class A {
virtual int foo() {
return 0;
}
};
//@A.cpp
#include "A.h"
int main() {
return 0;
}
int A::foo() {
return 0;
}
//=
#include "A.h"
int main() {
return 0;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2011 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2009, 2012 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
@ -19,14 +19,14 @@ import java.util.Properties;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringContext;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
/**
* @author Emanuel Graf IFS
*/
@ -39,8 +39,7 @@ public class RefactoringHistoryTest extends RefactoringTest {
@Override
protected void configureRefactoring(Properties refactoringProperties) {
scriptFile = fileMap.get(refactoringProperties.getProperty(
"scriptFile", "refScript.xml"));
scriptFile = fileMap.get(refactoringProperties.getProperty("scriptFile", "refScript.xml"));
}
@Override
@ -52,25 +51,12 @@ public class RefactoringHistoryTest extends RefactoringTest {
new ByteArrayInputStream(xmlSource.getBytes()), 0);
for (RefactoringDescriptorProxy proxy : refHist.getDescriptors()) {
RefactoringStatus status = new RefactoringStatus();
Refactoring ref = proxy.requestDescriptor(new NullProgressMonitor()).createRefactoring(status);
RefactoringDescriptor descriptor = proxy.requestDescriptor(new NullProgressMonitor());
RefactoringContext context = descriptor.createRefactoringContext(status);
assertTrue(status.isOK());
RefactoringStatus checkInitialConditions = ref.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError) {
assertConditionsFatalError(checkInitialConditions);
return;
} else {
assertConditionsOk(checkInitialConditions);
executeRefactoring(ref);
}
Refactoring refactoring = context.getRefactoring();
executeRefactoring(refactoring, context, false);
compareFiles(fileMap);
}
}
protected void executeRefactoring(Refactoring refactoring) throws Exception {
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(finalConditions);
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
createChange.perform(NULL_PROGRESS_MONITOR);
compareFiles(fileMap);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -17,6 +17,10 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringContext;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
@ -25,17 +29,23 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* Don't create new tests based on this class. Use RefactoringTestBase instead.
*
* @author Emanuel Graf
*/
public abstract class RefactoringTest extends RefactoringBaseTest {
private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$
protected String fileName;
protected RefactoringASTCache astCache;
protected boolean fatalError;
protected int initialErrors;
protected int initialWarnings;
protected int finalWarnings;
protected int finalInfos;
public RefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
@ -44,6 +54,62 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
protected abstract void configureRefactoring(Properties refactoringProperties);
protected void executeRefactoring(Refactoring refactoring) throws CoreException {
RefactoringContext context = refactoring instanceof CRefactoring2 ?
new CRefactoringContext((CRefactoring2) refactoring) :
new RefactoringContext(refactoring);
executeRefactoring(refactoring, context, true);
}
protected void executeRefactoring(Refactoring refactoring, boolean withUserInput) throws CoreException {
RefactoringContext context = refactoring instanceof CRefactoring2 ?
new CRefactoringContext((CRefactoring2) refactoring) :
new RefactoringContext(refactoring);
executeRefactoring(refactoring, context, withUserInput);
}
protected void executeRefactoring(Refactoring refactoring, RefactoringContext context,
boolean withUserInput) throws CoreException {
try {
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError) {
assertConditionsFatalError(checkInitialConditions);
return;
}
if (initialErrors != 0) {
assertConditionsError(checkInitialConditions, initialErrors);
} else if (initialWarnings != 0) {
assertConditionsFatalError(checkInitialConditions, initialWarnings);
} else {
assertConditionsOk(checkInitialConditions);
}
if (withUserInput)
simulateUserInput();
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
if (finalWarnings > 0) {
assertConditionsWarning(finalConditions, finalWarnings);
} else if (finalInfos > 0) {
assertConditionsInfo(finalConditions, finalInfos);
} else {
assertConditionsOk(finalConditions);
}
Change change = refactoring.createChange(NULL_PROGRESS_MONITOR);
change.perform(NULL_PROGRESS_MONITOR);
} finally {
if (context != null)
context.dispose();
}
}
/**
* Subclasses can override to simulate user input.
*/
protected void simulateUserInput() {
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -52,12 +118,10 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
CCorePlugin.getIndexManager().reindex(cproject);
boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR);
assertTrue(joined);
astCache = new RefactoringASTCache();
}
@Override
protected void tearDown() throws Exception {
astCache.dispose();
super.tearDown();
}

View file

@ -24,9 +24,12 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringContext;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
@ -36,13 +39,18 @@ import org.osgi.framework.Bundle;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* Common base for refactoring tests.
@ -51,8 +59,9 @@ public abstract class RefactoringTestBase extends BaseTestCase {
private static final int INDEXER_TIMEOUT_SEC = 360;
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
protected boolean createEmptyFiles = true;
protected boolean ascendingVisibilityOrder;
private boolean cpp = true;
private RefactoringASTCache astCache;
private ICProject cproject;
private final Set<TestSourceFile> testFiles = new LinkedHashSet<TestSourceFile>();
private TestSourceFile selectedFile;
@ -70,6 +79,7 @@ public abstract class RefactoringTestBase extends BaseTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
resetPreferences();
cproject = cpp ?
CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) :
CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
@ -95,7 +105,7 @@ public abstract class RefactoringTestBase extends BaseTestCase {
}
reader.close();
if (!testFile.getSource().isEmpty()) {
if (createEmptyFiles || !testFile.getSource().isEmpty()) {
TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()),
testFile.getSource());
}
@ -111,16 +121,15 @@ public abstract class RefactoringTestBase extends BaseTestCase {
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000,
NULL_PROGRESS_MONITOR));
astCache = new RefactoringASTCache();
}
@Override
public void tearDown() throws Exception {
astCache.dispose();
if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
NULL_PROGRESS_MONITOR);
}
resetPreferences();
super.tearDown();
}
@ -134,30 +143,45 @@ public abstract class RefactoringTestBase extends BaseTestCase {
}
private void executeRefactoring(boolean expectedSuccess) throws Exception {
if (ascendingVisibilityOrder) {
getPreferenceStore().setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER,
ascendingVisibilityOrder);
}
if (historyScript != null) {
executeHistoryRefactoring(expectedSuccess);
return;
}
Refactoring refactoring = createRefactoring();
executeRefactoring(refactoring, true, expectedSuccess);
RefactoringContext context;
if (refactoring instanceof CRefactoring2) {
context = new CRefactoringContext((CRefactoring2) refactoring);
} else {
context = new RefactoringContext(refactoring);
}
executeRefactoring(refactoring, context, true, expectedSuccess);
}
protected void executeRefactoring(Refactoring refactoring, boolean withUserInput,
boolean expectedSuccess) throws CoreException, Exception {
RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (!expectedSuccess) {
assertStatusFatalError(initialStatus);
return;
}
protected void executeRefactoring(Refactoring refactoring, RefactoringContext context,
boolean withUserInput, boolean expectedSuccess) throws CoreException, Exception {
try {
RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (!expectedSuccess) {
assertStatusFatalError(initialStatus);
return;
}
assertStatusOk(initialStatus);
if (withUserInput)
simulateUserInput();
RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertStatusOk(finalStatus);
Change change = refactoring.createChange(NULL_PROGRESS_MONITOR);
change.perform(NULL_PROGRESS_MONITOR);
assertStatusOk(initialStatus);
if (withUserInput)
simulateUserInput();
RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertStatusOk(finalStatus);
Change change = refactoring.createChange(NULL_PROGRESS_MONITOR);
change.perform(NULL_PROGRESS_MONITOR);
} finally {
if (context != null)
context.dispose();
}
}
private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception {
@ -166,11 +190,11 @@ public abstract class RefactoringTestBase extends BaseTestCase {
RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory(
new ByteArrayInputStream(scriptSource.getBytes()), 0);
for (RefactoringDescriptorProxy proxy : history.getDescriptors()) {
RefactoringDescriptor descriptor = proxy.requestDescriptor(NULL_PROGRESS_MONITOR);
RefactoringStatus status = new RefactoringStatus();
Refactoring refactoring =
proxy.requestDescriptor(NULL_PROGRESS_MONITOR).createRefactoring(status);
RefactoringContext context = descriptor.createRefactoringContext(status);
assertTrue(status.isOK());
executeRefactoring(refactoring, false, expectedSuccess);
executeRefactoring(context.getRefactoring(), context, false, expectedSuccess);
}
}
@ -199,6 +223,13 @@ public abstract class RefactoringTestBase extends BaseTestCase {
return cproject.getProject().getFile(new Path(selectedFile.getName()));
}
protected ITranslationUnit getSelectedTranslationUnit() {
IFile file = getSelectedFile();
if (file == null)
return null;
return (ITranslationUnit) CoreModel.getDefault().create(file);
}
protected TestSourceFile getHistoryScriptFile() {
return historyScript;
}
@ -305,14 +336,21 @@ public abstract class RefactoringTestBase extends BaseTestCase {
}
protected String getFileContents(IFile file) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
StringBuilder code = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
code.append(line);
code.append('\n');
}
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents(), "UTF-8"));
StringBuilder buffer = new StringBuilder();
char[] part= new char[2048];
int read= 0;
while ((read= reader.read(part)) != -1)
buffer.append(part, 0, read);
reader.close();
return code.toString();
return buffer.toString();
}
protected void resetPreferences() {
getPreferenceStore().setToDefault(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER);
}
protected IPreferenceStore getPreferenceStore() {
return CUIPlugin.getDefault().getPreferenceStore();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -16,14 +16,14 @@ package org.eclipse.cdt.ui.tests.refactoring;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantTestSuite;
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.extractlocalvariable.ExtractLocalVariableTestSuite;
import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTestSuite;
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.implementmethod.ImplementMethodTestSuite;
import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests;
import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTestSuite;
import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToogleRefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
/**
@ -36,12 +36,12 @@ public class RefactoringTestSuite extends TestSuite {
suite.addTest(UtilTestSuite.suite());
suite.addTest(RenameRegressionTests.suite());
suite.addTest(ExtractFunctionRefactoringTest.suite());
suite.addTest(ExtractConstantTestSuite.suite());
suite.addTest(ExtractConstantRefactoringTest.suite());
suite.addTest(HideMethodTestSuite.suite());
suite.addTest(GenerateGettersAndSettersTestSuite.suite());
suite.addTest(GenerateGettersAndSettersTest.suite());
suite.addTest(ImplementMethodTestSuite.suite());
suite.addTest(ExtractLocalVariableTestSuite.suite());
suite.addTest(ToggleRefactoringTestSuite.suite());
suite.addTest(ToogleRefactoringTest.suite());
return suite;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -8,52 +8,788 @@
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractconstant;
import java.util.Collection;
import java.util.Properties;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantInfo;
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
/**
* @author Emanuel Graf
* Tests for Extract Constant refactoring.
*/
public class ExtractConstantRefactoringTest extends RefactoringTest {
protected VisibilityEnum visibility;
public class ExtractConstantRefactoringTest extends RefactoringTestBase {
private ExtractConstantInfo refactoringInfo;
private String extractedConstantName = "EXTRACTED";
private VisibilityEnum visibility = VisibilityEnum.v_private;
public ExtractConstantRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
public ExtractConstantRefactoringTest() {
super();
}
public ExtractConstantRefactoringTest(String name) {
super(name);
}
public static Test suite() {
return suite(ExtractConstantRefactoringTest.class);
}
@Override
protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileName);
ExtractConstantInfo info = new ExtractConstantInfo();
CRefactoring refactoring = new ExtractConstantRefactoring(refFile, selection, info, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(checkInitialConditions);
info.setName("theAnswer"); //$NON-NLS-1$
info.setVisibility(visibility);
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(finalConditions);
createChange.perform(NULL_PROGRESS_MONITOR);
compareFiles(fileMap);
protected Refactoring createRefactoring() {
refactoringInfo = new ExtractConstantInfo();
return new ExtractConstantRefactoring(getSelectedFile(), getSelection(), refactoringInfo,
getCProject());
}
@Override
protected void configureRefactoring(Properties refactoringProperties) {
visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_public.toString())); //$NON-NLS-1$
protected void simulateUserInput() {
refactoringInfo.setName(extractedConstantName);
refactoringInfo.setVisibility(visibility);
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//
//private:
// static const int EXTRACTED = 42;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return /*$*/42/*$$*/; //Hello
//}
//
//void A::bar() {
// int a = 42;
// int b = 42;
//}
//====================
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return EXTRACTED; //Hello
//}
//
//void A::bar() {
// int a = EXTRACTED;
// int b = EXTRACTED;
//}
public void testExtractConstantInt() throws Exception {
assertRefactoringSuccess();
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//
//private:
// static const int EXTRACTED = 42;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// //Hello
// return /*$*/42/*$$*/;
//}
//
//void A::bar() {
// int a = 42;
// int b = 42;
//}
//====================
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// //Hello
// return EXTRACTED;
//}
//
//void A::bar() {
// int a = EXTRACTED;
// int b = EXTRACTED;
//}
public void testExtractConstantInt2() throws Exception {
assertRefactoringSuccess();
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// float foo();
// void bar();
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// float foo();
// void bar();
//
//private:
// static const float EXTRACTED = 42.0f;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//float A::foo() {
// return /*$*/42.0f/*$$*/;
//}
//
//void A::bar() {
// float a = 42.0f;
// float b = 42.0f;
//}
//====================
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//float A::foo() {
// return EXTRACTED;
//}
//
//void A::bar() {
// float a = EXTRACTED;
// float b = EXTRACTED;
//}
public void testExtractConstantFloat() throws Exception {
assertRefactoringSuccess();
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// double foo();
// void bar();
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// double foo();
// void bar();
//
//private:
// static const double EXTRACTED = 42.0;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//double A::foo() {
// return /*$*/42.0/*$$*/;
//}
//
//void A::bar() {
// double a = 42.0;
// double b = 42.0;
//}
//====================
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//double A::foo() {
// return EXTRACTED;
//}
//
//void A::bar() {
// double a = EXTRACTED;
// double b = EXTRACTED;
//}
public void testExtractConstantDouble() throws Exception {
assertRefactoringSuccess();
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// static const int a = 42;
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// static const int a = 42;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return 42;
//}
//
//int bar() {
// return /*$*/42/*$$*/;
//}
//====================
//#include "A.h"
//
//namespace {
//
//const int EXTRACTED = 42;
//
//}
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return EXTRACTED;
//}
//
//int bar() {
// return EXTRACTED;
//}
public void testExtractConstantStaticInt() 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();
//
//protected:
// static const int EXTRACTED = 42;
//};
//
//#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() {
// return EXTRACTED;
//}
public void testReplaceNumberProtected() throws Exception {
visibility = VisibilityEnum.v_protected;
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();
//
//private:
// static const int EXTRACTED = 42;
//};
//
//#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() {
// return EXTRACTED;
//}
public void testReplaceNumberPrivate() throws Exception {
assertRefactoringSuccess();
}
//A.h
//class X {
// void method() {
// int a = /*$*/42/*$$*/;
// }
//};
//====================
//class X {
//public:
// static const int EXTRACTED = 42;
//
//private:
// void method() {
// int a = EXTRACTED;
// }
//};
public void testExtractConstantFromInlinedMethod_Bug246062() throws Exception {
visibility = VisibilityEnum.v_public;
assertRefactoringSuccess();
}
//A.h
//class X {
// void method() {
// char* a = /*$*/"sometext"/*$$*/;
// }
//
// void method2() {
// const char* b = "sometext";
// }
//};
//====================
//class X {
// void method() {
// char* a = EXTRACTED;
// }
//
// void method2() {
// const char* b = EXTRACTED;
// }
//
// static const char* EXTRACTED = "sometext";
//};
public void testString() throws Exception {
assertRefactoringSuccess();
}
//A.h
//class X {
// void method() {
// wchar_t* a = /*$*/L"sometext"/*$$*/;
// }
//
// void method2() {
// const wchar_t* b = L"sometext";
// const char* c = "sometext";
// }
//};
//====================
//class X {
// void method() {
// wchar_t* a = EXTRACTED;
// }
//
// void method2() {
// const wchar_t* b = EXTRACTED;
// const char* c = "sometext";
// }
//
// static const wchar_t* EXTRACTED = L"sometext";
//};
public void testExtractConstantWideString() throws Exception {
assertRefactoringSuccess();
}
//A.h
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//};
//
//#endif /*A_H_*/
//====================
//#ifndef A_H_
//#define A_H_
//
//class A {
//public:
// A();
// virtual ~A();
// int foo();
// void bar();
//
// static const int EXTRACTED = 42;
//};
//
//#endif /*A_H_*/
//A.cpp
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return 42; // Hello
//}
//
//void A::bar() {
// int a = 42;
// int b = 42;
//}
//====================
//#include "A.h"
//
//A::A() {
//}
//
//A::~A() {
//}
//
//int A::foo() {
// return EXTRACTED; // Hello
//}
//
//void A::bar() {
// int a = EXTRACTED;
// int b = EXTRACTED;
//}
//refactoringScript.xml
//<?xml version="1.0" encoding="UTF-8"?>
//<session version="1.0">
//<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
//fileName="file:${projectPath}/A.cpp" flags="4"
//id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="EXTRACTED"
//project="RegressionTestProject" selection="64,2" visibility="public"/>
//</session>
//
public void testHistoryExtractConstantInt() 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();
//
//protected:
// static const int EXTRACTED = 42;
//};
//
//#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() {
// return EXTRACTED;
//}
//refactoringScript.xml
//<?xml version="1.0" encoding="UTF-8"?>
//<session version="1.0">
//<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
//fileName="file:${projectPath}/A.cpp" flags="4"
//id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="EXTRACTED"
//project="RegressionTestProject" selection="64,2" visibility="protected"/>
//</session>
public void testHistoryReplaceNumberProtected() 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();
//
//private:
// static const int EXTRACTED = 42;
//};
//
//#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() {
// return EXTRACTED;
//}
//refactoringScript.xml
//<?xml version="1.0" encoding="UTF-8"?>
//<session version="1.0">
//<refactoring comment="Create constant for 42" description="Extract Constant Refactoring"
//fileName="file:${projectPath}/A.cpp" flags="4"
//id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring" name="EXTRACTED"
//project="RegressionTestProject" selection="64,2" visibility="private"/>
//</session>
public void testHistoryReplaceNumberPrivate() throws Exception {
assertRefactoringSuccess();
}
}

View file

@ -1,34 +0,0 @@
/*******************************************************************************
* Copyright (c) 2009 Google, Inc 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:
* Tom Ball (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractconstant;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
/**
* Test suite to run just the Extract Constant unit tests.
*
* @author Tom Ball
*/
public class ExtractConstantTestSuite extends TestSuite {
@SuppressWarnings("nls")
public static Test suite() throws Exception {
TestSuite suite = new ExtractConstantTestSuite();
suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTest",
"resources/refactoring/ExtractConstant.rts"));
suite.addTest(RefactoringTester.suite("ExtractConstantHistoryRefactoringTest",
"resources/refactoring/ExtractConstantHistory.rts"));
return suite;
}
}

View file

@ -18,10 +18,8 @@ import java.util.Map;
import junit.framework.Test;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
@ -59,25 +57,12 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
}
@Override
public void setUp() throws Exception {
super.setUp();
resetPreferences();
}
@Override
public void tearDown() throws Exception {
super.tearDown();
resetPreferences();
}
private void resetPreferences() {
protected void resetPreferences() {
super.resetPreferences();
getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT);
getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER);
}
private IPreferenceStore getPreferenceStore() {
return CUIPlugin.getDefault().getPreferenceStore();
}
@Override
protected Refactoring createRefactoring() {
refactoringInfo = new ExtractFunctionInformation();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Tom Ball (Google) - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
@ -15,14 +16,12 @@ import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.CoreModel;
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.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring;
/**
@ -32,7 +31,6 @@ import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocal
*/
public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
protected String variableName;
protected boolean fatalError;
public ExtractLocalVariableRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
@ -40,22 +38,12 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
@Override
protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileName);
NameNVisibilityInformation info = new NameNVisibilityInformation();
info.setName(variableName);
CRefactoring refactoring = new ExtractLocalVariableRefactoring( refFile, selection, info, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError){
assertConditionsFatalError(checkInitialConditions);
return;
}
assertConditionsOk(checkInitialConditions);
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(finalConditions);
createChange.perform(NULL_PROGRESS_MONITOR);
IFile file = project.getFile(fileName);
ICElement element = CoreModel.getDefault().create(file);
ExtractLocalVariableRefactoring refactoring =
new ExtractLocalVariableRefactoring(element, selection, cproject);
refactoring.getRefactoringInfo().setName(variableName);
executeRefactoring(refactoring);
compareFiles(fileMap);
}

View file

@ -1,32 +0,0 @@
/*******************************************************************************
* Copyright (c) 2009 Google, Inc 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:
* Tom Ball (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.gettersandsetters;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
/**
* Test suite to run just the Generate Getters and Setters unit tests.
*
* @author Tom Ball
*/
public class GenerateGettersAndSettersTestSuite extends TestSuite {
@SuppressWarnings("nls")
public static Test suite() throws Exception {
TestSuite suite = new GenerateGettersAndSettersTestSuite();
suite.addTest(RefactoringTester.suite("GenerateGettersAndSettersTest",
"resources/refactoring/GenerateGettersAndSetters.rts"));
return suite;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.hidemethod;
@ -15,22 +16,17 @@ import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring;
/**
* @author Guido Zgraggen IFS
*/
public class HideMethodRefactoringTest extends RefactoringTest {
private int warnings;
private int errors;
private int fatalerrors;
public HideMethodRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
@ -39,32 +35,15 @@ public class HideMethodRefactoringTest extends RefactoringTest {
@Override
protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileWithSelection);
CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (errors > 0) {
assertConditionsError(checkInitialConditions, errors);
} else if (fatalerrors > 0) {
assertConditionsError(checkInitialConditions, errors);
return;
} else {
assertConditionsOk(checkInitialConditions);
}
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
if (warnings > 0) {
assertConditionsWarning(finalConditions, warnings);
} else {
assertConditionsOk(finalConditions);
}
createChange.perform(NULL_PROGRESS_MONITOR);
Refactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject);
executeRefactoring(refactoring);
compareFiles(fileMap);
}
@Override
protected void configureRefactoring(Properties refactoringProperties) {
warnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
errors = new Integer(refactoringProperties.getProperty("errors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
fatalerrors = new Integer(refactoringProperties.getProperty("fatalerrors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$
finalWarnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
initialErrors = new Integer(refactoringProperties.getProperty("errors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -9,6 +9,7 @@
* Contributors:
* Institute for Software - initial API and implementation
* Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.implementmethod;
@ -16,8 +17,6 @@ import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
@ -31,9 +30,6 @@ import org.eclipse.cdt.internal.ui.refactoring.implementmethod.ImplementMethodRe
* @author Mirko Stocker
*/
public class ImplementMethodRefactoringTest extends RefactoringTest {
protected int finalWarnings;
private int initialWarnings;
private int infos;
public ImplementMethodRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
@ -43,28 +39,8 @@ public class ImplementMethodRefactoringTest extends RefactoringTest {
protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileName);
ICElement element = CoreModel.getDefault().create(refFile);
CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject, astCache);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (initialWarnings == 0) {
assertConditionsOk(checkInitialConditions);
} else {
assertConditionsFatalError(checkInitialConditions, initialWarnings);
return;
}
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
if (finalWarnings > 0) {
assertConditionsWarning(finalConditions, finalWarnings);
} else if (infos > 0) {
assertConditionsInfo(finalConditions, infos);
} else {
assertConditionsOk(finalConditions);
}
createChange.perform(NULL_PROGRESS_MONITOR);
CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject);
executeRefactoring(refactoring);
compareFiles(fileMap);
}
@ -72,6 +48,6 @@ public class ImplementMethodRefactoringTest extends RefactoringTest {
protected void configureRefactoring(Properties refactoringProperties) {
finalWarnings = new Integer(refactoringProperties.getProperty("finalWarnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
initialWarnings = Integer.parseInt(refactoringProperties.getProperty("initialWarnings", "0")); //$NON-NLS-1$//$NON-NLS-2$
infos = Integer.parseInt(refactoringProperties.getProperty("infos", "0")); //$NON-NLS-1$//$NON-NLS-2$
finalInfos = Integer.parseInt(refactoringProperties.getProperty("infos", "0")); //$NON-NLS-1$//$NON-NLS-2$
}
}

View file

@ -1,31 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011 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.togglefunction;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoringContext;
public class MockToggleRefactoringTest extends ToggleRefactoring {
public MockToggleRefactoringTest(IFile file, TextSelection selection, ICProject proj) {
super(file, selection, proj);
}
public ToggleRefactoringContext getContext() {
return context;
}
}

View file

@ -1,119 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011 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.togglefunction;
import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
public class ToggleRefactoringTest extends RefactoringTest {
private boolean fatalError;
private boolean newFileCreation;
private String[] newfiles;
public ToggleRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files);
}
@Override
protected void configureRefactoring(Properties refactoringProperties) {
fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
newFileCreation = Boolean.valueOf(refactoringProperties.getProperty("newfilecreation", "false")).booleanValue();
newfiles = separateNewFiles(refactoringProperties);
}
private String[] separateNewFiles(Properties refactoringProperties) {
return String.valueOf(refactoringProperties.getProperty("newfiles", "")).replace(" ", "").split(",");
}
@Override
protected void runTest() throws Throwable {
MockToggleRefactoringTest refactoring = new MockToggleRefactoringTest(project.getFile(fileName), selection, cproject);
if (newFileCreation) {
pre_executeNewFileCreationRefactoring(refactoring);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
refactoring.getContext().setSettedDefaultAnswer(true);
refactoring.getContext().setDefaultAnswer(true);
if (fatalError) {
assertConditionsFatalError(checkInitialConditions);
return;
}
assertConditionsOk(checkInitialConditions);
aftertest(refactoring);
return;
} else {
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (fatalError) {
assertConditionsFatalError(checkInitialConditions);
return;
}
assertConditionsOk(checkInitialConditions);
executeRefactoring(refactoring);
}
}
private void aftertest(Refactoring refactoring) throws Exception {
Change changes = refactoring.createChange(NULL_PROGRESS_MONITOR);
assertConditionsOk(refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR));
changes.perform(NULL_PROGRESS_MONITOR);
filesDoExist();
for (String fileName: fileMap.keySet()) {
IFile iFile = project.getFile(new Path(fileName));
String code = getCodeFromIFile(iFile);
String expectedSource = fileMap.get(fileName).getExpectedSource();
assertEquals(TestHelper.unifyNewLines(expectedSource), TestHelper.unifyNewLines(code));
}
}
private void pre_executeNewFileCreationRefactoring(Refactoring refactoring) throws Exception {
removeFiles();
filesDoNotExist();
}
private void filesDoExist() {
for (String fileName: newfiles) {
IFile file = project.getFile(new Path(fileName));
assertTrue(file.exists());
}
}
private void filesDoNotExist() {
for (String fileName: newfiles) {
IFile file = project.getFile(new Path(fileName));
assertFalse(file.exists());
}
}
private void removeFiles() throws CoreException {
for (String fileName: newfiles) {
IFile file = project.getFile(new Path(fileName));
file.delete(true, NULL_PROGRESS_MONITOR);
}
}
private void executeRefactoring(Refactoring refactoring) throws Exception {
Change changes = refactoring.createChange(NULL_PROGRESS_MONITOR);
assertConditionsOk(refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR));
changes.perform(NULL_PROGRESS_MONITOR);
compareFiles(fileMap);
}
}

View file

@ -1,65 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011 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.togglefunction;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
public class ToggleRefactoringTestSuite extends TestSuite {
@SuppressWarnings("nls")
public static Test suite() throws Exception {
TestSuite suite = new ToggleRefactoringTestSuite();
suite.addTest(RefactoringTester.suite("NewCreationTest",
"resources/refactoring/NewCreationTest.rts"));
suite.addTest(RefactoringTester.suite("ToggleErrorRefactoring",
"resources/refactoring/ToggleErrorRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleSelectionTest",
"resources/refactoring/ToggleSelection.rts"));
suite.addTest(RefactoringTester.suite(
"ToggleSimpleFunctionRefactoringTest",
"resources/refactoring/ToggleSimpleFunctionRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleTemplateRefactoringTest",
"resources/refactoring/ToggleTemplateRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleNamespaceRefactoringTest",
"resources/refactoring/ToggleNamespaceRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleTryCatchRefactoringTest",
"resources/refactoring/ToggleTryCatchRefactoring.rts"));
suite.addTest(RefactoringTester.suite(
"ToggleDefaultParameterRefactoringTest",
"resources/refactoring/ToggleDefaultParameterRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleCtorDtorRefactoringTest",
"resources/refactoring/ToggleCtorDtorRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleNestedRefactoringTest",
"resources/refactoring/ToggleNestedRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleDifferentSelectionsTest",
"resources/refactoring/ToggleDifferentSelections.rts"));
suite.addTest(RefactoringTester.suite("ToggleFreeFunctionTest",
"resources/refactoring/ToggleFreeFunction.rts"));
suite.addTest(RefactoringTester.suite("ToggleVirtualFunctionTest",
"resources/refactoring/ToggleVirtualFunction.rts"));
suite.addTest(RefactoringTester.suite("ToggleOrderingTest",
"resources/refactoring/ToggleOrdering.rts"));
suite.addTest(RefactoringTester.suite("ToggleCommentsClassToHeader",
"resources/refactoring/ToggleCommentsClassToHeader.rts"));
suite.addTest(RefactoringTester.suite("ToggleCommentsHeaderToClass",
"resources/refactoring/ToggleCommentsHeaderToClass.rts"));
suite.addTest(RefactoringTester.suite("ToggleCommentsHeaderToImpl",
"resources/refactoring/ToggleCommentsHeaderToImpl.rts"));
suite.addTest(RefactoringTester.suite("ToggleCommentsImplToHeader",
"resources/refactoring/ToggleCommentsImplToHeader.rts"));
suite.addTestSuite(ToggleNodeHelperTest.class);
return suite;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Marc-Andre Laperle and others.
* Copyright (c) 2011, 2012 Marc-Andre Laperle 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
@ -7,6 +7,7 @@
*
* Contributors:
* Marc-Andre Laperle - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.utils;
@ -14,16 +15,24 @@ import java.util.Collection;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder;
public class DefinitionFinderTest extends RefactoringTest {
@ -39,14 +48,36 @@ public class DefinitionFinderTest extends RefactoringTest {
@Override
protected void runTest() throws Throwable {
IFile file = project.getFile(fileName);
ICElement element = CCorePlugin.getDefault().getCoreModel().create(file);
if (element instanceof ITranslationUnit) {
IASTTranslationUnit ast = astCache.getAST((ITranslationUnit) element, null);
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
CRefactoring2 refactoring = new CRefactoring2(tu, null, tu.getCProject()) {
@Override
protected RefactoringStatus checkFinalConditions(IProgressMonitor progressMonitor,
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
return null;
}
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
return null;
}
@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException {
}
};
CRefactoringContext refactoringContext = new CRefactoringContext(refactoring);
try {
IASTTranslationUnit ast = refactoringContext.getAST(tu, null);
for (IASTDeclaration declaration : ast.getDeclarations()) {
if (declaration instanceof IASTSimpleDeclaration) {
assertNotNull(DefinitionFinder.getDefinition((IASTSimpleDeclaration) declaration, astCache, NULL_PROGRESS_MONITOR));
assertNotNull(DefinitionFinder.getDefinition((IASTSimpleDeclaration) declaration,
refactoringContext, NULL_PROGRESS_MONITOR));
}
}
} finally {
refactoringContext.dispose();
}
}
}

View file

@ -112,7 +112,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="3.4.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.6.0",
org.eclipse.ltk.ui.refactoring;bundle-version="3.4.0",
org.eclipse.ui.navigator.resources;bundle-version="3.3.100"
Bundle-ActivationPolicy: lazy

View file

@ -52,7 +52,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* A collection of static methods for finding the source file corresponding to a header
@ -330,7 +330,7 @@ public final class SourceHeaderPartnerFinder {
}
public static ITranslationUnit getPartnerTranslationUnit(ITranslationUnit tu,
RefactoringASTCache astCache) throws CoreException {
CRefactoringContext astCache) throws CoreException {
ITranslationUnit partnerUnit= getPartnerFileFromFilename(tu);
if (partnerUnit == null) {

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.ui.refactoring;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@ -47,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -68,14 +70,12 @@ public abstract class CRefactoring2 extends Refactoring {
protected String name = Messages.Refactoring_name;
protected final ICProject project;
protected final ITranslationUnit tu;
protected final RefactoringStatus initStatus;
protected final RefactoringASTCache astCache;
protected Region selectedRegion;
protected final RefactoringStatus initStatus;
protected CRefactoringContext refactoringContext;
public CRefactoring2(ICElement element, ISelection selection, ICProject project,
RefactoringASTCache astCache) {
public CRefactoring2(ICElement element, ISelection selection, ICProject project) {
this.project = project;
this.astCache = astCache;
this.initStatus= new RefactoringStatus();
if (!(element instanceof ISourceReference)) {
this.tu = null;
@ -98,70 +98,10 @@ public abstract class CRefactoring2 extends Refactoring {
}
}
private class ProblemFinder extends ASTVisitor {
private boolean problemFound = false;
private final RefactoringStatus status;
public ProblemFinder(RefactoringStatus status) {
this.status = status;
}
{
shouldVisitProblems = true;
shouldVisitDeclarations = true;
shouldVisitExpressions = true;
shouldVisitStatements = true;
shouldVisitTypeIds = true;
}
@Override
public int visit(IASTProblem problem) {
addWarningToState();
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTDeclaration declaration) {
if (declaration instanceof IASTProblemDeclaration) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTExpression expression) {
if (expression instanceof IASTProblemExpression) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTStatement statement) {
if (statement instanceof IASTProblemStatement) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTTypeId typeId) {
if (typeId instanceof IASTProblemTypeId) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
public boolean hasProblem() {
return problemFound;
}
private void addWarningToState() {
if (!problemFound) {
status.addWarning(Messages.Refactoring_CompileErrorInTU);
problemFound = true;
}
}
public void setContext(CRefactoringContext refactoringContext) {
Assert.isNotNull(refactoringContext);
this.refactoringContext = refactoringContext;
}
@Override
@ -248,7 +188,11 @@ public abstract class CRefactoring2 extends Refactoring {
protected IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm)
throws CoreException, OperationCanceledException {
return astCache.getAST(tu, pm);
return refactoringContext.getAST(tu, pm);
}
protected IIndex getIndex() throws OperationCanceledException, CoreException {
return refactoringContext.getIndex();
}
protected boolean checkAST(IASTTranslationUnit ast) {
@ -284,4 +228,70 @@ public abstract class CRefactoring2 extends Refactoring {
result.add(new ResourceChangeChecker());
return result;
}
private class ProblemFinder extends ASTVisitor {
private boolean problemFound = false;
private final RefactoringStatus status;
public ProblemFinder(RefactoringStatus status) {
this.status = status;
}
{
shouldVisitProblems = true;
shouldVisitDeclarations = true;
shouldVisitExpressions = true;
shouldVisitStatements = true;
shouldVisitTypeIds = true;
}
@Override
public int visit(IASTProblem problem) {
addWarningToState();
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTDeclaration declaration) {
if (declaration instanceof IASTProblemDeclaration) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTExpression expression) {
if (expression instanceof IASTProblemExpression) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTStatement statement) {
if (statement instanceof IASTProblemStatement) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
@Override
public int visit(IASTTypeId typeId) {
if (typeId instanceof IASTProblemTypeId) {
addWarningToState();
}
return ASTVisitor.PROCESS_CONTINUE;
}
public boolean hasProblem() {
return problemFound;
}
private void addWarningToState() {
if (!problemFound) {
status.addWarning(Messages.Refactoring_CompileErrorInTU);
problemFound = true;
}
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2011 Google, Inc and others.
* Copyright (c) 2010, 2012 Google, Inc 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
@ -13,11 +13,10 @@ package org.eclipse.cdt.internal.ui.refactoring;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ui.services.IDisposable;
import org.eclipse.ltk.core.refactoring.RefactoringContext;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -32,13 +31,13 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
/**
* Cache containing ASTs for the translation units participating in refactoring.
* The cache object has to be disposed of after use. Failure to do so may cause
* loss of index lock.
* A disposable context for C/C++ refactoring operations. Contains cache of ASTs of the translation
* units participating in refactoring. The context object has to be disposed of after use. Failure
* to do so may cause loss of index lock.
* <p>
* This class is not thread-safe.
*/
public class RefactoringASTCache implements IDisposable {
public class CRefactoringContext extends RefactoringContext {
private static final int PARSE_MODE = ITranslationUnit.AST_SKIP_ALL_HEADERS
| ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT
| ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS
@ -47,9 +46,10 @@ public class RefactoringASTCache implements IDisposable {
private final Map<ITranslationUnit, IASTTranslationUnit> fASTCache;
private IIndex fIndex;
private IASTTranslationUnit fSharedAST;
private boolean fDisposed;
public RefactoringASTCache() {
public CRefactoringContext(CRefactoring2 refactoring) {
super(refactoring);
refactoring.setContext(this);
fASTCache = new ConcurrentHashMap<ITranslationUnit, IASTTranslationUnit>();
}
@ -69,7 +69,8 @@ public class RefactoringASTCache implements IDisposable {
*/
public IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm)
throws CoreException, OperationCanceledException {
Assert.isTrue(!fDisposed, "RefactoringASTCache is already disposed"); //$NON-NLS-1$
if (isDisposed())
throw new IllegalStateException("CRefactoringContext is already disposed."); //$NON-NLS-1$
getIndex(); // Make sure the index is locked.
if (pm != null && pm.isCanceled())
throw new OperationCanceledException();
@ -108,7 +109,8 @@ public class RefactoringASTCache implements IDisposable {
* @return The index.
*/
public IIndex getIndex() throws CoreException, OperationCanceledException {
Assert.isTrue(!fDisposed, "RefactoringASTCache is already disposed"); //$NON-NLS-1$
if (isDisposed())
throw new IllegalStateException("CRefactoringContext is already disposed."); //$NON-NLS-1$
if (fIndex == null) {
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
IIndex index = CCorePlugin.getIndexManager().getIndex(projects);
@ -122,25 +124,27 @@ public class RefactoringASTCache implements IDisposable {
return fIndex;
}
/**
* @see IDisposable#dispose()
*/
@Override
public void dispose() {
Assert.isTrue(!fDisposed, "RefactoringASTCache.dispose() called more than once"); //$NON-NLS-1$
fDisposed = true;
if (isDisposed())
throw new IllegalStateException("CRefactoringContext.dispose() called more than once."); //$NON-NLS-1$
if (fSharedAST != null) {
ASTProvider.getASTProvider().releaseSharedAST(fSharedAST);
}
if (fIndex != null) {
fIndex.releaseReadLock();
}
super.dispose();
}
private boolean isDisposed() {
return getRefactoring() == null;
}
@Override
protected void finalize() throws Throwable {
if (!fDisposed)
CUIPlugin.logError("RefactoringASTCache was not disposed"); //$NON-NLS-1$
if (!isDisposed())
CUIPlugin.logError("CRefactoringContext was not disposed"); //$NON-NLS-1$
super.finalize();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2009, 2012 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
@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software (IFS)- initial API and implementation
* Institute for Software (IFS)- initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
@ -28,7 +29,10 @@ public abstract class CRefactoringContribution extends RefactoringContribution {
@SuppressWarnings("rawtypes")
@Override
public Map retrieveArgumentMap(RefactoringDescriptor descriptor) {
if (descriptor instanceof CRefactoringDescription) {
if (descriptor instanceof CRefactoringDescriptor) {
CRefactoringDescriptor refDesc = (CRefactoringDescriptor) descriptor;
return refDesc.getParameterMap();
} if (descriptor instanceof CRefactoringDescription) {
CRefactoringDescription refDesc = (CRefactoringDescription) descriptor;
return refDesc.getParameterMap();
} else {

View file

@ -29,16 +29,20 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
/**
* @author Emanuel Graf IFS
* @deprecated Use {@link CRefactoringDescriptor} instead.
*/
@Deprecated
public abstract class CRefactoringDescription extends RefactoringDescriptor {
public static final String FILE_NAME = "fileName"; //$NON-NLS-1$
public static final String SELECTION = "selection"; //$NON-NLS-1$
protected Map<String, String> arguments;
public CRefactoringDescription(String id, String project, String description, String comment, int flags,
Map<String, String> arguments) {
public CRefactoringDescription(String id, String project, String description, String comment,
int flags, Map<String, String> arguments) {
super(id, project, description, comment, flags);
this.arguments = arguments;
}
@ -48,35 +52,31 @@ public abstract class CRefactoringDescription extends RefactoringDescriptor {
}
protected ISelection getSelection() throws CoreException {
ISelection selection;
String selectStrings[] = arguments.get(SELECTION).split(","); //$NON-NLS-1$
if (selectStrings.length >= 2) {
int offset = Integer.parseInt(selectStrings[0]);
int length = Integer.parseInt(selectStrings[1]);
selection = new TextSelection(offset, length);
} else {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$
if (selectStrings.length < 2) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal selection")); //$NON-NLS-1$
}
return selection;
int offset = Integer.parseInt(selectStrings[0]);
int length = Integer.parseInt(selectStrings[1]);
return new TextSelection(offset, length);
}
protected ICProject getCProject() throws CoreException {
ICProject proj;
IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject());
proj = CoreModel.getDefault().create(iProject);
if (proj == null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject());
ICProject cProject = CoreModel.getDefault().create(project);
if (cProject == null) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Unknown Project")); //$NON-NLS-1$
}
return proj;
return cProject;
}
protected IFile getFile() throws CoreException {
IFile file;
try {
file = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI(arguments.get(FILE_NAME)))[0];
String filename = arguments.get(FILE_NAME);
return ResourceLookup.selectFileForLocationURI(new URI(filename),
ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()));
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, e.getMessage(), e));
}
return file;
}
}

View file

@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (c) 2009, 2012 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 (IFS)- initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
/**
* @author Emanuel Graf IFS
*/
public abstract class CRefactoringDescriptor extends RefactoringDescriptor {
public static final String FILE_NAME = "fileName"; //$NON-NLS-1$
public static final String SELECTION = "selection"; //$NON-NLS-1$
protected Map<String, String> arguments;
public CRefactoringDescriptor(String id, String project, String description, String comment,
int flags, Map<String, String> arguments) {
super(id, project, description, comment, flags);
this.arguments = arguments;
}
public Map<String, String> getParameterMap() {
return arguments;
}
@Override
public abstract CRefactoring2 createRefactoring(RefactoringStatus status) throws CoreException;
@Override
public CRefactoringContext createRefactoringContext(RefactoringStatus status) throws CoreException {
CRefactoring2 refactoring= createRefactoring(status);
if (refactoring == null)
return null;
return new CRefactoringContext(refactoring);
}
protected ISelection getSelection() throws CoreException {
ISelection selection;
String selectStrings[] = arguments.get(SELECTION).split(","); //$NON-NLS-1$
if (selectStrings.length >= 2) {
int offset = Integer.parseInt(selectStrings[0]);
int length = Integer.parseInt(selectStrings[1]);
selection = new TextSelection(offset, length);
} else {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID,
Messages.CRefactoringDescriptor_illegal_selection));
}
return selection;
}
protected ICProject getCProject() throws CoreException {
String projectName = getProject();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
ICProject cProject = CoreModel.getDefault().create(project);
if (cProject == null) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID,
NLS.bind(Messages.CRefactoringDescriptor_unknown_project, projectName)));
}
return cProject;
}
protected IFile getFile() throws CoreException {
try {
String filename = arguments.get(FILE_NAME);
return ResourceLookup.selectFileForLocationURI(new URI(filename),
ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()));
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, e.getMessage(), e));
}
}
protected ITranslationUnit getTranslationUnit() throws CoreException {
try {
String filename = arguments.get(FILE_NAME);
return CoreModelUtil.findTranslationUnitForLocation(new URI(filename), getCProject());
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, e.getMessage(), e));
}
}
}

View file

@ -31,6 +31,8 @@ public final class Messages extends NLS {
public static String CreateFileChange_FileExists;
public static String CRefactoring_FileNotFound;
public static String CRefactoring_checking_final_conditions;
public static String CRefactoringDescriptor_unknown_project;
public static String CRefactoringDescriptor_illegal_selection;
public static String Refactoring_SelectionNotValid;
public static String Refactoring_CantLoadTU;
public static String Refactoring_Ambiguity;

View file

@ -26,6 +26,8 @@ CreateFileChange_UnknownLoc=Unknown location: {0}
CreateFileChange_FileExists=File already exists: {0}
CRefactoring_FileNotFound=The file {0} is not on the build path of a C/C++ project.
CRefactoring_checking_final_conditions=Checking preconditions...
CRefactoringDescriptor_unknown_project=Project ''{0}'' does not exist of is not a C/C++ project.
CRefactoringDescriptor_illegal_selection=Illegal selection.
Refactoring_SelectionNotValid=Selection is not valid.
Refactoring_CantLoadTU=Can not load translation unit.
Refactoring_Ambiguity=Translation unit is ambiguous.

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
@ -17,10 +17,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
/**
* Associate a name with a visibility and holds a list of used names.
*
*/
public class NameNVisibilityInformation {
private String name = ""; //$NON-NLS-1$
private VisibilityEnum visibility = VisibilityEnum.v_public;
private final ArrayList<String> usedNames = new ArrayList<String>();
@ -52,5 +50,4 @@ public class NameNVisibilityInformation {
public void addNamesToUsedNames(ArrayList<String> names) {
usedNames.addAll(names);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc and others.
* Copyright (c) 2011, 2012 Google, Inc 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
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -23,27 +24,26 @@ import org.eclipse.cdt.core.model.ICProject;
public abstract class RefactoringRunner2 {
protected final ISelection selection;
protected final ICElement element;
protected final IShellProvider shellProvider;
protected final ICProject project;
protected final RefactoringStarter starter;
private final IShellProvider shellProvider;
public RefactoringRunner2(ICElement element, ISelection selection, IShellProvider shellProvider,
ICProject cProject) {
this.selection = selection;
this.element= element;
this.shellProvider= shellProvider;
this.project = cProject;
this.starter = new RefactoringStarter();
this.shellProvider= shellProvider;
}
public final void run() {
RefactoringASTCache astCache = new RefactoringASTCache();
public abstract void run();
protected final void run(RefactoringWizard wizard, CRefactoring2 refactoring, int saveMode) {
CRefactoringContext context = new CRefactoringContext(refactoring);
try {
run(astCache);
RefactoringStarter starter = new RefactoringStarter();
starter.activate(wizard, shellProvider.getShell(), refactoring.getName(), saveMode);
} finally {
astCache.dispose();
context.dispose();
}
}
protected abstract void run(RefactoringASTCache astCache);
}

View file

@ -11,16 +11,14 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.swt.widgets.Shell;
/**
* A helper class to activate the UI of a refactoring
* A helper class to activate the UI of a refactoring.
*/
public class RefactoringStarter {
private RefactoringStatus fStatus;

View file

@ -1,14 +1,13 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 Google and others. All rights reserved. This program and
* Copyright (c) 2008, 2012 Google 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:
* Google - initial API and implementation
* Tom Ball (Google) - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.ArrayList;
@ -16,7 +15,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@ -27,6 +25,7 @@ import org.eclipse.jface.text.Region;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.text.edits.TextEditGroup;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -47,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
@ -55,6 +55,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
@ -66,7 +67,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
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.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
@ -82,7 +83,7 @@ import org.eclipse.cdt.internal.ui.util.NameComposer;
*
* @author Tom Ball
*/
public class ExtractLocalVariableRefactoring extends CRefactoring {
public class ExtractLocalVariableRefactoring extends CRefactoring2 {
public static final String ID =
"org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$
@ -90,10 +91,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
private final NameNVisibilityInformation info;
private NodeContainer container;
public ExtractLocalVariableRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info,
ICProject project) {
super(file, selection, null, project);
this.info = info;
public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) {
super(element, selection, project);
info = new NameNVisibilityInformation();
name = Messages.ExtractLocalVariable;
}
@ -101,54 +101,47 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException {
SubMonitor sm = SubMonitor.convert(pm, 9);
try {
lockIndex();
try {
RefactoringStatus status = super.checkInitialConditions(sm.newChild(6));
if (status.hasError()) {
return status;
}
container = findAllExpressions();
if (container.size() < 1) {
initStatus.addFatalError(Messages.ExpressionMustBeSelected);
return initStatus;
}
sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region);
if (!oneMarked) {
if (target == null) {
initStatus.addFatalError(Messages.NoExpressionSelected);
} else {
initStatus.addFatalError(Messages.TooManyExpressionsSelected);
}
return initStatus;
}
sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
sm.worked(1);
info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1);
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
sm.worked(1);
info.setName(guessTempName());
sm.done();
} finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
RefactoringStatus status = super.checkInitialConditions(sm.newChild(6));
if (status.hasError()) {
return status;
}
container = findAllExpressions(pm);
if (container.isEmpty()) {
initStatus.addFatalError(Messages.ExpressionMustBeSelected);
return initStatus;
}
sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
boolean oneMarked = selectedRegion != null && isOneMarked(container.getNodesToWrite(), selectedRegion);
if (!oneMarked) {
initStatus.addFatalError(target == null ?
Messages.NoExpressionSelected : Messages.TooManyExpressionsSelected);
return initStatus;
}
sm.worked(1);
if (isProgressMonitorCanceld(sm, initStatus))
return initStatus;
sm.worked(1);
container.getNames(); //XXX Is this needed?
sm.worked(1);
info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1);
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), refactoringContext, sm);
sm.worked(1);
info.setName(guessTempName());
sm.done();
return initStatus;
}
@ -157,9 +150,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
if (comTypeSpec != null) {
for (IASTDeclaration dec : comTypeSpec.getMembers()) {
if (dec instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) dec;
for (IASTDeclaration decl : comTypeSpec.getMembers()) {
if (decl instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) decl;
for (IASTDeclarator decor : simpDec.getDeclarators()) {
names.add(decor.getName().getRawSignature());
}
@ -169,6 +162,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return names;
}
@Override
protected RefactoringStatus checkFinalConditions(IProgressMonitor subProgressMonitor,
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
return new RefactoringStatus();
}
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) {
if (funcDef != null) {
IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
@ -191,9 +190,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
for (IASTNode node : selectedNodes) {
if (node instanceof IASTExpression) {
IASTExpression expression = (IASTExpression) node;
boolean isInSameFileSelection =
SelectionHelper.isInSameFileSelection(textSelection, expression, file);
if (isInSameFileSelection && isExpressionInSelection(expression, textSelection)) {
if (expression.isPartOfTranslationUnitFile() &&
isExpressionInSelection(expression, textSelection)) {
if (target == null) {
target = expression;
oneMarked = true;
@ -208,11 +206,11 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
private boolean isExpressionInSelection(IASTExpression expression, Region selection) {
IASTFileLocation location = expression.getFileLocation();
int e1 = location.getNodeOffset();
int e2 = location.getNodeOffset() + location.getNodeLength();
int s1 = selection.getOffset();
int s2 = selection.getOffset() + selection.getLength();
return e1 >= s1 && e2 <= s2;
int expressionStart = location.getNodeOffset();
int expressionEnd = expressionStart + location.getNodeLength();
int selectionStart = selection.getOffset();
int selectionEnd = selectionStart + selection.getLength();
return expressionStart >= selectionStart && expressionEnd <= selectionEnd;
}
private boolean isTargetChild(IASTExpression child) {
@ -228,23 +226,28 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return false;
}
private NodeContainer findAllExpressions() {
private NodeContainer findAllExpressions(IProgressMonitor pm)
throws OperationCanceledException, CoreException {
final NodeContainer container = new NodeContainer();
ast.accept(new ASTVisitor() {
{
shouldVisitExpressions = true;
}
@Override
public int visit(IASTExpression expression) {
if (SelectionHelper.isSelectedFile(region, expression, file)) {
container.add(expression);
return PROCESS_SKIP;
IASTTranslationUnit ast = getAST(tu, pm);
if (ast != null) {
ast.accept(new ASTVisitor() {
{
shouldVisitExpressions = true;
}
return super.visit(expression);
}
});
@Override
public int visit(IASTExpression expression) {
if (expression.isPartOfTranslationUnitFile() &&
SelectionHelper.isExpressionWhollyInSelection(selectedRegion, expression)) {
container.add(expression);
return PROCESS_SKIP;
}
return super.visit(expression);
}
});
}
return container;
}
@ -252,29 +255,21 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException {
try {
lockIndex();
try {
String variableName = info.getName();
TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable);
String variableName = info.getName();
TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable);
// Define temporary variable declaration and insert it
IASTStatement declInsertPoint = getParentStatement(target);
IASTDeclarationStatement declaration = getVariableNodes(variableName);
declaration.setParent(declInsertPoint.getParent());
ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast);
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
// Define temporary variable declaration and insert it
IASTStatement declInsertPoint = getParentStatement(target);
IASTTranslationUnit ast = getAST(tu, pm);
IASTDeclarationStatement declaration = getVariableNodes(ast, variableName);
declaration.setParent(declInsertPoint.getParent());
ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast);
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
// Replace target with reference to temporary variable
CPPASTIdExpression idExpression =
new CPPASTIdExpression(new CPPASTName(variableName.toCharArray()));
rewriter.replace(target, idExpression, editGroup);
} finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// Replace target with reference to temporary variable
CPPASTIdExpression idExpression =
new CPPASTIdExpression(new CPPASTName(variableName.toCharArray()));
rewriter.replace(target, idExpression, editGroup);
}
private IASTStatement getParentStatement(IASTNode node) {
@ -286,8 +281,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return null;
}
private IASTDeclarationStatement getVariableNodes(String newName) {
INodeFactory factory = this.ast.getASTNodeFactory();
private IASTDeclarationStatement getVariableNodes(IASTTranslationUnit ast, String newName) {
INodeFactory factory = ast.getASTNodeFactory();
IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null);
@ -438,7 +433,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
}
}
}
});
}
if (guessedTempNames.isEmpty()) {
@ -491,7 +485,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IBinding[] bindings = scope.find(name);
return bindings == null || bindings.length == 0;
}
return true; // no name references found
return true; // No name references found
}
private String makeTempName(List<String> usedNames, IScope scope) {
@ -510,16 +504,20 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap();
RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescription(project.getProject().getName(),
RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescriptor(project.getProject().getName(),
"Extract Local Variable Refactoring", "Extract " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$
return desc;
}
private Map<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractLocalVariableRefactoringDescription.NAME, info.getName());
arguments.put(CRefactoringDescription.FILE_NAME, tu.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$
arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName());
return arguments;
}
public NameNVisibilityInformation getRefactoringInfo() {
return info;
}
}

View file

@ -27,7 +27,7 @@ public class ExtractLocalVariableRefactoringContribution extends CRefactoringCon
public RefactoringDescriptor createDescriptor(String id, String project, String description,
String comment, Map arguments, int flags) throws IllegalArgumentException {
if (id.equals(ExtractLocalVariableRefactoring.ID)) {
return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments);
return new ExtractLocalVariableRefactoringDescriptor(project, description, comment, arguments);
} else {
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2009, 2012 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
@ -7,51 +7,42 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software (IFS)- initial API and implementation
* Institute for Software (IFS)- initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
/**
* @author Emanuel Graf IFS
*
*/
public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription {
public class ExtractLocalVariableRefactoringDescriptor extends CRefactoringDescriptor {
static protected final String NAME = "name"; //$NON-NLS-1$
public ExtractLocalVariableRefactoringDescription(String project, String description,
public ExtractLocalVariableRefactoringDescriptor(String project, String description,
String comment, Map<String, String> arguments) {
super(ExtractLocalVariableRefactoring.ID, project, description, comment,
RefactoringDescriptor.MULTI_CHANGE, arguments);
}
@Override
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
IFile file;
NameNVisibilityInformation info = new NameNVisibilityInformation();
ICProject proj;
info.setName(arguments.get(NAME));
proj = getCProject();
file = getFile();
public CRefactoring2 createRefactoring(RefactoringStatus status) throws CoreException {
ISelection selection = getSelection();
return new ExtractLocalVariableRefactoring(file, selection, info, proj);
ICProject proj = getCProject();
ExtractLocalVariableRefactoring refactoring =
new ExtractLocalVariableRefactoring(getTranslationUnit(), selection, proj);
refactoring.getRefactoringInfo().setName(arguments.get(NAME));
return refactoring;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2009 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -7,45 +7,38 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Tom Ball (Google) - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
/**
* Extract Local Variable refactoring runner.
*
* @author Tom Ball
*/
public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner {
public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner2 {
public ExtractLocalVariableRefactoringRunner(IFile file, ISelection selection,
public ExtractLocalVariableRefactoringRunner(ICElement element, ISelection selection,
IShellProvider shellProvider, ICProject cProject) {
super(file, selection, null, shellProvider, cProject);
super(element, selection, shellProvider, cProject);
}
@Override
public void run() {
NameNVisibilityInformation info = new NameNVisibilityInformation();
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, selection, info, project);
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
refactoring, info);
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
try {
operator.run(shellProvider.getShell(), refactoring.getName());
} catch (InterruptedException e) {
// initial condition checking got canceled by the user.
}
ExtractLocalVariableRefactoring refactoring =
new ExtractLocalVariableRefactoring(element, selection, project);
ExtractLocalVariableRefactoringWizard wizard =
new ExtractLocalVariableRefactoringWizard(refactoring);
run(wizard, refactoring, RefactoringSaveHelper.SAVE_NOTHING);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2011 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
@ -7,15 +7,13 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Tom Ball (Google) - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
/**
* The wizard page for Extract Local Variable Refactoring, creates the UI page.
*
@ -23,17 +21,15 @@ import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
*/
public class ExtractLocalVariableRefactoringWizard extends RefactoringWizard {
private InputPage page;
private final NameNVisibilityInformation info;
public ExtractLocalVariableRefactoringWizard(Refactoring refactoring,
NameNVisibilityInformation info) {
public ExtractLocalVariableRefactoringWizard(ExtractLocalVariableRefactoring refactoring) {
super(refactoring, WIZARD_BASED_USER_INTERFACE);
this.info = info;
}
@Override
protected void addUserInputPages() {
page = new InputPage(Messages.ExtractLocalVariable, info);
ExtractLocalVariableRefactoring refactoring = (ExtractLocalVariableRefactoring) getRefactoring();
page = new InputPage(Messages.ExtractLocalVariable, refactoring.getRefactoringInfo());
addPage(page);
}
}

View file

@ -50,7 +50,6 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter;
import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.InsertLocation;
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder;
import org.eclipse.cdt.internal.ui.refactoring.utils.Checks;
@ -93,8 +92,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
private InsertLocation definitionInsertLocation;
public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection,
ICProject project, RefactoringASTCache astCache) {
super(element, selection, project, astCache);
ICProject project) {
super(element, selection, project);
context = new GetterSetterContext();
}
@ -148,7 +147,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
}
private void initRefactoring(IProgressMonitor pm) throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = astCache.getAST(tu, null);
IASTTranslationUnit ast = getAST(tu, null);
context.selectedName = getSelectedName(ast);
IASTCompositeTypeSpecifier compositeTypeSpecifier = null;
if (context.selectedName != null) {
@ -279,7 +278,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
IASTSimpleDeclaration decl = context.existingFields.get(0);
MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder();
InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(),
astCache, pm);
refactoringContext, pm);
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.ITextEditor;
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
/**
@ -36,14 +36,13 @@ public class GenerateGettersAndSettersRefactoringRunner extends RefactoringRunne
}
@Override
public void run(RefactoringASTCache astCache) {
public void run() {
if (getActiveEditor() instanceof ITextEditor) {
GenerateGettersAndSettersRefactoring refactoring =
new GenerateGettersAndSettersRefactoring(element, selection, project, astCache);
GenerateGettersAndSettersRefactoringWizard wizard =
new GenerateGettersAndSettersRefactoring(element, selection, project);
RefactoringWizard wizard =
new GenerateGettersAndSettersRefactoringWizard(refactoring);
starter.activate(wizard, shellProvider.getShell(), refactoring.getName(),
RefactoringSaveHelper.SAVE_REFACTORING);
run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING);
}
}

View file

@ -9,6 +9,7 @@
* Contributors:
* Institute for Software - initial API and implementation
* Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
@ -59,7 +60,6 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.utils.Checks;
import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
@ -78,8 +78,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
private Map<IASTSimpleDeclaration, InsertLocation> insertLocations;
private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory();
public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project, RefactoringASTCache astCache) {
super(element, selection, project, astCache);
public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project) {
super(element, selection, project);
data = new ImplementMethodData();
methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder();
insertLocations = new HashMap<IASTSimpleDeclaration, InsertLocation>();
@ -99,7 +99,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
data.setMethodDeclarations(unimplementedMethodDeclarations);
if (selectedRegion.getLength() > 0) {
IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(selectedRegion, astCache.getAST(tu, pm));
IASTSimpleDeclaration methodDeclaration =
SelectionHelper.findFirstSelectedDeclaration(selectedRegion, getAST(tu, pm));
if (NodeHelper.isMethodDeclaration(methodDeclaration)) {
for (MethodToImplementConfig config : data.getMethodDeclarations()) {
if (config.getDeclaration() == methodDeclaration) {
@ -114,8 +115,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
return initStatus;
}
private List<IASTSimpleDeclaration> findUnimplementedMethodDeclarations(IProgressMonitor pm) throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = astCache.getAST(tu, pm);
private List<IASTSimpleDeclaration> findUnimplementedMethodDeclarations(IProgressMonitor pm)
throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = getAST(tu, pm);
final List<IASTSimpleDeclaration> list = new ArrayList<IASTSimpleDeclaration>();
ast.accept(new ASTVisitor() {
{
@ -151,8 +153,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
}
try {
IIndexName[] indexNames = astCache.getIndex().findNames(binding, IIndex.FIND_DEFINITIONS
| IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
IIndexName[] indexNames = getIndex().findNames(binding,
IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
if (indexNames.length == 0) {
return true;
}
@ -166,7 +168,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException {
throws CoreException, OperationCanceledException {
List<MethodToImplementConfig> methodsToImplement = data.getMethodsToImplement();
SubMonitor sm = SubMonitor.convert(pm, 4 * methodsToImplement.size());
for (MethodToImplementConfig config : methodsToImplement) {
@ -174,8 +176,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
}
}
protected void createDefinition(ModificationCollector collector,
MethodToImplementConfig config, IProgressMonitor subMonitor) throws CoreException, OperationCanceledException {
protected void createDefinition(ModificationCollector collector, MethodToImplementConfig config,
IProgressMonitor subMonitor) throws CoreException, OperationCanceledException {
if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
@ -228,7 +230,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
if (insertLocations.containsKey(methodDeclaration)) {
return insertLocations.get(methodDeclaration);
}
InsertLocation insertLocation = methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(), methodDeclaration.getParent(), astCache, subMonitor);
InsertLocation insertLocation =
methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(),
methodDeclaration.getParent(), refactoringContext, subMonitor);
if (insertLocation.getTranslationUnit() == null || NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) {
insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu);
@ -286,7 +290,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
int insertOffset = insertLocation.getInsertPosition();
return NameHelper.createQualifiedNameFor(
functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(),
insertLocation.getTranslationUnit(), insertOffset, astCache);
insertLocation.getTranslationUnit(), insertOffset, refactoringContext);
}
public ImplementMethodData getRefactoringData() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -9,17 +9,18 @@
* Contributors:
* Institute for Software - initial API and implementation
* Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
/**
* @author Lukas Felber
@ -32,15 +33,10 @@ public class ImplementMethodRefactoringRunner extends RefactoringRunner2 {
}
@Override
public void run(RefactoringASTCache astCache) {
ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(element, selection, project, astCache);
public void run() {
ImplementMethodRefactoring refactoring =
new ImplementMethodRefactoring(element, selection, project);
ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring);
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
try {
operator.run(shellProvider.getShell(), refactoring.getName());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING);
}
}

View file

@ -34,7 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder;
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
@ -53,7 +53,7 @@ public class MethodDefinitionInsertLocationFinder {
new HashMap<IASTSimpleDeclaration, IASTName>();
public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation,
IASTNode parent, RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException {
IASTNode parent, CRefactoringContext astCache, IProgressMonitor pm) throws CoreException {
IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
InsertLocation insertLocation = new InsertLocation();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2011, 2012 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
@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation
* Martin Schwab & Thomas Kallenberg - initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -18,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -29,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
* are skipped during search.
*/
public class DeclaratorFinder {
private IASTFunctionDeclarator foundDeclarator;
public DeclaratorFinder(ITextSelection selection, IASTTranslationUnit unit) {
@ -47,16 +49,15 @@ public class DeclaratorFinder {
return foundDeclarator.getName();
}
private IASTFunctionDeclarator findDeclaratorInSelection(
ITextSelection selection,
private IASTFunctionDeclarator findDeclaratorInSelection(ITextSelection selection,
IASTTranslationUnit unit) {
IASTNode firstNodeInsideSelection = unit.getNodeSelector(null)
.findFirstContainedNode(selection.getOffset(),
selection.getLength());
IASTNodeSelector nodeSelector = unit.getNodeSelector(null);
IASTNode firstNodeInsideSelection =
nodeSelector.findFirstContainedNode(selection.getOffset(), selection.getLength());
IASTFunctionDeclarator declarator = findDeclaratorInAncestors(firstNodeInsideSelection);
if (declarator == null) {
firstNodeInsideSelection = unit.getNodeSelector(null).findEnclosingNode(
firstNodeInsideSelection = nodeSelector.findEnclosingNode(
selection.getOffset(), selection.getLength());
declarator = findDeclaratorInAncestors(firstNodeInsideSelection);
}
@ -65,6 +66,9 @@ ITextSelection selection,
private IASTFunctionDeclarator findDeclaratorInAncestors(IASTNode node) {
while (node != null) {
if (node instanceof IASTProblemStatement) {
return null;
}
IASTFunctionDeclarator declarator = extractDeclarator(node);
if (node instanceof ICPPASTTemplateDeclaration) {
declarator = extractDeclarator(((ICPPASTTemplateDeclaration) node).getDeclaration());
@ -93,8 +97,7 @@ ITextSelection selection,
throw new NotSupportedException(Messages.DeclaratorFinder_MultipleDeclarators);
}
if (declarators.length == 1 &&
declarators[0] instanceof IASTFunctionDeclarator)
if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator)
return (IASTFunctionDeclarator) declarators[0];
}
return null;

View file

@ -65,19 +65,18 @@ public class ToggleFileCreator {
}
return result;
}
public void createNewFile() {
CreateFileChange change;
String filename = getNewFileName();
try {
change = new CreateFileChange(filename, new Path(getPath() + filename),
CreateFileChange change = new CreateFileChange(filename, new Path(getPath() + filename),
EMPTY_STRING, context.getSelectionFile().getCharset());
change.perform(new NullProgressMonitor());
} catch (CoreException e) {
throw new NotSupportedException(Messages.ToggleFileCreator_CanNotCreateNewFile);
}
}
public boolean askUserForFileCreation(final ToggleRefactoringContext context) {
if (context.isSettedDefaultAnswer()) {
return context.getDefaultAnswer();

View file

@ -336,7 +336,7 @@ public class ToggleNodeHelper extends NodeHelper {
for (IIndexFile thisFile : thisFileVariants) {
for (IIndexInclude include : projectIndex.findIncludes(thisFile)) {
if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) {
if (include.getIncludesLocation() == null){
if (include.getIncludesLocation() == null) {
throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$
}
String loc = include.getIncludesLocation().getFullPath();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2011, 2012 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
@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation
* Martin Schwab & Thomas Kallenberg - initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -38,17 +39,16 @@ import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
* position.
*/
public class ToggleRefactoring extends CRefactoring {
private ITextSelection selection;
private IToggleRefactoringStrategy strategy;
protected ToggleRefactoringContext context;
private ToggleRefactoringContext context;
private IIndex fIndex;
public ToggleRefactoring(IFile file, ITextSelection selection, ICProject proj) {
super(file, selection, null, proj);
if (selection == null || file == null || project == null)
initStatus.addFatalError(Messages.ToggleRefactoring_InvalidSelection);
if (!IDE.saveAllEditors(new IResource[] {ResourcesPlugin.getWorkspace().getRoot()}, false))
if (!IDE.saveAllEditors(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, false))
initStatus.addFatalError(Messages.ToggleRefactoring_CanNotSaveFiles);
this.selection = selection;
}
@ -97,4 +97,8 @@ public class ToggleRefactoring extends CRefactoring {
protected RefactoringDescriptor getRefactoringDescriptor() {
return new EmptyRefactoringDescription();
}
public ToggleRefactoringContext getContext() {
return context;
}
}

View file

@ -35,7 +35,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
public class DefinitionFinder {
public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration,
RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException {
CRefactoringContext astCache, IProgressMonitor pm) throws CoreException {
IIndex index = astCache.getIndex();
IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0];
if (index == null) {
@ -58,7 +58,7 @@ public class DefinitionFinder {
}
private static IASTName getDefinition(IIndexBinding binding,
RefactoringASTCache astCache, IIndex index, IProgressMonitor pm) throws CoreException {
CRefactoringContext astCache, IIndex index, IProgressMonitor pm) throws CoreException {
Set<String> searchedFiles = new HashSet<String>();
List<IASTName> definitions = new ArrayList<IASTName>();
IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true);
@ -91,7 +91,7 @@ public class DefinitionFinder {
}
private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu,
RefactoringASTCache astCache, List<IASTName> definitions, IProgressMonitor pm)
CRefactoringContext astCache, List<IASTName> definitions, IProgressMonitor pm)
throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = astCache.getAST(tu, pm);
findDefinitionsInAST(binding, ast, tu, definitions);

View file

@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* Helps with IASTNames.
@ -68,7 +68,7 @@ public class NameHelper {
*/
public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName,
ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu,
int insertLocation, RefactoringASTCache astCache) throws CoreException {
int insertLocation, CRefactoringContext astCache) throws CoreException {
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu,

View file

@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleTypeTemplatePara
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* Helper class to find Namespace informations.
@ -48,7 +48,7 @@ public class NamespaceHelper {
* @return ICPPASTQualifiedName with the names of all namespaces
* @throws CoreException
*/
public static ICPPASTQualifiedName getSurroundingNamespace(final ITranslationUnit translationUnit, final int offset, RefactoringASTCache astCache)
public static ICPPASTQualifiedName getSurroundingNamespace(final ITranslationUnit translationUnit, final int offset, CRefactoringContext astCache)
throws CoreException {
final CPPASTQualifiedName qualifiedName = new CPPASTQualifiedName();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -8,15 +8,18 @@
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.utils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -30,7 +33,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
@ -38,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/**
* General class for common Node operations.
@ -99,7 +107,72 @@ public class NodeHelper {
return null;
}
public static MethodContext findMethodContext(IASTNode node, IIndex index) throws CoreException{
public static MethodContext findMethodContext(IASTNode node, CRefactoringContext astCache,
IProgressMonitor pm) throws CoreException {
IASTTranslationUnit translationUnit = node.getTranslationUnit();
boolean found = false;
MethodContext context = new MethodContext();
context.setType(MethodContext.ContextType.NONE);
IASTName name = null;
while (node != null && !found) {
node = node.getParent();
if (node instanceof IASTFunctionDeclarator) {
name = ((IASTFunctionDeclarator) node).getName();
found = true;
context.setType(MethodContext.ContextType.FUNCTION);
} else if (node instanceof IASTFunctionDefinition) {
name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()).getName();
found = true;
context.setType(MethodContext.ContextType.FUNCTION);
}
}
getMethodContexWithIndex(astCache, translationUnit, name, context, pm);
return context;
}
private static void getMethodContexWithIndex(CRefactoringContext astCache,
IASTTranslationUnit ast, IASTName name, MethodContext context, IProgressMonitor pm)
throws CoreException {
if (name instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
context.setMethodQName(qname);
}
IBinding binding = name.resolveBinding();
if (binding instanceof ICPPMethod) {
context.setType(MethodContext.ContextType.METHOD);
IIndex index = astCache.getIndex();
IIndexName[] declarations = index.findDeclarations(binding);
if (declarations.length == 0) {
context.setMethodDeclarationName(name);
} else {
IASTFileLocation tuFileLocation = ast.getFileLocation();
ICProject cProject = ast.getOriginatingTranslationUnit().getCProject();
for (IIndexName decl : declarations) {
IASTTranslationUnit ast2 = ast;
if (!tuFileLocation.equals(decl.getFileLocation())) {
IIndexFileLocation fileLocation = decl.getFile().getLocation();
ITranslationUnit locTu =
CoreModelUtil.findTranslationUnitForLocation(fileLocation, cProject);
astCache.getAST(locTu, pm);
}
IASTName declName = DeclarationFinder.findDeclarationInTranslationUnit(ast2, decl);
if (declName != null) {
IASTNode methodDeclaration = declName.getParent().getParent();
if (methodDeclaration instanceof IASTSimpleDeclaration ||
methodDeclaration instanceof IASTFunctionDefinition) {
context.setMethodDeclarationName(declName);
}
}
}
}
}
}
/**
* @deprecated Use #findMethodContext(IASTNode, RefactoringASTCache, IProgressMonitor pm)
*/
@Deprecated
public static MethodContext findMethodContext(IASTNode node, IIndex index) throws CoreException {
IASTTranslationUnit translationUnit = node.getTranslationUnit();
boolean found = false;
MethodContext context = new MethodContext();
@ -125,23 +198,7 @@ public class NodeHelper {
return context;
}
private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context,
IASTName name) {
if (name instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
context.setMethodQName(qname);
IBinding bind = qname.resolveBinding();
IASTName[] decl = translationUnit.getDeclarationsInAST(bind);
for (IASTName tmpname : decl) {
IASTNode methodDefinition = tmpname.getParent().getParent();
if (methodDefinition instanceof IASTSimpleDeclaration) {
context.setMethodDeclarationName(tmpname);
context.setType(MethodContext.ContextType.METHOD);
}
}
}
}
@Deprecated
private static void getMethodContexWithIndex(IIndex index, IASTTranslationUnit translationUnit,
MethodContext context, IASTName name) throws CoreException {
IBinding bind = name.resolveBinding();
@ -174,6 +231,23 @@ public class NodeHelper {
}
}
private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context,
IASTName name) {
if (name instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
context.setMethodQName(qname);
IBinding bind = qname.resolveBinding();
IASTName[] decl = translationUnit.getDeclarationsInAST(bind);
for (IASTName tmpname : decl) {
IASTNode methodDefinition = tmpname.getParent().getParent();
if (methodDefinition instanceof IASTSimpleDeclaration) {
context.setMethodDeclarationName(tmpname);
context.setType(MethodContext.ContextType.METHOD);
}
}
}
}
public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) {
while (node != null) {
if (node instanceof IASTCompoundStatement) {

View file

@ -1,18 +1,17 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 Wind River Systems, Inc.
* Copyright (c) 2005, 2011 Wind River Systems, Inc.
* 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:
* Markus Schorn - initial API and implementation
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.refactoring.actions;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.window.IShellProvider;
@ -38,9 +37,8 @@ public class ExtractLocalVariableAction extends RefactoringAction {
@Override
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
IResource res= wc.getResource();
if (res instanceof IFile) {
new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run();
if (wc.getResource() != null) {
new ExtractLocalVariableRefactoringRunner(wc, selection, shellProvider, wc.getCProject()).run();
}
}