1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 08:15:48 +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

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

View file

@ -590,6 +590,10 @@ public class ChangeGenerator extends ASTVisitor {
} }
} }
newNode.accept(writer); 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) { if (prevNode != null) {
IASTNode nextNode = getNextSiblingOrPreprocessorNode(prevNode); 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 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=A.cpp filename=A.cpp
fatalerrors=1 fatalerror=true
//@A.cpp //@A.cpp
int /*$*/main/*$$*/() { int /*$*/main/*$$*/() {
int i = 2; 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. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -19,14 +19,14 @@ import java.util.Properties;
import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.NullProgressMonitor; 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.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.RefactoringDescriptorProxy;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
@ -39,8 +39,7 @@ public class RefactoringHistoryTest extends RefactoringTest {
@Override @Override
protected void configureRefactoring(Properties refactoringProperties) { protected void configureRefactoring(Properties refactoringProperties) {
scriptFile = fileMap.get(refactoringProperties.getProperty( scriptFile = fileMap.get(refactoringProperties.getProperty("scriptFile", "refScript.xml"));
"scriptFile", "refScript.xml"));
} }
@Override @Override
@ -52,25 +51,12 @@ public class RefactoringHistoryTest extends RefactoringTest {
new ByteArrayInputStream(xmlSource.getBytes()), 0); new ByteArrayInputStream(xmlSource.getBytes()), 0);
for (RefactoringDescriptorProxy proxy : refHist.getDescriptors()) { for (RefactoringDescriptorProxy proxy : refHist.getDescriptors()) {
RefactoringStatus status = new RefactoringStatus(); 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()); assertTrue(status.isOK());
RefactoringStatus checkInitialConditions = ref.checkInitialConditions(NULL_PROGRESS_MONITOR); Refactoring refactoring = context.getRefactoring();
executeRefactoring(refactoring, context, false);
if (fatalError) {
assertConditionsFatalError(checkInitialConditions);
return;
} else {
assertConditionsOk(checkInitialConditions);
executeRefactoring(ref);
}
}
}
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); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -17,6 +17,10 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Properties; 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.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; 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.core.index.IIndexManager;
import org.eclipse.cdt.ui.testplugin.CTestPlugin; 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 * @author Emanuel Graf
*/ */
public abstract class RefactoringTest extends RefactoringBaseTest { public abstract class RefactoringTest extends RefactoringBaseTest {
private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$ private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$
protected String fileName; protected String fileName;
protected RefactoringASTCache astCache;
protected boolean fatalError; protected boolean fatalError;
protected int initialErrors;
protected int initialWarnings;
protected int finalWarnings;
protected int finalInfos;
public RefactoringTest(String name, Collection<TestSourceFile> files) { public RefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files); super(name, files);
@ -44,6 +54,62 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
protected abstract void configureRefactoring(Properties refactoringProperties); 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 @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@ -52,12 +118,10 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
CCorePlugin.getIndexManager().reindex(cproject); CCorePlugin.getIndexManager().reindex(cproject);
boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR); boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR);
assertTrue(joined); assertTrue(joined);
astCache = new RefactoringASTCache();
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
astCache.dispose();
super.tearDown(); 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.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.TextSelection;
import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring; 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.RefactoringDescriptorProxy;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; 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.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; 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.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. * Common base for refactoring tests.
@ -51,8 +59,9 @@ public abstract class RefactoringTestBase extends BaseTestCase {
private static final int INDEXER_TIMEOUT_SEC = 360; private static final int INDEXER_TIMEOUT_SEC = 360;
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
protected boolean createEmptyFiles = true;
protected boolean ascendingVisibilityOrder;
private boolean cpp = true; private boolean cpp = true;
private RefactoringASTCache astCache;
private ICProject cproject; private ICProject cproject;
private final Set<TestSourceFile> testFiles = new LinkedHashSet<TestSourceFile>(); private final Set<TestSourceFile> testFiles = new LinkedHashSet<TestSourceFile>();
private TestSourceFile selectedFile; private TestSourceFile selectedFile;
@ -70,6 +79,7 @@ public abstract class RefactoringTestBase extends BaseTestCase {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
resetPreferences();
cproject = cpp ? cproject = cpp ?
CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) :
CProjectHelper.createCProject(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(); reader.close();
if (!testFile.getSource().isEmpty()) { if (createEmptyFiles || !testFile.getSource().isEmpty()) {
TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()), TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()),
testFile.getSource()); testFile.getSource());
} }
@ -111,16 +121,15 @@ public abstract class RefactoringTestBase extends BaseTestCase {
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000,
NULL_PROGRESS_MONITOR)); NULL_PROGRESS_MONITOR));
astCache = new RefactoringASTCache();
} }
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
astCache.dispose();
if (cproject != null) { if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
NULL_PROGRESS_MONITOR); NULL_PROGRESS_MONITOR);
} }
resetPreferences();
super.tearDown(); super.tearDown();
} }
@ -134,17 +143,28 @@ public abstract class RefactoringTestBase extends BaseTestCase {
} }
private void executeRefactoring(boolean expectedSuccess) throws Exception { private void executeRefactoring(boolean expectedSuccess) throws Exception {
if (ascendingVisibilityOrder) {
getPreferenceStore().setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER,
ascendingVisibilityOrder);
}
if (historyScript != null) { if (historyScript != null) {
executeHistoryRefactoring(expectedSuccess); executeHistoryRefactoring(expectedSuccess);
return; return;
} }
Refactoring refactoring = createRefactoring(); 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, protected void executeRefactoring(Refactoring refactoring, RefactoringContext context,
boolean expectedSuccess) throws CoreException, Exception { boolean withUserInput, boolean expectedSuccess) throws CoreException, Exception {
try {
RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
if (!expectedSuccess) { if (!expectedSuccess) {
assertStatusFatalError(initialStatus); assertStatusFatalError(initialStatus);
@ -158,6 +178,10 @@ public abstract class RefactoringTestBase extends BaseTestCase {
assertStatusOk(finalStatus); assertStatusOk(finalStatus);
Change change = refactoring.createChange(NULL_PROGRESS_MONITOR); Change change = refactoring.createChange(NULL_PROGRESS_MONITOR);
change.perform(NULL_PROGRESS_MONITOR); change.perform(NULL_PROGRESS_MONITOR);
} finally {
if (context != null)
context.dispose();
}
} }
private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception { private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception {
@ -166,11 +190,11 @@ public abstract class RefactoringTestBase extends BaseTestCase {
RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory( RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory(
new ByteArrayInputStream(scriptSource.getBytes()), 0); new ByteArrayInputStream(scriptSource.getBytes()), 0);
for (RefactoringDescriptorProxy proxy : history.getDescriptors()) { for (RefactoringDescriptorProxy proxy : history.getDescriptors()) {
RefactoringDescriptor descriptor = proxy.requestDescriptor(NULL_PROGRESS_MONITOR);
RefactoringStatus status = new RefactoringStatus(); RefactoringStatus status = new RefactoringStatus();
Refactoring refactoring = RefactoringContext context = descriptor.createRefactoringContext(status);
proxy.requestDescriptor(NULL_PROGRESS_MONITOR).createRefactoring(status);
assertTrue(status.isOK()); 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())); 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() { protected TestSourceFile getHistoryScriptFile() {
return historyScript; return historyScript;
} }
@ -305,14 +336,21 @@ public abstract class RefactoringTestBase extends BaseTestCase {
} }
protected String getFileContents(IFile file) throws Exception { protected String getFileContents(IFile file) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents())); BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents(), "UTF-8"));
StringBuilder code = new StringBuilder(); StringBuilder buffer = new StringBuilder();
String line; char[] part= new char[2048];
while ((line = reader.readLine()) != null) { int read= 0;
code.append(line); while ((read= reader.read(part)) != -1)
code.append('\n'); buffer.append(part, 0, read);
}
reader.close(); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -16,14 +16,14 @@ package org.eclipse.cdt.ui.tests.refactoring;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; 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.extractfunction.ExtractFunctionRefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableTestSuite; 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.hidemethod.HideMethodTestSuite;
import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodTestSuite; 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.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; import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
/** /**
@ -36,12 +36,12 @@ public class RefactoringTestSuite extends TestSuite {
suite.addTest(UtilTestSuite.suite()); suite.addTest(UtilTestSuite.suite());
suite.addTest(RenameRegressionTests.suite()); suite.addTest(RenameRegressionTests.suite());
suite.addTest(ExtractFunctionRefactoringTest.suite()); suite.addTest(ExtractFunctionRefactoringTest.suite());
suite.addTest(ExtractConstantTestSuite.suite()); suite.addTest(ExtractConstantRefactoringTest.suite());
suite.addTest(HideMethodTestSuite.suite()); suite.addTest(HideMethodTestSuite.suite());
suite.addTest(GenerateGettersAndSettersTestSuite.suite()); suite.addTest(GenerateGettersAndSettersTest.suite());
suite.addTest(ImplementMethodTestSuite.suite()); suite.addTest(ImplementMethodTestSuite.suite());
suite.addTest(ExtractLocalVariableTestSuite.suite()); suite.addTest(ExtractLocalVariableTestSuite.suite());
suite.addTest(ToggleRefactoringTestSuite.suite()); suite.addTest(ToogleRefactoringTest.suite());
return 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,52 +8,788 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractconstant; package org.eclipse.cdt.ui.tests.refactoring.extractconstant;
import java.util.Collection; import junit.framework.Test;
import java.util.Properties;
import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
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.ExtractConstantInfo;
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring; import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
/** /**
* @author Emanuel Graf * Tests for Extract Constant refactoring.
*/ */
public class ExtractConstantRefactoringTest extends RefactoringTest { public class ExtractConstantRefactoringTest extends RefactoringTestBase {
protected VisibilityEnum visibility; private ExtractConstantInfo refactoringInfo;
private String extractedConstantName = "EXTRACTED";
private VisibilityEnum visibility = VisibilityEnum.v_private;
public ExtractConstantRefactoringTest(String name, Collection<TestSourceFile> files) { public ExtractConstantRefactoringTest() {
super(name, files); super();
}
public ExtractConstantRefactoringTest(String name) {
super(name);
}
public static Test suite() {
return suite(ExtractConstantRefactoringTest.class);
} }
@Override @Override
protected void runTest() throws Throwable { protected Refactoring createRefactoring() {
IFile refFile = project.getFile(fileName); refactoringInfo = new ExtractConstantInfo();
ExtractConstantInfo info = new ExtractConstantInfo(); return new ExtractConstantRefactoring(getSelectedFile(), getSelection(), refactoringInfo,
CRefactoring refactoring = new ExtractConstantRefactoring(refFile, selection, info, cproject); getCProject());
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);
} }
@Override @Override
protected void configureRefactoring(Properties refactoringProperties) { protected void simulateUserInput() {
visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_public.toString())); //$NON-NLS-1$ 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 junit.framework.Test;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
@ -59,25 +57,12 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
} }
@Override @Override
public void setUp() throws Exception { protected void resetPreferences() {
super.setUp(); super.resetPreferences();
resetPreferences(); getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT);
}
@Override
public void tearDown() throws Exception {
super.tearDown();
resetPreferences();
}
private void resetPreferences() {
getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER); getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER);
} }
private IPreferenceStore getPreferenceStore() {
return CUIPlugin.getDefault().getPreferenceStore();
}
@Override @Override
protected Refactoring createRefactoring() { protected Refactoring createRefactoring() {
refactoringInfo = new ExtractFunctionInformation(); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
@ -15,14 +16,12 @@ import java.util.Collection;
import java.util.Properties; import java.util.Properties;
import org.eclipse.core.resources.IFile; 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.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; 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; 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 { public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
protected String variableName; protected String variableName;
protected boolean fatalError;
public ExtractLocalVariableRefactoringTest(String name, Collection<TestSourceFile> files) { public ExtractLocalVariableRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files); super(name, files);
@ -40,22 +38,12 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
@Override @Override
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileName); IFile file = project.getFile(fileName);
NameNVisibilityInformation info = new NameNVisibilityInformation(); ICElement element = CoreModel.getDefault().create(file);
info.setName(variableName); ExtractLocalVariableRefactoring refactoring =
CRefactoring refactoring = new ExtractLocalVariableRefactoring( refFile, selection, info, cproject); new ExtractLocalVariableRefactoring(element, selection, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); refactoring.getRefactoringInfo().setName(variableName);
executeRefactoring(refactoring);
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);
compareFiles(fileMap); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,6 +8,7 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.hidemethod; package org.eclipse.cdt.ui.tests.refactoring.hidemethod;
@ -15,22 +16,17 @@ import java.util.Collection;
import java.util.Properties; import java.util.Properties;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
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.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; 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; import org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring;
/** /**
* @author Guido Zgraggen IFS * @author Guido Zgraggen IFS
*/ */
public class HideMethodRefactoringTest extends RefactoringTest { public class HideMethodRefactoringTest extends RefactoringTest {
private int warnings;
private int errors;
private int fatalerrors;
public HideMethodRefactoringTest(String name, Collection<TestSourceFile> files) { public HideMethodRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files); super(name, files);
@ -39,32 +35,15 @@ public class HideMethodRefactoringTest extends RefactoringTest {
@Override @Override
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileWithSelection); IFile refFile = project.getFile(fileWithSelection);
CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject); Refactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); executeRefactoring(refactoring);
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);
compareFiles(fileMap); compareFiles(fileMap);
} }
@Override @Override
protected void configureRefactoring(Properties refactoringProperties) { protected void configureRefactoring(Properties refactoringProperties) {
warnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$
errors = new Integer(refactoringProperties.getProperty("errors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ finalWarnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$
fatalerrors = new Integer(refactoringProperties.getProperty("fatalerrors", "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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -9,6 +9,7 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Marc-Andre Laperle * Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.implementmethod; package org.eclipse.cdt.ui.tests.refactoring.implementmethod;
@ -16,8 +17,6 @@ import java.util.Collection;
import java.util.Properties; import java.util.Properties;
import org.eclipse.core.resources.IFile; 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.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -31,9 +30,6 @@ import org.eclipse.cdt.internal.ui.refactoring.implementmethod.ImplementMethodRe
* @author Mirko Stocker * @author Mirko Stocker
*/ */
public class ImplementMethodRefactoringTest extends RefactoringTest { public class ImplementMethodRefactoringTest extends RefactoringTest {
protected int finalWarnings;
private int initialWarnings;
private int infos;
public ImplementMethodRefactoringTest(String name, Collection<TestSourceFile> files) { public ImplementMethodRefactoringTest(String name, Collection<TestSourceFile> files) {
super(name, files); super(name, files);
@ -43,28 +39,8 @@ public class ImplementMethodRefactoringTest extends RefactoringTest {
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
IFile refFile = project.getFile(fileName); IFile refFile = project.getFile(fileName);
ICElement element = CoreModel.getDefault().create(refFile); ICElement element = CoreModel.getDefault().create(refFile);
CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject, astCache); CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); executeRefactoring(refactoring);
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);
compareFiles(fileMap); compareFiles(fileMap);
} }
@ -72,6 +48,6 @@ public class ImplementMethodRefactoringTest extends RefactoringTest {
protected void configureRefactoring(Properties refactoringProperties) { protected void configureRefactoring(Properties refactoringProperties) {
finalWarnings = new Integer(refactoringProperties.getProperty("finalWarnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ 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$ 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Marc-Andre Laperle - Initial API and implementation * Marc-Andre Laperle - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.utils; package org.eclipse.cdt.ui.tests.refactoring.utils;
@ -14,16 +15,24 @@ import java.util.Collection;
import java.util.Properties; import java.util.Properties;
import org.eclipse.core.resources.IFile; 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.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; 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.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; 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; import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder;
public class DefinitionFinderTest extends RefactoringTest { public class DefinitionFinderTest extends RefactoringTest {
@ -39,14 +48,36 @@ public class DefinitionFinderTest extends RefactoringTest {
@Override @Override
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
IFile file = project.getFile(fileName); IFile file = project.getFile(fileName);
ICElement element = CCorePlugin.getDefault().getCoreModel().create(file); ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
if (element instanceof ITranslationUnit) { CRefactoring2 refactoring = new CRefactoring2(tu, null, tu.getCProject()) {
IASTTranslationUnit ast = astCache.getAST((ITranslationUnit) element, null); @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()) { for (IASTDeclaration declaration : ast.getDeclarations()) {
if (declaration instanceof IASTSimpleDeclaration) { 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.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.filesystem;bundle-version="[1.1.0,2.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.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.ltk.ui.refactoring;bundle-version="3.4.0",
org.eclipse.ui.navigator.resources;bundle-version="3.3.100" org.eclipse.ui.navigator.resources;bundle-version="3.3.100"
Bundle-ActivationPolicy: lazy 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.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 * 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, public static ITranslationUnit getPartnerTranslationUnit(ITranslationUnit tu,
RefactoringASTCache astCache) throws CoreException { CRefactoringContext astCache) throws CoreException {
ITranslationUnit partnerUnit= getPartnerFileFromFilename(tu); ITranslationUnit partnerUnit= getPartnerFileFromFilename(tu);
if (partnerUnit == null) { if (partnerUnit == null) {

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.ui.refactoring;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; 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.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; 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.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -68,14 +70,12 @@ public abstract class CRefactoring2 extends Refactoring {
protected String name = Messages.Refactoring_name; protected String name = Messages.Refactoring_name;
protected final ICProject project; protected final ICProject project;
protected final ITranslationUnit tu; protected final ITranslationUnit tu;
protected final RefactoringStatus initStatus;
protected final RefactoringASTCache astCache;
protected Region selectedRegion; protected Region selectedRegion;
protected final RefactoringStatus initStatus;
protected CRefactoringContext refactoringContext;
public CRefactoring2(ICElement element, ISelection selection, ICProject project, public CRefactoring2(ICElement element, ISelection selection, ICProject project) {
RefactoringASTCache astCache) {
this.project = project; this.project = project;
this.astCache = astCache;
this.initStatus= new RefactoringStatus(); this.initStatus= new RefactoringStatus();
if (!(element instanceof ISourceReference)) { if (!(element instanceof ISourceReference)) {
this.tu = null; 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) { public void setContext(CRefactoringContext refactoringContext) {
this.status = status; Assert.isNotNull(refactoringContext);
} this.refactoringContext = refactoringContext;
{
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;
}
}
} }
@Override @Override
@ -248,7 +188,11 @@ public abstract class CRefactoring2 extends Refactoring {
protected IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm) protected IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm)
throws CoreException, OperationCanceledException { 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) { protected boolean checkAST(IASTTranslationUnit ast) {
@ -284,4 +228,70 @@ public abstract class CRefactoring2 extends Refactoring {
result.add(new ResourceChangeChecker()); result.add(new ResourceChangeChecker());
return result; 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; 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.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; 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; import org.eclipse.cdt.internal.ui.editor.ASTProvider;
/** /**
* Cache containing ASTs for the translation units participating in refactoring. * A disposable context for C/C++ refactoring operations. Contains cache of ASTs of the translation
* The cache object has to be disposed of after use. Failure to do so may cause * units participating in refactoring. The context object has to be disposed of after use. Failure
* loss of index lock. * to do so may cause loss of index lock.
* <p> * <p>
* This class is not thread-safe. * 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 private static final int PARSE_MODE = ITranslationUnit.AST_SKIP_ALL_HEADERS
| ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT
| ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS | ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS
@ -47,9 +46,10 @@ public class RefactoringASTCache implements IDisposable {
private final Map<ITranslationUnit, IASTTranslationUnit> fASTCache; private final Map<ITranslationUnit, IASTTranslationUnit> fASTCache;
private IIndex fIndex; private IIndex fIndex;
private IASTTranslationUnit fSharedAST; private IASTTranslationUnit fSharedAST;
private boolean fDisposed;
public RefactoringASTCache() { public CRefactoringContext(CRefactoring2 refactoring) {
super(refactoring);
refactoring.setContext(this);
fASTCache = new ConcurrentHashMap<ITranslationUnit, IASTTranslationUnit>(); fASTCache = new ConcurrentHashMap<ITranslationUnit, IASTTranslationUnit>();
} }
@ -69,7 +69,8 @@ public class RefactoringASTCache implements IDisposable {
*/ */
public IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm) public IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm)
throws CoreException, OperationCanceledException { 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. getIndex(); // Make sure the index is locked.
if (pm != null && pm.isCanceled()) if (pm != null && pm.isCanceled())
throw new OperationCanceledException(); throw new OperationCanceledException();
@ -108,7 +109,8 @@ public class RefactoringASTCache implements IDisposable {
* @return The index. * @return The index.
*/ */
public IIndex getIndex() throws CoreException, OperationCanceledException { 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) { if (fIndex == null) {
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
IIndex index = CCorePlugin.getIndexManager().getIndex(projects); IIndex index = CCorePlugin.getIndexManager().getIndex(projects);
@ -122,25 +124,27 @@ public class RefactoringASTCache implements IDisposable {
return fIndex; return fIndex;
} }
/**
* @see IDisposable#dispose()
*/
@Override @Override
public void dispose() { public void dispose() {
Assert.isTrue(!fDisposed, "RefactoringASTCache.dispose() called more than once"); //$NON-NLS-1$ if (isDisposed())
fDisposed = true; throw new IllegalStateException("CRefactoringContext.dispose() called more than once."); //$NON-NLS-1$
if (fSharedAST != null) { if (fSharedAST != null) {
ASTProvider.getASTProvider().releaseSharedAST(fSharedAST); ASTProvider.getASTProvider().releaseSharedAST(fSharedAST);
} }
if (fIndex != null) { if (fIndex != null) {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
} }
super.dispose();
}
private boolean isDisposed() {
return getRefactoring() == null;
} }
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if (!fDisposed) if (!isDisposed())
CUIPlugin.logError("RefactoringASTCache was not disposed"); //$NON-NLS-1$ CUIPlugin.logError("CRefactoringContext was not disposed"); //$NON-NLS-1$
super.finalize(); 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. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,6 +8,7 @@
* *
* Contributors: * 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; package org.eclipse.cdt.internal.ui.refactoring;
@ -28,7 +29,10 @@ public abstract class CRefactoringContribution extends RefactoringContribution {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public Map retrieveArgumentMap(RefactoringDescriptor descriptor) { 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; CRefactoringDescription refDesc = (CRefactoringDescription) descriptor;
return refDesc.getParameterMap(); return refDesc.getParameterMap();
} else { } 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.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
* @deprecated Use {@link CRefactoringDescriptor} instead.
*/ */
@Deprecated
public abstract class CRefactoringDescription extends RefactoringDescriptor { public abstract class CRefactoringDescription extends RefactoringDescriptor {
public static final String FILE_NAME = "fileName"; //$NON-NLS-1$ public static final String FILE_NAME = "fileName"; //$NON-NLS-1$
public static final String SELECTION = "selection"; //$NON-NLS-1$ public static final String SELECTION = "selection"; //$NON-NLS-1$
protected Map<String, String> arguments; protected Map<String, String> arguments;
public CRefactoringDescription(String id, String project, String description, String comment, int flags, public CRefactoringDescription(String id, String project, String description, String comment,
Map<String, String> arguments) { int flags, Map<String, String> arguments) {
super(id, project, description, comment, flags); super(id, project, description, comment, flags);
this.arguments = arguments; this.arguments = arguments;
} }
@ -48,35 +52,31 @@ public abstract class CRefactoringDescription extends RefactoringDescriptor {
} }
protected ISelection getSelection() throws CoreException { protected ISelection getSelection() throws CoreException {
ISelection selection;
String selectStrings[] = arguments.get(SELECTION).split(","); //$NON-NLS-1$ String selectStrings[] = arguments.get(SELECTION).split(","); //$NON-NLS-1$
if (selectStrings.length >= 2) { if (selectStrings.length < 2) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal selection")); //$NON-NLS-1$
}
int offset = Integer.parseInt(selectStrings[0]); int offset = Integer.parseInt(selectStrings[0]);
int length = Integer.parseInt(selectStrings[1]); int length = Integer.parseInt(selectStrings[1]);
selection = new TextSelection(offset, length); return new TextSelection(offset, length);
} else {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$
}
return selection;
} }
protected ICProject getCProject() throws CoreException { protected ICProject getCProject() throws CoreException {
ICProject proj; IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject());
IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()); ICProject cProject = CoreModel.getDefault().create(project);
proj = CoreModel.getDefault().create(iProject); if (cProject == null) {
if (proj == null) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Unknown Project")); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Unknown Project")); //$NON-NLS-1$
} }
return proj; return cProject;
} }
protected IFile getFile() throws CoreException { protected IFile getFile() throws CoreException {
IFile file;
try { 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) { } catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, e.getMessage(), 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 CreateFileChange_FileExists;
public static String CRefactoring_FileNotFound; public static String CRefactoring_FileNotFound;
public static String CRefactoring_checking_final_conditions; 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_SelectionNotValid;
public static String Refactoring_CantLoadTU; public static String Refactoring_CantLoadTU;
public static String Refactoring_Ambiguity; public static String Refactoring_Ambiguity;

View file

@ -26,6 +26,8 @@ CreateFileChange_UnknownLoc=Unknown location: {0}
CreateFileChange_FileExists=File already exists: {0} CreateFileChange_FileExists=File already exists: {0}
CRefactoring_FileNotFound=The file {0} is not on the build path of a C/C++ project. CRefactoring_FileNotFound=The file {0} is not on the build path of a C/C++ project.
CRefactoring_checking_final_conditions=Checking preconditions... 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_SelectionNotValid=Selection is not valid.
Refactoring_CantLoadTU=Can not load translation unit. Refactoring_CantLoadTU=Can not load translation unit.
Refactoring_Ambiguity=Translation unit is ambiguous. Refactoring_Ambiguity=Translation unit is ambiguous.

View file

@ -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. * Associate a name with a visibility and holds a list of used names.
*
*/ */
public class NameNVisibilityInformation { public class NameNVisibilityInformation {
private String name = ""; //$NON-NLS-1$ private String name = ""; //$NON-NLS-1$
private VisibilityEnum visibility = VisibilityEnum.v_public; private VisibilityEnum visibility = VisibilityEnum.v_public;
private final ArrayList<String> usedNames = new ArrayList<String>(); private final ArrayList<String> usedNames = new ArrayList<String>();
@ -52,5 +50,4 @@ public class NameNVisibilityInformation {
public void addNamesToUsedNames(ArrayList<String> names) { public void addNamesToUsedNames(ArrayList<String> names) {
usedNames.addAll(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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; 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.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -23,27 +24,26 @@ import org.eclipse.cdt.core.model.ICProject;
public abstract class RefactoringRunner2 { public abstract class RefactoringRunner2 {
protected final ISelection selection; protected final ISelection selection;
protected final ICElement element; protected final ICElement element;
protected final IShellProvider shellProvider;
protected final ICProject project; protected final ICProject project;
protected final RefactoringStarter starter; private final IShellProvider shellProvider;
public RefactoringRunner2(ICElement element, ISelection selection, IShellProvider shellProvider, public RefactoringRunner2(ICElement element, ISelection selection, IShellProvider shellProvider,
ICProject cProject) { ICProject cProject) {
this.selection = selection; this.selection = selection;
this.element= element; this.element= element;
this.shellProvider= shellProvider;
this.project = cProject; this.project = cProject;
this.starter = new RefactoringStarter(); this.shellProvider= shellProvider;
} }
public final void run() { public abstract void run();
RefactoringASTCache astCache = new RefactoringASTCache();
protected final void run(RefactoringWizard wizard, CRefactoring2 refactoring, int saveMode) {
CRefactoringContext context = new CRefactoringContext(refactoring);
try { try {
run(astCache); RefactoringStarter starter = new RefactoringStarter();
starter.activate(wizard, shellProvider.getShell(), refactoring.getName(), saveMode);
} finally { } finally {
astCache.dispose(); context.dispose();
} }
} }
protected abstract void run(RefactoringASTCache astCache);
} }

View file

@ -11,16 +11,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring; package org.eclipse.cdt.internal.ui.refactoring;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard; import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; 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 { public class RefactoringStarter {
private RefactoringStatus fStatus; 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 * the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at * Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Google - initial API and implementation * Tom Ball (Google) - Initial API and implementation
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,7 +15,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; 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.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.text.edits.TextEditGroup; import org.eclipse.text.edits.TextEditGroup;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; 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.IASTNode.CopyStyle;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; 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.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.INodeFactory; 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.ast.cpp.ICPPASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator; 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.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; 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.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
@ -82,7 +83,7 @@ import org.eclipse.cdt.internal.ui.util.NameComposer;
* *
* @author Tom Ball * @author Tom Ball
*/ */
public class ExtractLocalVariableRefactoring extends CRefactoring { public class ExtractLocalVariableRefactoring extends CRefactoring2 {
public static final String ID = public static final String ID =
"org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$ "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 final NameNVisibilityInformation info;
private NodeContainer container; private NodeContainer container;
public ExtractLocalVariableRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info, public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) {
ICProject project) { super(element, selection, project);
super(file, selection, null, project); info = new NameNVisibilityInformation();
this.info = info;
name = Messages.ExtractLocalVariable; name = Messages.ExtractLocalVariable;
} }
@ -101,16 +101,14 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException { throws CoreException, OperationCanceledException {
SubMonitor sm = SubMonitor.convert(pm, 9); SubMonitor sm = SubMonitor.convert(pm, 9);
try {
lockIndex();
try {
RefactoringStatus status = super.checkInitialConditions(sm.newChild(6)); RefactoringStatus status = super.checkInitialConditions(sm.newChild(6));
if (status.hasError()) { if (status.hasError()) {
return status; return status;
} }
container = findAllExpressions(); container = findAllExpressions(pm);
if (container.size() < 1) { if (container.isEmpty()) {
initStatus.addFatalError(Messages.ExpressionMustBeSelected); initStatus.addFatalError(Messages.ExpressionMustBeSelected);
return initStatus; return initStatus;
} }
@ -119,13 +117,10 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
if (isProgressMonitorCanceld(sm, initStatus)) if (isProgressMonitorCanceld(sm, initStatus))
return initStatus; return initStatus;
boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region); boolean oneMarked = selectedRegion != null && isOneMarked(container.getNodesToWrite(), selectedRegion);
if (!oneMarked) { if (!oneMarked) {
if (target == null) { initStatus.addFatalError(target == null ?
initStatus.addFatalError(Messages.NoExpressionSelected); Messages.NoExpressionSelected : Messages.TooManyExpressionsSelected);
} else {
initStatus.addFatalError(Messages.TooManyExpressionsSelected);
}
return initStatus; return initStatus;
} }
sm.worked(1); sm.worked(1);
@ -135,20 +130,18 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
sm.worked(1); sm.worked(1);
container.getNames(); //XXX Is this needed?
sm.worked(1);
info.addNamesToUsedNames(findAllDeclaredNames()); info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1); sm.worked(1);
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); NodeHelper.findMethodContext(container.getNodesToWrite().get(0), refactoringContext, sm);
sm.worked(1); sm.worked(1);
info.setName(guessTempName()); info.setName(guessTempName());
sm.done(); sm.done();
} finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return initStatus; return initStatus;
} }
@ -157,9 +150,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target); IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef); ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
if (comTypeSpec != null) { if (comTypeSpec != null) {
for (IASTDeclaration dec : comTypeSpec.getMembers()) { for (IASTDeclaration decl : comTypeSpec.getMembers()) {
if (dec instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) dec; IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) decl;
for (IASTDeclarator decor : simpDec.getDeclarators()) { for (IASTDeclarator decor : simpDec.getDeclarators()) {
names.add(decor.getName().getRawSignature()); names.add(decor.getName().getRawSignature());
} }
@ -169,6 +162,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return names; return names;
} }
@Override
protected RefactoringStatus checkFinalConditions(IProgressMonitor subProgressMonitor,
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
return new RefactoringStatus();
}
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) { private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) {
if (funcDef != null) { if (funcDef != null) {
IBinding binding = funcDef.getDeclarator().getName().resolveBinding(); IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
@ -191,9 +190,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
for (IASTNode node : selectedNodes) { for (IASTNode node : selectedNodes) {
if (node instanceof IASTExpression) { if (node instanceof IASTExpression) {
IASTExpression expression = (IASTExpression) node; IASTExpression expression = (IASTExpression) node;
boolean isInSameFileSelection = if (expression.isPartOfTranslationUnitFile() &&
SelectionHelper.isInSameFileSelection(textSelection, expression, file); isExpressionInSelection(expression, textSelection)) {
if (isInSameFileSelection && isExpressionInSelection(expression, textSelection)) {
if (target == null) { if (target == null) {
target = expression; target = expression;
oneMarked = true; oneMarked = true;
@ -208,11 +206,11 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
private boolean isExpressionInSelection(IASTExpression expression, Region selection) { private boolean isExpressionInSelection(IASTExpression expression, Region selection) {
IASTFileLocation location = expression.getFileLocation(); IASTFileLocation location = expression.getFileLocation();
int e1 = location.getNodeOffset(); int expressionStart = location.getNodeOffset();
int e2 = location.getNodeOffset() + location.getNodeLength(); int expressionEnd = expressionStart + location.getNodeLength();
int s1 = selection.getOffset(); int selectionStart = selection.getOffset();
int s2 = selection.getOffset() + selection.getLength(); int selectionEnd = selectionStart + selection.getLength();
return e1 >= s1 && e2 <= s2; return expressionStart >= selectionStart && expressionEnd <= selectionEnd;
} }
private boolean isTargetChild(IASTExpression child) { private boolean isTargetChild(IASTExpression child) {
@ -228,9 +226,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return false; return false;
} }
private NodeContainer findAllExpressions() { private NodeContainer findAllExpressions(IProgressMonitor pm)
throws OperationCanceledException, CoreException {
final NodeContainer container = new NodeContainer(); final NodeContainer container = new NodeContainer();
IASTTranslationUnit ast = getAST(tu, pm);
if (ast != null) {
ast.accept(new ASTVisitor() { ast.accept(new ASTVisitor() {
{ {
shouldVisitExpressions = true; shouldVisitExpressions = true;
@ -238,13 +239,15 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override @Override
public int visit(IASTExpression expression) { public int visit(IASTExpression expression) {
if (SelectionHelper.isSelectedFile(region, expression, file)) { if (expression.isPartOfTranslationUnitFile() &&
SelectionHelper.isExpressionWhollyInSelection(selectedRegion, expression)) {
container.add(expression); container.add(expression);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
return super.visit(expression); return super.visit(expression);
} }
}); });
}
return container; return container;
} }
@ -252,15 +255,13 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override @Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException { throws CoreException, OperationCanceledException {
try {
lockIndex();
try {
String variableName = info.getName(); String variableName = info.getName();
TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable); TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable);
// Define temporary variable declaration and insert it // Define temporary variable declaration and insert it
IASTStatement declInsertPoint = getParentStatement(target); IASTStatement declInsertPoint = getParentStatement(target);
IASTDeclarationStatement declaration = getVariableNodes(variableName); IASTTranslationUnit ast = getAST(tu, pm);
IASTDeclarationStatement declaration = getVariableNodes(ast, variableName);
declaration.setParent(declInsertPoint.getParent()); declaration.setParent(declInsertPoint.getParent());
ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast); ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast);
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup); rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
@ -269,12 +270,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
CPPASTIdExpression idExpression = CPPASTIdExpression idExpression =
new CPPASTIdExpression(new CPPASTName(variableName.toCharArray())); new CPPASTIdExpression(new CPPASTName(variableName.toCharArray()));
rewriter.replace(target, idExpression, editGroup); rewriter.replace(target, idExpression, editGroup);
} finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} }
private IASTStatement getParentStatement(IASTNode node) { private IASTStatement getParentStatement(IASTNode node) {
@ -286,8 +281,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return null; return null;
} }
private IASTDeclarationStatement getVariableNodes(String newName) { private IASTDeclarationStatement getVariableNodes(IASTTranslationUnit ast, String newName) {
INodeFactory factory = this.ast.getASTNodeFactory(); INodeFactory factory = ast.getASTNodeFactory();
IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null); IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null);
@ -438,7 +433,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
} }
} }
} }
}); });
} }
if (guessedTempNames.isEmpty()) { if (guessedTempNames.isEmpty()) {
@ -491,7 +485,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IBinding[] bindings = scope.find(name); IBinding[] bindings = scope.find(name);
return bindings == null || bindings.length == 0; 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) { private String makeTempName(List<String> usedNames, IScope scope) {
@ -510,16 +504,20 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override @Override
protected RefactoringDescriptor getRefactoringDescriptor() { protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap(); 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$ "Extract Local Variable Refactoring", "Extract " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$
return desc; return desc;
} }
private Map<String, String> getArgumentMap() { private Map<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>(); Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString()); arguments.put(CRefactoringDescription.FILE_NAME, tu.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$ arguments.put(CRefactoringDescription.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$
arguments.put(ExtractLocalVariableRefactoringDescription.NAME, info.getName()); arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName());
return arguments; 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, public RefactoringDescriptor createDescriptor(String id, String project, String description,
String comment, Map arguments, int flags) throws IllegalArgumentException { String comment, Map arguments, int flags) throws IllegalArgumentException {
if (id.equals(ExtractLocalVariableRefactoring.ID)) { if (id.equals(ExtractLocalVariableRefactoring.ID)) {
return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments); return new ExtractLocalVariableRefactoringDescriptor(project, description, comment, arguments);
} else { } else {
return null; 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. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,50 +8,41 @@
* *
* Contributors: * 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; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.Map; import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection; 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.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription { public class ExtractLocalVariableRefactoringDescriptor extends CRefactoringDescriptor {
static protected final String NAME = "name"; //$NON-NLS-1$ 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) { String comment, Map<String, String> arguments) {
super(ExtractLocalVariableRefactoring.ID, project, description, comment, super(ExtractLocalVariableRefactoring.ID, project, description, comment,
RefactoringDescriptor.MULTI_CHANGE, arguments); RefactoringDescriptor.MULTI_CHANGE, arguments);
} }
@Override @Override
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException { public CRefactoring2 createRefactoring(RefactoringStatus status) throws CoreException {
IFile file;
NameNVisibilityInformation info = new NameNVisibilityInformation();
ICProject proj;
info.setName(arguments.get(NAME));
proj = getCProject();
file = getFile();
ISelection selection = getSelection(); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -7,45 +7,38 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; 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.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
/** /**
* Extract Local Variable refactoring runner. * Extract Local Variable refactoring runner.
* *
* @author Tom Ball * @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) { IShellProvider shellProvider, ICProject cProject) {
super(file, selection, null, shellProvider, cProject); super(element, selection, shellProvider, cProject);
} }
@Override @Override
public void run() { public void run() {
NameNVisibilityInformation info = new NameNVisibilityInformation(); ExtractLocalVariableRefactoring refactoring =
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, selection, info, project); new ExtractLocalVariableRefactoring(element, selection, project);
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard( ExtractLocalVariableRefactoringWizard wizard =
refactoring, info); new ExtractLocalVariableRefactoringWizard(refactoring);
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); run(wizard, refactoring, RefactoringSaveHelper.SAVE_NOTHING);
try {
operator.run(shellProvider.getShell(), refactoring.getName());
} catch (InterruptedException e) {
// initial condition checking got canceled by the user.
}
} }
} }

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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -7,15 +7,13 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; 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.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
/** /**
* The wizard page for Extract Local Variable Refactoring, creates the UI page. * 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 { public class ExtractLocalVariableRefactoringWizard extends RefactoringWizard {
private InputPage page; private InputPage page;
private final NameNVisibilityInformation info;
public ExtractLocalVariableRefactoringWizard(Refactoring refactoring, public ExtractLocalVariableRefactoringWizard(ExtractLocalVariableRefactoring refactoring) {
NameNVisibilityInformation info) {
super(refactoring, WIZARD_BASED_USER_INTERFACE); super(refactoring, WIZARD_BASED_USER_INTERFACE);
this.info = info;
} }
@Override @Override
protected void addUserInputPages() { protected void addUserInputPages() {
page = new InputPage(Messages.ExtractLocalVariable, info); ExtractLocalVariableRefactoring refactoring = (ExtractLocalVariableRefactoring) getRefactoring();
page = new InputPage(Messages.ExtractLocalVariable, refactoring.getRefactoringInfo());
addPage(page); 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.ClassMemberInserter;
import org.eclipse.cdt.internal.ui.refactoring.Container; import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; 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.InsertLocation;
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder; import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder;
import org.eclipse.cdt.internal.ui.refactoring.utils.Checks; import org.eclipse.cdt.internal.ui.refactoring.utils.Checks;
@ -93,8 +92,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
private InsertLocation definitionInsertLocation; private InsertLocation definitionInsertLocation;
public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection, public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection,
ICProject project, RefactoringASTCache astCache) { ICProject project) {
super(element, selection, project, astCache); super(element, selection, project);
context = new GetterSetterContext(); context = new GetterSetterContext();
} }
@ -148,7 +147,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
} }
private void initRefactoring(IProgressMonitor pm) throws OperationCanceledException, CoreException { private void initRefactoring(IProgressMonitor pm) throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = astCache.getAST(tu, null); IASTTranslationUnit ast = getAST(tu, null);
context.selectedName = getSelectedName(ast); context.selectedName = getSelectedName(ast);
IASTCompositeTypeSpecifier compositeTypeSpecifier = null; IASTCompositeTypeSpecifier compositeTypeSpecifier = null;
if (context.selectedName != null) { if (context.selectedName != null) {
@ -279,7 +278,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
IASTSimpleDeclaration decl = context.existingFields.get(0); IASTSimpleDeclaration decl = context.existingFields.get(0);
MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder(); MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder();
InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(), InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(),
astCache, pm); refactoringContext, pm);
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) { if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.ITextEditor; 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.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper; import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
/** /**
@ -36,14 +36,13 @@ public class GenerateGettersAndSettersRefactoringRunner extends RefactoringRunne
} }
@Override @Override
public void run(RefactoringASTCache astCache) { public void run() {
if (getActiveEditor() instanceof ITextEditor) { if (getActiveEditor() instanceof ITextEditor) {
GenerateGettersAndSettersRefactoring refactoring = GenerateGettersAndSettersRefactoring refactoring =
new GenerateGettersAndSettersRefactoring(element, selection, project, astCache); new GenerateGettersAndSettersRefactoring(element, selection, project);
GenerateGettersAndSettersRefactoringWizard wizard = RefactoringWizard wizard =
new GenerateGettersAndSettersRefactoringWizard(refactoring); new GenerateGettersAndSettersRefactoringWizard(refactoring);
starter.activate(wizard, shellProvider.getShell(), refactoring.getName(), run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING);
RefactoringSaveHelper.SAVE_REFACTORING);
} }
} }

View file

@ -9,6 +9,7 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Marc-Andre Laperle * Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.implementmethod; 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.CRefactoring2;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; 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.Checks;
import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
@ -78,8 +78,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
private Map<IASTSimpleDeclaration, InsertLocation> insertLocations; private Map<IASTSimpleDeclaration, InsertLocation> insertLocations;
private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory(); private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory();
public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project, RefactoringASTCache astCache) { public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project) {
super(element, selection, project, astCache); super(element, selection, project);
data = new ImplementMethodData(); data = new ImplementMethodData();
methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder(); methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder();
insertLocations = new HashMap<IASTSimpleDeclaration, InsertLocation>(); insertLocations = new HashMap<IASTSimpleDeclaration, InsertLocation>();
@ -99,7 +99,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
data.setMethodDeclarations(unimplementedMethodDeclarations); data.setMethodDeclarations(unimplementedMethodDeclarations);
if (selectedRegion.getLength() > 0) { 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)) { if (NodeHelper.isMethodDeclaration(methodDeclaration)) {
for (MethodToImplementConfig config : data.getMethodDeclarations()) { for (MethodToImplementConfig config : data.getMethodDeclarations()) {
if (config.getDeclaration() == methodDeclaration) { if (config.getDeclaration() == methodDeclaration) {
@ -114,8 +115,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
return initStatus; return initStatus;
} }
private List<IASTSimpleDeclaration> findUnimplementedMethodDeclarations(IProgressMonitor pm) throws OperationCanceledException, CoreException { private List<IASTSimpleDeclaration> findUnimplementedMethodDeclarations(IProgressMonitor pm)
IASTTranslationUnit ast = astCache.getAST(tu, pm); throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = getAST(tu, pm);
final List<IASTSimpleDeclaration> list = new ArrayList<IASTSimpleDeclaration>(); final List<IASTSimpleDeclaration> list = new ArrayList<IASTSimpleDeclaration>();
ast.accept(new ASTVisitor() { ast.accept(new ASTVisitor() {
{ {
@ -151,8 +153,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
} }
try { try {
IIndexName[] indexNames = astCache.getIndex().findNames(binding, IIndex.FIND_DEFINITIONS IIndexName[] indexNames = getIndex().findNames(binding,
| IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES); IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
if (indexNames.length == 0) { if (indexNames.length == 0) {
return true; return true;
} }
@ -174,8 +176,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
} }
} }
protected void createDefinition(ModificationCollector collector, protected void createDefinition(ModificationCollector collector, MethodToImplementConfig config,
MethodToImplementConfig config, IProgressMonitor subMonitor) throws CoreException, OperationCanceledException { IProgressMonitor subMonitor) throws CoreException, OperationCanceledException {
if (subMonitor.isCanceled()) { if (subMonitor.isCanceled()) {
throw new OperationCanceledException(); throw new OperationCanceledException();
} }
@ -228,7 +230,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
if (insertLocations.containsKey(methodDeclaration)) { if (insertLocations.containsKey(methodDeclaration)) {
return insertLocations.get(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)) { if (insertLocation.getTranslationUnit() == null || NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) {
insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu); insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu);
@ -286,7 +290,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
int insertOffset = insertLocation.getInsertPosition(); int insertOffset = insertLocation.getInsertPosition();
return NameHelper.createQualifiedNameFor( return NameHelper.createQualifiedNameFor(
functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(), functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(),
insertLocation.getTranslationUnit(), insertOffset, astCache); insertLocation.getTranslationUnit(), insertOffset, refactoringContext);
} }
public ImplementMethodData getRefactoringData() { 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -9,17 +9,18 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Marc-Andre Laperle * Marc-Andre Laperle
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.implementmethod; package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; 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.ICElement;
import org.eclipse.cdt.core.model.ICProject; 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.RefactoringRunner2;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
/** /**
* @author Lukas Felber * @author Lukas Felber
@ -32,15 +33,10 @@ public class ImplementMethodRefactoringRunner extends RefactoringRunner2 {
} }
@Override @Override
public void run(RefactoringASTCache astCache) { public void run() {
ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(element, selection, project, astCache); ImplementMethodRefactoring refactoring =
new ImplementMethodRefactoring(element, selection, project);
ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring); ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring);
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING);
try {
operator.run(shellProvider.getShell(), refactoring.getName());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} }
} }

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.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder; 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.DefinitionFinder;
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
@ -53,7 +53,7 @@ public class MethodDefinitionInsertLocationFinder {
new HashMap<IASTSimpleDeclaration, IASTName>(); new HashMap<IASTSimpleDeclaration, IASTName>();
public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation, 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); IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
InsertLocation insertLocation = new InsertLocation(); 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. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,6 +8,7 @@
* *
* Contributors: * 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; 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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; 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.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; 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. * are skipped during search.
*/ */
public class DeclaratorFinder { public class DeclaratorFinder {
private IASTFunctionDeclarator foundDeclarator; private IASTFunctionDeclarator foundDeclarator;
public DeclaratorFinder(ITextSelection selection, IASTTranslationUnit unit) { public DeclaratorFinder(ITextSelection selection, IASTTranslationUnit unit) {
@ -47,16 +49,15 @@ public class DeclaratorFinder {
return foundDeclarator.getName(); return foundDeclarator.getName();
} }
private IASTFunctionDeclarator findDeclaratorInSelection( private IASTFunctionDeclarator findDeclaratorInSelection(ITextSelection selection,
ITextSelection selection,
IASTTranslationUnit unit) { IASTTranslationUnit unit) {
IASTNode firstNodeInsideSelection = unit.getNodeSelector(null) IASTNodeSelector nodeSelector = unit.getNodeSelector(null);
.findFirstContainedNode(selection.getOffset(), IASTNode firstNodeInsideSelection =
selection.getLength()); nodeSelector.findFirstContainedNode(selection.getOffset(), selection.getLength());
IASTFunctionDeclarator declarator = findDeclaratorInAncestors(firstNodeInsideSelection); IASTFunctionDeclarator declarator = findDeclaratorInAncestors(firstNodeInsideSelection);
if (declarator == null) { if (declarator == null) {
firstNodeInsideSelection = unit.getNodeSelector(null).findEnclosingNode( firstNodeInsideSelection = nodeSelector.findEnclosingNode(
selection.getOffset(), selection.getLength()); selection.getOffset(), selection.getLength());
declarator = findDeclaratorInAncestors(firstNodeInsideSelection); declarator = findDeclaratorInAncestors(firstNodeInsideSelection);
} }
@ -65,6 +66,9 @@ ITextSelection selection,
private IASTFunctionDeclarator findDeclaratorInAncestors(IASTNode node) { private IASTFunctionDeclarator findDeclaratorInAncestors(IASTNode node) {
while (node != null) { while (node != null) {
if (node instanceof IASTProblemStatement) {
return null;
}
IASTFunctionDeclarator declarator = extractDeclarator(node); IASTFunctionDeclarator declarator = extractDeclarator(node);
if (node instanceof ICPPASTTemplateDeclaration) { if (node instanceof ICPPASTTemplateDeclaration) {
declarator = extractDeclarator(((ICPPASTTemplateDeclaration) node).getDeclaration()); declarator = extractDeclarator(((ICPPASTTemplateDeclaration) node).getDeclaration());
@ -93,8 +97,7 @@ ITextSelection selection,
throw new NotSupportedException(Messages.DeclaratorFinder_MultipleDeclarators); throw new NotSupportedException(Messages.DeclaratorFinder_MultipleDeclarators);
} }
if (declarators.length == 1 && if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator)
declarators[0] instanceof IASTFunctionDeclarator)
return (IASTFunctionDeclarator) declarators[0]; return (IASTFunctionDeclarator) declarators[0];
} }
return null; return null;

View file

@ -67,10 +67,9 @@ public class ToggleFileCreator {
} }
public void createNewFile() { public void createNewFile() {
CreateFileChange change;
String filename = getNewFileName(); String filename = getNewFileName();
try { try {
change = new CreateFileChange(filename, new Path(getPath() + filename), CreateFileChange change = new CreateFileChange(filename, new Path(getPath() + filename),
EMPTY_STRING, context.getSelectionFile().getCharset()); EMPTY_STRING, context.getSelectionFile().getCharset());
change.perform(new NullProgressMonitor()); change.perform(new NullProgressMonitor());
} catch (CoreException e) { } catch (CoreException e) {

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. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,6 +8,7 @@
* *
* Contributors: * 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; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -38,10 +39,9 @@ import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
* position. * position.
*/ */
public class ToggleRefactoring extends CRefactoring { public class ToggleRefactoring extends CRefactoring {
private ITextSelection selection; private ITextSelection selection;
private IToggleRefactoringStrategy strategy; private IToggleRefactoringStrategy strategy;
protected ToggleRefactoringContext context; private ToggleRefactoringContext context;
private IIndex fIndex; private IIndex fIndex;
public ToggleRefactoring(IFile file, ITextSelection selection, ICProject proj) { public ToggleRefactoring(IFile file, ITextSelection selection, ICProject proj) {
@ -97,4 +97,8 @@ public class ToggleRefactoring extends CRefactoring {
protected RefactoringDescriptor getRefactoringDescriptor() { protected RefactoringDescriptor getRefactoringDescriptor() {
return new EmptyRefactoringDescription(); 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.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; 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; import org.eclipse.cdt.internal.ui.util.EditorUtility;
/** /**
@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
public class DefinitionFinder { public class DefinitionFinder {
public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration, public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration,
RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException { CRefactoringContext astCache, IProgressMonitor pm) throws CoreException {
IIndex index = astCache.getIndex(); IIndex index = astCache.getIndex();
IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0]; IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0];
if (index == null) { if (index == null) {
@ -58,7 +58,7 @@ public class DefinitionFinder {
} }
private static IASTName getDefinition(IIndexBinding binding, 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>(); Set<String> searchedFiles = new HashSet<String>();
List<IASTName> definitions = new ArrayList<IASTName>(); List<IASTName> definitions = new ArrayList<IASTName>();
IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true); IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true);
@ -91,7 +91,7 @@ public class DefinitionFinder {
} }
private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu, 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 { throws OperationCanceledException, CoreException {
IASTTranslationUnit ast = astCache.getAST(tu, pm); IASTTranslationUnit ast = astCache.getAST(tu, pm);
findDefinitionsInAST(binding, ast, tu, definitions); 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.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/** /**
* Helps with IASTNames. * Helps with IASTNames.
@ -68,7 +68,7 @@ public class NameHelper {
*/ */
public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName, public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName,
ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu, ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu,
int insertLocation, RefactoringASTCache astCache) throws CoreException { int insertLocation, CRefactoringContext astCache) throws CoreException {
ICPPASTQualifiedName qname = new CPPASTQualifiedName(); ICPPASTQualifiedName qname = new CPPASTQualifiedName();
IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, 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.CPPASTTemplateId;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId; 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. * Helper class to find Namespace informations.
@ -48,7 +48,7 @@ public class NamespaceHelper {
* @return ICPPASTQualifiedName with the names of all namespaces * @return ICPPASTQualifiedName with the names of all namespaces
* @throws CoreException * @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 { throws CoreException {
final CPPASTQualifiedName qualifiedName = new CPPASTQualifiedName(); 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 * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -8,15 +8,18 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.utils; package org.eclipse.cdt.internal.ui.refactoring.utils;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; 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.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndex; 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.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.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition; 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.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.MethodContext; import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext;
/** /**
* General class for common Node operations. * General class for common Node operations.
@ -99,6 +107,71 @@ public class NodeHelper {
return null; return null;
} }
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 { public static MethodContext findMethodContext(IASTNode node, IIndex index) throws CoreException {
IASTTranslationUnit translationUnit = node.getTranslationUnit(); IASTTranslationUnit translationUnit = node.getTranslationUnit();
boolean found = false; boolean found = false;
@ -125,23 +198,7 @@ public class NodeHelper {
return context; return context;
} }
private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context, @Deprecated
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);
}
}
}
}
private static void getMethodContexWithIndex(IIndex index, IASTTranslationUnit translationUnit, private static void getMethodContexWithIndex(IIndex index, IASTTranslationUnit translationUnit,
MethodContext context, IASTName name) throws CoreException { MethodContext context, IASTName name) throws CoreException {
IBinding bind = name.resolveBinding(); 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) { public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) {
while (node != null) { while (node != null) {
if (node instanceof IASTCompoundStatement) { if (node instanceof IASTCompoundStatement) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,11 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.refactoring.actions; 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.text.ITextSelection;
import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.IShellProvider;
@ -38,9 +37,8 @@ public class ExtractLocalVariableAction extends RefactoringAction {
@Override @Override
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) { public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
IResource res= wc.getResource(); if (wc.getResource() != null) {
if (res instanceof IFile) { new ExtractLocalVariableRefactoringRunner(wc, selection, shellProvider, wc.getCProject()).run();
new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run();
} }
} }