From 3453fa6fcd43800486c8d8c95e429f49d4121459 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 15 Feb 2012 15:41:26 -0800 Subject: [PATCH] Bug 347712 - Use shared AST in ExtractLocalVariableRefactoring. --- .../rewrite/astwriter/StatementWriter.java | 3 +- .../changegenerator/ChangeGenerator.java | 4 + .../resources/refactoring/ExtractConstant.rts | 518 --- .../refactoring/ExtractConstantHistory.rts | 197 -- .../refactoring/GenerateGettersAndSetters.rts | 1512 --------- .../resources/refactoring/HideMethod.rts | 2 +- .../resources/refactoring/NewCreationTest.rts | 44 - .../ToggleCommentsClassToHeader.rts | 186 -- .../ToggleCommentsHeaderToClass.rts | 141 - .../ToggleCommentsHeaderToImpl.rts | 109 - .../ToggleCommentsImplToHeader.rts | 121 - .../refactoring/ToggleCtorDtorRefactoring.rts | 242 -- .../ToggleDefaultParameterRefactoring.rts | 92 - .../refactoring/ToggleDifferentSelections.rts | 90 - .../refactoring/ToggleErrorRefactoring.rts | 105 - .../refactoring/ToggleFreeFunction.rts | 260 -- .../ToggleNamespaceRefactoring.rts | 265 -- .../refactoring/ToggleNestedRefactoring.rts | 104 - .../resources/refactoring/ToggleOrdering.rts | 202 -- .../resources/refactoring/ToggleSelection.rts | 128 - .../ToggleSimpleFunctionRefactoring.rts | 184 -- .../refactoring/ToggleTemplateRefactoring.rts | 131 - .../refactoring/ToggleTryCatchRefactoring.rts | 262 -- .../refactoring/ToggleVirtualFunction.rts | 83 - .../refactoring/RefactoringHistoryTest.java | 32 +- .../ui/tests/refactoring/RefactoringTest.java | 74 +- .../refactoring/RefactoringTestBase.java | 100 +- .../refactoring/RefactoringTestSuite.java | 14 +- .../ExtractConstantRefactoringTest.java | 794 ++++- .../ExtractConstantTestSuite.java | 34 - .../ExtractFunctionRefactoringTest.java | 21 +- .../ExtractLocalVariableRefactoringTest.java | 34 +- .../GenerateGettersAndSettersTest.java | 1656 +++++++++- .../GenerateGettersAndSettersTestSuite.java | 32 - .../hidemethod/HideMethodRefactoringTest.java | 37 +- .../ImplementMethodRefactoringTest.java | 34 +- .../MockToggleRefactoringTest.java | 31 - .../togglefunction/ToggleRefactoringTest.java | 119 - .../ToggleRefactoringTestSuite.java | 65 - .../togglefunction/ToogleRefactoringTest.java | 2865 +++++++++++++++++ .../utils/DefinitionFinderTest.java | 43 +- core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF | 2 +- .../ui/editor/SourceHeaderPartnerFinder.java | 4 +- .../ui/refactoring/CRefactoring2.java | 148 +- ...ASTCache.java => CRefactoringContext.java} | 40 +- .../refactoring/CRefactoringContribution.java | 10 +- .../refactoring/CRefactoringDescription.java | 36 +- .../refactoring/CRefactoringDescriptor.java | 111 + .../cdt/internal/ui/refactoring/Messages.java | 2 + .../ui/refactoring/Messages.properties | 2 + .../NameNVisibilityInformation.java | 5 +- .../ui/refactoring/RefactoringRunner2.java | 22 +- .../ui/refactoring/RefactoringStarter.java | 6 +- .../ExtractLocalVariableRefactoring.java | 218 +- ...tLocalVariableRefactoringContribution.java | 2 +- ...ctLocalVariableRefactoringDescriptor.java} | 35 +- ...ExtractLocalVariableRefactoringRunner.java | 35 +- ...ExtractLocalVariableRefactoringWizard.java | 16 +- .../GenerateGettersAndSettersRefactoring.java | 9 +- ...ateGettersAndSettersRefactoringRunner.java | 13 +- .../ImplementMethodRefactoring.java | 30 +- .../ImplementMethodRefactoringRunner.java | 20 +- .../MethodDefinitionInsertLocationFinder.java | 4 +- .../togglefunction/DeclaratorFinder.java | 25 +- .../togglefunction/ToggleFileCreator.java | 7 +- .../togglefunction/ToggleNodeHelper.java | 2 +- .../togglefunction/ToggleRefactoring.java | 14 +- .../refactoring/utils/DefinitionFinder.java | 8 +- .../ui/refactoring/utils/NameHelper.java | 4 +- .../ui/refactoring/utils/NamespaceHelper.java | 4 +- .../ui/refactoring/utils/NodeHelper.java | 112 +- .../actions/ExtractLocalVariableAction.java | 12 +- 72 files changed, 5993 insertions(+), 5935 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleErrorRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSelection.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantTestSuite.java delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTestSuite.java delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/MockToggleRefactoringTest.java delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTestSuite.java create mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToogleRefactoringTest.java rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/{RefactoringASTCache.java => CRefactoringContext.java} (80%) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescriptor.java rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/{ExtractLocalVariableRefactoringDescription.java => ExtractLocalVariableRefactoringDescriptor.java} (57%) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java index 5cf34223998..a7c9580bec8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java @@ -395,7 +395,8 @@ public class StatementWriter extends NodeWriter { protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) { return compoundStatement.getStatements(); } - + + // TODO(sprigogin): Rename second parameter protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) { if (statement instanceof IASTCompoundStatement) { //TODO hsr existiert noch eine methode diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java index eb35b998fbd..f8a07a9b3e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java @@ -590,6 +590,10 @@ public class ChangeGenerator extends ASTVisitor { } } newNode.accept(writer); + // TODO(sprigogin): Temporary workaround for invalid handling of line breaks in StatementWriter + if (!writer.toString().endsWith("\n")) //$NON-NLS-1$ + writer.newLine(); + } if (prevNode != null) { IASTNode nextNode = getNextSiblingOrPreprocessorNode(prevNode); diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts deleted file mode 100644 index 8099b078d57..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts +++ /dev/null @@ -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"; -}; - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts deleted file mode 100644 index 6df4814549a..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts +++ /dev/null @@ -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 - - - - - - -//!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 - - - - - -//!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 - - - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts deleted file mode 100644 index ac0dfa784c4..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts +++ /dev/null @@ -1,1512 +0,0 @@ -//!Generate Getters and Setters One Getter Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=name -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - char* getName() const { - return name; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -//!Generate Getters and Setters One Getter Selection with Namespace -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=name -//@A.h -#ifndef A_H_ -#define A_H_ - -namespace Personal { - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -} - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -namespace Personal { - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - char* getName() const { - return name; - } -}; - -} - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -//!Generate Getters and Setters One Setter Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -setters=name -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - void setName(char* name) { - this->name = name; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -//!Generate Getters and Setters Getter and Setter Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -setters=name -getters=name -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - char* getName() const { - return name; - } - - void setName(char* name) { - this->name = name; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -//!Generate Getters and Setters Multiple Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=name,systemId -setters=name,systemId -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - char* getName() const { - return name; - } - - void setName(char* name) { - this->name = name; - } - - int getSystemId() const { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -//!Generate Getters and Setters Visibility order 1 -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=GaS.h -getters=i,ok -setters=i,ok -//@GaS.h -#ifndef GAS_H_ -#define GAS_H_ - -class GaS { -public: - GaS(); - virtual ~GaS(); - bool /*$*/ok/*$$*/; - void method2(); - -private: - int i; -}; - -#endif -//= -#ifndef GAS_H_ -#define GAS_H_ - -class GaS { -public: - GaS(); - virtual ~GaS(); - bool ok; - void method2(); - - int getI() const { - return i; - } - - void setI(int i) { - this->i = i; - } - - bool isOk() const { - return ok; - } - - void setOk(bool ok) { - this->ok = ok; - } - -private: - int i; -}; - -#endif -//@GaS.cpp -#include "Getters.h" - -GaS::Getters() { -} - -GaS::~Getters() { -} -//!Generate Getters and Setters no methods -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=id -setters=id -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int /*$*/id/*$$*/; -}; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -public: - int getId() const { - return id; - } - - void setId(int id) { - this->id = id; - } - -private: - int id; -}; - -#endif /* A_H_ */ -//!Generate Getters and Setters no methods ascending visibility order -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=i -setters=i -ascendingVisibilityOrder=true -//@A.h -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { - int /*$*/i/*$$*/; //comment2 - char* b; - //comment3 -}; - -#endif /* TEST_H_ */ -//= -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { - int i; //comment2 - char* b; - //comment3 - -public: - int getI() const { - return i; - } - - void setI(int i) { - this->i = i; - } -}; - -#endif /* TEST_H_ */ -//!Generate Getters and Setters no fields -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -fatalerror=true -//@A.h -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { - void /*$*/test/*$$*/(); - //comment3 -}; - -#endif /* TEST_H_ */ -//= -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { - void test(); - //comment3 -}; - -#endif /* TEST_H_ */ -//!Generate Getters and Setters, Pass by Reference, Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=name -setters=name -definitionSeparate=true -//@A.h -#ifndef A_H_ -#define A_H_ - -struct FullName { - const char* first; - const char* last; - FullName(const FullName& other); - ~FullName(); -}; - -class Person { -private: - int systemId; - -protected: - FullName name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId(); - - void setSystemId(int systemId); -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -struct FullName { - const char* first; - const char* last; - FullName(const FullName& other); - ~FullName(); -}; - -class Person { -private: - int systemId; - -protected: - FullName name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId(); - - void setSystemId(int systemId); - const FullName& getName() const; - void setName(const FullName& name); -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -#include "A.h" - -const FullName& Person::getName() const { - return name; -} - -void Person::setName(const FullName& name) { - this->name = name; -} - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//!Generate Getters and Setters One Getter Selection with Namespace Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=name -definitionSeparate=true -//@A.h -#ifndef A_H_ -#define A_H_ - -namespace Personal { - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -} - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -namespace Personal { - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - char* getName() const; -}; - -} - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -namespace Personal { - -int Person::SocSecNo() { - return socSecNo; -} - -} // namespace Personal - -int main(int argc, char** argv) { -} -//= -#include "A.h" - -namespace Personal { - -char* Person::getName() const { - return name; -} - -int Person::SocSecNo() { - return socSecNo; -} - -} // namespace Personal - -int main(int argc, char** argv) { -} -//!Generate Getters and Setters One Setter Selection Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -setters=name -definitionSeparate=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - void setName(char* name); -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -#include "A.h" - -void Person::setName(char* name) { - this->name = name; -} - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//!Getter and Setter Selection Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -setters=name -getters=name -definitionSeparate=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int /*$*/SocSecNo/*$$*/(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } -}; - -int gooo = 1; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int systemId; - -protected: - char* name; - -public: - const int socSecNo; - - Person myFriend; - - Person(int socSecNo); // constructor - - ~Person(); // destructor - - char* Name(); - - void Print(); - - int SocSecNo(); - - int GetUniqueId(); - - int getSystemId() { - return systemId; - } - - void setSystemId(int systemId) { - this->systemId = systemId; - } - - char* getName() const; - void setName(char* name); -}; - -int gooo = 1; - -#endif /* A_H_ */ -//@A.cpp -#include "A.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//= -#include "A.h" - -char* Person::getName() const { - return name; -} - -void Person::setName(char* name) { - this->name = name; -} - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} -//!Generate Getters and Setters no Methods Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=id -setters=id -definitionSeparate=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class Person { -private: - int /*$*/id/*$$*/; -}; - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class Person { -public: - int getId() const; - void setId(int id); - -private: - int id; -}; - -inline int Person::getId() const { - return id; -} - -inline void Person::setId(int id) { - this->id = id; -} - -#endif /* A_H_ */ -//!No Methods Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=i -setters=i -definitionSeparate=true -//@A.h -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { - int /*$*/i/*$$*/; //comment2 - char* b; - //comment3 -}; - -#endif /* TEST_H_ */ -//= -/* - * test.h - */ - -#ifndef TEST_H_ -#define TEST_H_ - -//comment1 -class test { -public: - int getI() const; - void setI(int i); - -private: - int i; //comment2 - char* b; - //comment3 -}; - -inline int test::getI() const { - return i; -} - -inline void test::setI(int i) { - this->i = i; -} - -#endif /* TEST_H_ */ -//!Bug 323780 "Generate Getters and Setters..." crashes -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=Test.h -getters=testField -setters=testField -definitionSeparate=true - -//@Test.h -#ifndef TEST_H_ -#define TEST_H_ - -namespace foo { - -class Test { - int /*$*/testField/*$$*/; - void foo(); -}; - -} // namespace foo - -#endif -//= -#ifndef TEST_H_ -#define TEST_H_ - -namespace foo { - -class Test { -public: - int getTestField() const; - void setTestField(int testField); - -private: - int testField; - void foo(); -}; - -} // namespace foo - -#endif -//@Test.cpp -#include "Test.h" - -namespace foo { - -void Test::foo() { -} - -} -//= -#include "Test.h" - -namespace foo { - -int Test::getTestField() const { - return testField; -} - -void Test::setTestField(int testField) { - this->testField = testField; -} - -void Test::foo() { -} - -} -//!Bug 337040 - Insert definition in empty implementation file (.cxx) -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=Test.h -getters=testField -setters=testField -definitionSeparate=true - -//@Test.h -#ifndef TEST_H_ -#define TEST_H_ - -class Test { - int /*$*/testField/*$$*/; -}; - -#endif -//= -#ifndef TEST_H_ -#define TEST_H_ - -class Test { -public: - int getTestField() const; - void setTestField(int testField); - -private: - int testField; -}; - -#endif -//@Test.cxx - -//= -int Test::getTestField() const { - return testField; -} - -void Test::setTestField(int testField) { - this->testField = testField; -} -//!Bug 337040 - Insert definition in empty implementation file in complex directory structure -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=component_b/public_headers/Test.h -getters=testField -setters=testField -definitionSeparate=true - -//@component_b/public_headers/Test.h -#ifndef TEST_H_ -#define TEST_H_ - -class Test { - int /*$*/testField/*$$*/; -}; - -#endif -//= -#ifndef TEST_H_ -#define TEST_H_ - -class Test { -public: - int getTestField() const; - void setTestField(int testField); - -private: - int testField; -}; - -#endif -//@component_b/implementation/Test.cpp - -//= -int Test::getTestField() const { - return testField; -} - -void Test::setTestField(int testField) { - this->testField = testField; -} -//@component_a/public_headers/Test.h - -//= - -//@component_a/implementation/Test.cpp - -//= - -//!Bug 363244 - Generate Getters and Setters for class with macro -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=test -//@A.h -#ifndef A_H_ -#define A_H_ - -#define Typedef \ - typedef int Int - -class Test -{ -public: - Typedef; - - void Foo(); - Test(); - - int /*$*/test/*$$*/; -}; -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -#define Typedef \ - typedef int Int - -class Test -{ -public: - Typedef; - - void Foo(); - Test(); - - int getTest() const { - return test; - } - - int test; -}; -#endif /* A_H_ */ -//!Bug 319278 - Getter for an array field -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=a -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -private: - int /*$*/a[2]/*$$*/; -}; -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - const int* getA() const { - return a; - } - -private: - int a[2]; -}; -#endif /* A_H_ */ -//!Bug 352258 - Avoiding reserved names -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=A.h -getters=mClass -setters=mClass -//@A.h -#ifndef A_H_ -#define A_H_ - -class getClass { -private: - int /*$*/mClass/*$$*/; -}; -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -class getClass { -public: - int getClass1() const { - return mClass; - } - - void setClass(int clazz) { - mClass = clazz; - } - -private: - int mClass; -}; -#endif /* A_H_ */ diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts index 9329f5d7ded..31440b3d883 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts @@ -1361,7 +1361,7 @@ private: //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=A.cpp -fatalerrors=1 +fatalerror=true //@A.cpp int /*$*/main/*$$*/() { int i = 2; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts deleted file mode 100644 index 4ac721ac2a1..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts +++ /dev/null @@ -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; -} - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts deleted file mode 100644 index f84ae165492..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts +++ /dev/null @@ -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 - T /*$*/member/*$$*/() { - return T(); - } -}; -//= -class A { - // Top comment - template - T member(); -}; - -// Top comment -template -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 */ diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts deleted file mode 100644 index 70d269f1b47..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts +++ /dev/null @@ -1,141 +0,0 @@ -//!HeaderToClassBodyComment1 -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -template -class A { - T /*$*/member/*$$*/(); -}; - -template -inline T A::member() { - // body comment - return T(); -} -//= -template -class A { - T member() { - // body comment - return T(); - } -}; -//!HeaderToClassRetainTopComments -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -template -class A { - // First comment - // Second comment - T /*$*/member/*$$*/(); -}; - -// Third comment -// Fourth comment -template -inline T A::member() { - return T(); -} -//= -template -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 -class A { - T /*$*/member/*$$*/(); -}; - -template -inline T A::member() -try { - // body comment - return T(); -} -catch (int e) { - // Catch 1 -} -catch (int e) { - // Catch 2 -} -//= -template -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 -class A { - // Top Comment - template - T /*$*/member/*$$*/(); -}; - -// 2nd Top Comment -template -template -inline T A::member() { - // body comment - return T(); -} -//= -template -class A { - // Top Comment - template - T member() { - // body comment - return T(); - } -}; -//!HeaderToClassBodyComment -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -template -class A { - T /*$*/member/*$$*/(); -}; - -// Top comment -template -inline T A::member() { - return T(); -} -//= -template -class A { - // Top comment - T member() { - return T(); - } -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts deleted file mode 100644 index 95ac67e6d36..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts deleted file mode 100644 index 64a295bb055..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts deleted file mode 100644 index f4832deaec6..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts +++ /dev/null @@ -1,242 +0,0 @@ -//!TestConstructorToggleInClassToInHeader -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -class A { -private: - int a; - int b; - -public: - /*$*/A/*$$*/(int x, int y) : - a(x), b(y) { - } - ~A() { - } -}; -//= -#include - -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 - -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 - -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 - -class A { - A(int x, int y); - ~A() { - } -}; -//= -#include - -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 - -class A { -private: - int a; - int b; - -public: - /*$*/~A/*$$*/() { - } -}; -//= -#include - -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 - -class A { -private: - int a; - int b; - -public: - ~A(); -}; - -inline /*$*/A::~A/*$$*/() { -} -//= -#include - -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 - -class A { - A(int x, int y) : - a(x), b(y) { - } - ~A(); -}; -//= -#include - -class A { - A(int x, int y) : - a(x), b(y) { - } - ~A() { - int x; - int y; - return; - } -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts deleted file mode 100644 index 8c7d3b7c23a..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts +++ /dev/null @@ -1,92 +0,0 @@ -//!TestDefaultParameterInitializerInClassToInHeader -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -class A { - void /*$*/member/*$$*/(int a = 0, int b = 0) { - return; - } -}; -//= -#include - -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 - -class A { - void member(int a = 0, int b = 0); -}; - -inline void /*$*/A::member/*$$*/(int a, int b) { - return; -} -//= -#include - -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 - -class A { - void member(int a = 0, int b = 0); -}; -//= -#include - -class A { - void member(int a = 0, int b = 0) { - return; - } -}; \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts deleted file mode 100644 index a08d9a0453a..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts +++ /dev/null @@ -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 -#include - -namespace N { - -class A { - void foo(); -}; - -} -//= -#include -#include - -namespace N { - -class A { - void foo() { - return; - } -}; - -} -//!TestImplementationToClassWithDeclarationSelected -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include -#include - -namespace N { - -class A { - void /*$*/foo/*$$*/(); -}; - -} - -//= -#include -#include - -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleErrorRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleErrorRefactoring.rts deleted file mode 100644 index 307f138e3ef..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleErrorRefactoring.rts +++ /dev/null @@ -1,105 +0,0 @@ -//!TestNotSupportedVariableSelection -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -fatalerror=true -//@A.h -#include - -class A { -public: - void foo() { - } - -private: - int /*$*/x/*$$*/; -}; - -//!TestNotSupportedNoDefinition -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -fatalerror=true -//@A.h -#include - -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 - -class A { -public: - void /*$*/foo/*$$*/(); -}; - -//!TestMultipleDeclarations -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -fatalerror=true -//@A.h -#include - -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 - -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 - -class A { - void foo() { - void /*$*/bar/*$$*/() { - } - } -}; \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts deleted file mode 100644 index d17f1fb9365..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts +++ /dev/null @@ -1,260 +0,0 @@ -//!TestFreeFunctionToggleFromHeaderToImplementation -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -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 - -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 - -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 - -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 - -class A { -private: - int a; - int b; - -public: - A(int x, int y) : - a(x), b(y) { - } - ~A() { - } -}; -//= -#include - -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 - -namespace N { - -void /*$*/freefunction/*$$*/() { - return; -} - -} - -#endif /* A_H_ */ -//= -#ifndef A_H_ -#define A_H_ - -#include - -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; -} - -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts deleted file mode 100644 index ec4baa9d2ce..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts +++ /dev/null @@ -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 -#include - -namespace N { - -class A { - void /*$*/foo/*$$*/() { - return; - } -}; - -} -//= -#include -#include - -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 -#include - -namespace N { - -class A { - void foo(); -}; - -inline void A::/*$*/foo/*$$*/() { - return; -} - -} -//= -#include -#include - -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 -#include - -namespace N { - -class A { - void foo(); -}; - -inline void A::/*$*/foo/*$$*/() { - return; -} - -} -//= -#include -#include - -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 -#include - -namespace N { - -class A { - void foo(); -}; - -} - -inline void /*$*/N::A::foo/*$$*/() { - return; -} -//= -#include -#include - -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 - -namespace N { - -class A { - void foo(); -}; - -} -//= -#include - -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 - -namespace N { - -class A { - void foo(); -}; - -} -//= -#include - -namespace N { - -class A { - void foo() { - return; - } -}; - -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts deleted file mode 100644 index c2e2372d430..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts +++ /dev/null @@ -1,104 +0,0 @@ -//!TestNestedClassInClassToInHeader -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -class A { - class B { - void /*$*/member/*$$*/(int a, int b) { - return; - } - }; -}; -//= -#include - -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 - -class A { - class B { - void member(int a, int b); - }; -}; - -inline void A::B::/*$*/member/*$$*/(int a, int b) { - return; -} -//= -#include - -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 - -class A { - class B { - void member(int a, int b); - }; -}; -//= -#include - -class A { - class B { - void member(int a, int b) { - return; - } - }; -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts deleted file mode 100644 index 2622b732712..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts +++ /dev/null @@ -1,202 +0,0 @@ -//!TestCorrectOrderingInClassToInHeader -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -class A { -public: - void func1(); - void /*$*/func2/*$$*/() { - } - void func3(); - void func4() { - } -}; - -inline void A::func1() { -} - -inline void A::func3() { -} -//= -#include - -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 - -class A { -public: - void func1(); - void func2(); - void func3(); - void func4() { - } -}; - -inline void A::/*$*/func2/*$$*/() { - return; -} -//= -#include - -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 - -template -class A { -public: - void func1(); - void /*$*/func2/*$$*/() { - } - void func3(); - void func4() { - } -}; - -template -inline void A::func1() { -} - -template -inline void A::func3() { -} -//= -#include - -template -class A { -public: - void func1(); - void func2(); - void func3(); - void func4() { - } -}; - -template -inline void A::func1() { -} - -template -inline void A::func2() { -} - -template -inline void A::func3() { -} -//!TestCorrectTemplateOrderingInHeaderToInClass -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include - -template -class A { -public: - void func1(); - void func2(); - void func3(); - void func4() { - } -}; - -template -inline void A::func1() { -} - -template -inline void A::/*$*/func2/*$$*/() { -} - -template -inline void A::func3() { -} -//= -#include - -template -class A { -public: - void func1(); - void func2() { - } - void func3(); - void func4() { - } -}; - -template -inline void A::func1() { -} - -template -inline void A::func3() { -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSelection.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSelection.rts deleted file mode 100644 index 0518f02bad3..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSelection.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts deleted file mode 100644 index b15bc2123c5..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts +++ /dev/null @@ -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 - -class A { -public: - int /*$*/function/*$$*/() { - return 0; - } - -private: - int a; -}; -//= -#include - -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 - -class A { -public: - int function(); - -private: - int a; -}; - -inline int A::/*$*/function/*$$*/() { - return 0; -} -//= -#include - -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 - -class A { -public: - int function(); - -private: - int a; -}; -//= -#include - -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) { - } -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts deleted file mode 100644 index b3249535f8d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts +++ /dev/null @@ -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 - -template -class A { - class B { - T /*$*/member/*$$*/() { - return T(); - } - }; -}; -//= -#include - -template -class A { - class B { - T member(); - }; -}; - -template -inline T A::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 - -template -class A { - class B { - T member(); - }; -}; - -template -inline T A::B::/*$*/member/*$$*/() { - return T(); -} -//= -#include - -template -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/*$$*/ - T foo() { - return T(); - } -}; -//= -class A { - template - T foo(); -}; - -template -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 -class A { -public: - template - void /*$*/foo/*$$*/(const U& u, const V& v) { - return; - } -}; -//= -template -class A { -public: - template - void foo(const U& u, const V& v); -}; - -template -template -inline void A::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 -class A { -public: - template - void /*$*/foo/*$$*/(const U& u, const V& v); -}; - -template -template -inline void A::foo(const U& u, const V& v) { - return; -} -//= -template -class A { -public: - template - void foo(const U& u, const V& v) { - return; - } -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts deleted file mode 100644 index 1aa25624edb..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts +++ /dev/null @@ -1,262 +0,0 @@ -//!TestTryCatchFromInClassToInHeader -//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest -//@.config -filename=A.h -//@A.h -#include -#include - -class A { - void /*$*/member/*$$*/(int a, int b) - try { - return; - } - catch (std::exception& e1){ - return; - } -}; -//= -#include -#include - -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 -#include - -class A { - void member(int a, int b); -}; - -inline void /*$*/A::member/*$$*/(int a, int b) -try { - return; -} -catch (std::exception& e1) { - return; -} -//= -#include -#include - -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 -#include "A.h" - -void A::/*$*/member/*$$*/() -try { - return; -} -catch (std::exception& e1) { - return; -} - -int main() { - return 0; -} -//= -#include -#include "A.h" - -int main() { - return 0; -} -//@A.h -#include - -class A { - void member(); -}; -//= -#include - -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 -#include - -class A { - void /*$*/member/*$$*/(int a, int b) - try { - return; - } - catch (std::exception& e1) { - return; - } - catch (std::exception& e2) { - return; - } -}; -//= -#include -#include - -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 -#include - -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 -#include - -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 -#include "A.h" - -void A::/*$*/member/*$$*/() -try { - return; -} -catch (std::exception& e1) { - return; -} -catch (std::exception& e2) { - return; -} - -int main() { - return 0; -} -//= -#include -#include "A.h" - -int main() { - return 0; -} -//@A.h -#include - -class A { - void member(); -}; -//= -#include - -class A { - void member() - try { - return; - } - catch (std::exception& e1) { - return; - } - catch (std::exception& e2) { - return; - } -}; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts deleted file mode 100644 index 5be3a7a7612..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java index a2ab8fefe9c..d45db58bd66 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2009, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -19,14 +19,14 @@ import java.util.Properties; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; - /** * @author Emanuel Graf IFS */ @@ -39,8 +39,7 @@ public class RefactoringHistoryTest extends RefactoringTest { @Override protected void configureRefactoring(Properties refactoringProperties) { - scriptFile = fileMap.get(refactoringProperties.getProperty( - "scriptFile", "refScript.xml")); + scriptFile = fileMap.get(refactoringProperties.getProperty("scriptFile", "refScript.xml")); } @Override @@ -52,25 +51,12 @@ public class RefactoringHistoryTest extends RefactoringTest { new ByteArrayInputStream(xmlSource.getBytes()), 0); for (RefactoringDescriptorProxy proxy : refHist.getDescriptors()) { RefactoringStatus status = new RefactoringStatus(); - Refactoring ref = proxy.requestDescriptor(new NullProgressMonitor()).createRefactoring(status); + RefactoringDescriptor descriptor = proxy.requestDescriptor(new NullProgressMonitor()); + RefactoringContext context = descriptor.createRefactoringContext(status); assertTrue(status.isOK()); - RefactoringStatus checkInitialConditions = ref.checkInitialConditions(NULL_PROGRESS_MONITOR); - - if (fatalError) { - assertConditionsFatalError(checkInitialConditions); - return; - } else { - assertConditionsOk(checkInitialConditions); - executeRefactoring(ref); - } + Refactoring refactoring = context.getRefactoring(); + executeRefactoring(refactoring, context, false); + compareFiles(fileMap); } } - - protected void executeRefactoring(Refactoring refactoring) throws Exception { - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(finalConditions); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - createChange.perform(NULL_PROGRESS_MONITOR); - compareFiles(fileMap); - } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java index 45adc3efb53..dd3d9aaae08 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -17,6 +17,10 @@ import java.io.IOException; import java.util.Collection; import java.util.Properties; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; @@ -25,17 +29,23 @@ import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.ui.testplugin.CTestPlugin; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** + * Don't create new tests based on this class. Use RefactoringTestBase instead. + * * @author Emanuel Graf */ public abstract class RefactoringTest extends RefactoringBaseTest { private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$ protected String fileName; - protected RefactoringASTCache astCache; protected boolean fatalError; + protected int initialErrors; + protected int initialWarnings; + protected int finalWarnings; + protected int finalInfos; public RefactoringTest(String name, Collection files) { super(name, files); @@ -44,6 +54,62 @@ public abstract class RefactoringTest extends RefactoringBaseTest { protected abstract void configureRefactoring(Properties refactoringProperties); + protected void executeRefactoring(Refactoring refactoring) throws CoreException { + RefactoringContext context = refactoring instanceof CRefactoring2 ? + new CRefactoringContext((CRefactoring2) refactoring) : + new RefactoringContext(refactoring); + executeRefactoring(refactoring, context, true); + } + + protected void executeRefactoring(Refactoring refactoring, boolean withUserInput) throws CoreException { + RefactoringContext context = refactoring instanceof CRefactoring2 ? + new CRefactoringContext((CRefactoring2) refactoring) : + new RefactoringContext(refactoring); + executeRefactoring(refactoring, context, withUserInput); + } + + protected void executeRefactoring(Refactoring refactoring, RefactoringContext context, + boolean withUserInput) throws CoreException { + try { + RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); + + if (fatalError) { + assertConditionsFatalError(checkInitialConditions); + return; + } + if (initialErrors != 0) { + assertConditionsError(checkInitialConditions, initialErrors); + } else if (initialWarnings != 0) { + assertConditionsFatalError(checkInitialConditions, initialWarnings); + } else { + assertConditionsOk(checkInitialConditions); + } + + if (withUserInput) + simulateUserInput(); + + RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); + if (finalWarnings > 0) { + assertConditionsWarning(finalConditions, finalWarnings); + } else if (finalInfos > 0) { + assertConditionsInfo(finalConditions, finalInfos); + } else { + assertConditionsOk(finalConditions); + } + Change change = refactoring.createChange(NULL_PROGRESS_MONITOR); + change.perform(NULL_PROGRESS_MONITOR); + } finally { + if (context != null) + context.dispose(); + } + } + + /** + * Subclasses can override to simulate user input. + */ + protected void simulateUserInput() { + } + @Override protected void setUp() throws Exception { super.setUp(); @@ -52,12 +118,10 @@ public abstract class RefactoringTest extends RefactoringBaseTest { CCorePlugin.getIndexManager().reindex(cproject); boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR); assertTrue(joined); - astCache = new RefactoringASTCache(); } @Override protected void tearDown() throws Exception { - astCache.dispose(); super.tearDown(); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java index 5f7f26e8505..b98a640d0cb 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java @@ -24,9 +24,12 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.TextSelection; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; @@ -36,13 +39,18 @@ import org.osgi.framework.Bundle; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.testplugin.CTestPlugin; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** * Common base for refactoring tests. @@ -51,8 +59,9 @@ public abstract class RefactoringTestBase extends BaseTestCase { private static final int INDEXER_TIMEOUT_SEC = 360; protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); + protected boolean createEmptyFiles = true; + protected boolean ascendingVisibilityOrder; private boolean cpp = true; - private RefactoringASTCache astCache; private ICProject cproject; private final Set testFiles = new LinkedHashSet(); private TestSourceFile selectedFile; @@ -70,6 +79,7 @@ public abstract class RefactoringTestBase extends BaseTestCase { @Override public void setUp() throws Exception { super.setUp(); + resetPreferences(); cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); @@ -95,7 +105,7 @@ public abstract class RefactoringTestBase extends BaseTestCase { } reader.close(); - if (!testFile.getSource().isEmpty()) { + if (createEmptyFiles || !testFile.getSource().isEmpty()) { TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()), testFile.getSource()); } @@ -111,16 +121,15 @@ public abstract class RefactoringTestBase extends BaseTestCase { CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, NULL_PROGRESS_MONITOR)); - astCache = new RefactoringASTCache(); } @Override public void tearDown() throws Exception { - astCache.dispose(); if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, NULL_PROGRESS_MONITOR); } + resetPreferences(); super.tearDown(); } @@ -134,30 +143,45 @@ public abstract class RefactoringTestBase extends BaseTestCase { } private void executeRefactoring(boolean expectedSuccess) throws Exception { + if (ascendingVisibilityOrder) { + getPreferenceStore().setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, + ascendingVisibilityOrder); + } if (historyScript != null) { executeHistoryRefactoring(expectedSuccess); return; } Refactoring refactoring = createRefactoring(); - executeRefactoring(refactoring, true, expectedSuccess); + RefactoringContext context; + if (refactoring instanceof CRefactoring2) { + context = new CRefactoringContext((CRefactoring2) refactoring); + } else { + context = new RefactoringContext(refactoring); + } + executeRefactoring(refactoring, context, true, expectedSuccess); } - protected void executeRefactoring(Refactoring refactoring, boolean withUserInput, - boolean expectedSuccess) throws CoreException, Exception { - RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - if (!expectedSuccess) { - assertStatusFatalError(initialStatus); - return; - } + protected void executeRefactoring(Refactoring refactoring, RefactoringContext context, + boolean withUserInput, boolean expectedSuccess) throws CoreException, Exception { + try { + RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); + if (!expectedSuccess) { + assertStatusFatalError(initialStatus); + return; + } - assertStatusOk(initialStatus); - if (withUserInput) - simulateUserInput(); - RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertStatusOk(finalStatus); - Change change = refactoring.createChange(NULL_PROGRESS_MONITOR); - change.perform(NULL_PROGRESS_MONITOR); + assertStatusOk(initialStatus); + if (withUserInput) + simulateUserInput(); + RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); + assertStatusOk(finalStatus); + Change change = refactoring.createChange(NULL_PROGRESS_MONITOR); + change.perform(NULL_PROGRESS_MONITOR); + } finally { + if (context != null) + context.dispose(); + } } private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception { @@ -166,11 +190,11 @@ public abstract class RefactoringTestBase extends BaseTestCase { RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory( new ByteArrayInputStream(scriptSource.getBytes()), 0); for (RefactoringDescriptorProxy proxy : history.getDescriptors()) { + RefactoringDescriptor descriptor = proxy.requestDescriptor(NULL_PROGRESS_MONITOR); RefactoringStatus status = new RefactoringStatus(); - Refactoring refactoring = - proxy.requestDescriptor(NULL_PROGRESS_MONITOR).createRefactoring(status); + RefactoringContext context = descriptor.createRefactoringContext(status); assertTrue(status.isOK()); - executeRefactoring(refactoring, false, expectedSuccess); + executeRefactoring(context.getRefactoring(), context, false, expectedSuccess); } } @@ -199,6 +223,13 @@ public abstract class RefactoringTestBase extends BaseTestCase { return cproject.getProject().getFile(new Path(selectedFile.getName())); } + protected ITranslationUnit getSelectedTranslationUnit() { + IFile file = getSelectedFile(); + if (file == null) + return null; + return (ITranslationUnit) CoreModel.getDefault().create(file); + } + protected TestSourceFile getHistoryScriptFile() { return historyScript; } @@ -305,14 +336,21 @@ public abstract class RefactoringTestBase extends BaseTestCase { } protected String getFileContents(IFile file) throws Exception { - BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents())); - StringBuilder code = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - code.append(line); - code.append('\n'); - } + BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents(), "UTF-8")); + StringBuilder buffer = new StringBuilder(); + char[] part= new char[2048]; + int read= 0; + while ((read= reader.read(part)) != -1) + buffer.append(part, 0, read); reader.close(); - return code.toString(); + return buffer.toString(); + } + + protected void resetPreferences() { + getPreferenceStore().setToDefault(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER); + } + + protected IPreferenceStore getPreferenceStore() { + return CUIPlugin.getDefault().getPreferenceStore(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java index 404b4ddde2b..79c696ce73f 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,14 +16,14 @@ package org.eclipse.cdt.ui.tests.refactoring; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantTestSuite; +import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableTestSuite; -import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTestSuite; +import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest; import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodTestSuite; import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodTestSuite; import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests; -import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTestSuite; +import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToogleRefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite; /** @@ -36,12 +36,12 @@ public class RefactoringTestSuite extends TestSuite { suite.addTest(UtilTestSuite.suite()); suite.addTest(RenameRegressionTests.suite()); suite.addTest(ExtractFunctionRefactoringTest.suite()); - suite.addTest(ExtractConstantTestSuite.suite()); + suite.addTest(ExtractConstantRefactoringTest.suite()); suite.addTest(HideMethodTestSuite.suite()); - suite.addTest(GenerateGettersAndSettersTestSuite.suite()); + suite.addTest(GenerateGettersAndSettersTest.suite()); suite.addTest(ImplementMethodTestSuite.suite()); suite.addTest(ExtractLocalVariableTestSuite.suite()); - suite.addTest(ToggleRefactoringTestSuite.suite()); + suite.addTest(ToogleRefactoringTest.suite()); return suite; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java index b45d7c44a31..8cf74bdddd8 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,52 +8,788 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.extractconstant; -import java.util.Collection; -import java.util.Properties; +import junit.framework.Test; -import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; -import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantInfo; import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; /** - * @author Emanuel Graf + * Tests for Extract Constant refactoring. */ -public class ExtractConstantRefactoringTest extends RefactoringTest { - protected VisibilityEnum visibility; +public class ExtractConstantRefactoringTest extends RefactoringTestBase { + private ExtractConstantInfo refactoringInfo; + private String extractedConstantName = "EXTRACTED"; + private VisibilityEnum visibility = VisibilityEnum.v_private; - public ExtractConstantRefactoringTest(String name, Collection files) { - super(name, files); + public ExtractConstantRefactoringTest() { + super(); + } + + public ExtractConstantRefactoringTest(String name) { + super(name); + } + + public static Test suite() { + return suite(ExtractConstantRefactoringTest.class); } @Override - protected void runTest() throws Throwable { - IFile refFile = project.getFile(fileName); - ExtractConstantInfo info = new ExtractConstantInfo(); - CRefactoring refactoring = new ExtractConstantRefactoring(refFile, selection, info, cproject); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(checkInitialConditions); - info.setName("theAnswer"); //$NON-NLS-1$ - info.setVisibility(visibility); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(finalConditions); - createChange.perform(NULL_PROGRESS_MONITOR); - compareFiles(fileMap); + protected Refactoring createRefactoring() { + refactoringInfo = new ExtractConstantInfo(); + return new ExtractConstantRefactoring(getSelectedFile(), getSelection(), refactoringInfo, + getCProject()); } @Override - protected void configureRefactoring(Properties refactoringProperties) { - visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_public.toString())); //$NON-NLS-1$ + protected void simulateUserInput() { + refactoringInfo.setName(extractedConstantName); + refactoringInfo.setVisibility(visibility); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + // + //private: + // static const int EXTRACTED = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return /*$*/42/*$$*/; //Hello + //} + // + //void A::bar() { + // int a = 42; + // int b = 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return EXTRACTED; //Hello + //} + // + //void A::bar() { + // int a = EXTRACTED; + // int b = EXTRACTED; + //} + public void testExtractConstantInt() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + // + //private: + // static const int EXTRACTED = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // //Hello + // return /*$*/42/*$$*/; + //} + // + //void A::bar() { + // int a = 42; + // int b = 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // //Hello + // return EXTRACTED; + //} + // + //void A::bar() { + // int a = EXTRACTED; + // int b = EXTRACTED; + //} + public void testExtractConstantInt2() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // float foo(); + // void bar(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // float foo(); + // void bar(); + // + //private: + // static const float EXTRACTED = 42.0f; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //float A::foo() { + // return /*$*/42.0f/*$$*/; + //} + // + //void A::bar() { + // float a = 42.0f; + // float b = 42.0f; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //float A::foo() { + // return EXTRACTED; + //} + // + //void A::bar() { + // float a = EXTRACTED; + // float b = EXTRACTED; + //} + public void testExtractConstantFloat() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // double foo(); + // void bar(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // double foo(); + // void bar(); + // + //private: + // static const double EXTRACTED = 42.0; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //double A::foo() { + // return /*$*/42.0/*$$*/; + //} + // + //void A::bar() { + // double a = 42.0; + // double b = 42.0; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //double A::foo() { + // return EXTRACTED; + //} + // + //void A::bar() { + // double a = EXTRACTED; + // double b = EXTRACTED; + //} + public void testExtractConstantDouble() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // static const int a = 42; + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // static const int a = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return 42; + //} + // + //int bar() { + // return /*$*/42/*$$*/; + //} + //==================== + //#include "A.h" + // + //namespace { + // + //const int EXTRACTED = 42; + // + //} + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return EXTRACTED; + //} + // + //int bar() { + // return EXTRACTED; + //} + public void testExtractConstantStaticInt() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //protected: + // static const int EXTRACTED = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return /*$*/42/*$$*/; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return EXTRACTED; + //} + public void testReplaceNumberProtected() throws Exception { + visibility = VisibilityEnum.v_protected; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // static const int EXTRACTED = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return /*$*/42/*$$*/; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return EXTRACTED; + //} + public void testReplaceNumberPrivate() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class X { + // void method() { + // int a = /*$*/42/*$$*/; + // } + //}; + //==================== + //class X { + //public: + // static const int EXTRACTED = 42; + // + //private: + // void method() { + // int a = EXTRACTED; + // } + //}; + public void testExtractConstantFromInlinedMethod_Bug246062() throws Exception { + visibility = VisibilityEnum.v_public; + assertRefactoringSuccess(); + } + + //A.h + //class X { + // void method() { + // char* a = /*$*/"sometext"/*$$*/; + // } + // + // void method2() { + // const char* b = "sometext"; + // } + //}; + //==================== + //class X { + // void method() { + // char* a = EXTRACTED; + // } + // + // void method2() { + // const char* b = EXTRACTED; + // } + // + // static const char* EXTRACTED = "sometext"; + //}; + public void testString() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class X { + // void method() { + // wchar_t* a = /*$*/L"sometext"/*$$*/; + // } + // + // void method2() { + // const wchar_t* b = L"sometext"; + // const char* c = "sometext"; + // } + //}; + //==================== + //class X { + // void method() { + // wchar_t* a = EXTRACTED; + // } + // + // void method2() { + // const wchar_t* b = EXTRACTED; + // const char* c = "sometext"; + // } + // + // static const wchar_t* EXTRACTED = L"sometext"; + //}; + public void testExtractConstantWideString() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void bar(); + // + // static const int EXTRACTED = 42; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return 42; // Hello + //} + // + //void A::bar() { + // int a = 42; + // int b = 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return EXTRACTED; // Hello + //} + // + //void A::bar() { + // int a = EXTRACTED; + // int b = EXTRACTED; + //} + + //refactoringScript.xml + // + // + // + // + // + 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 + // + // + // + // + 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 + // + // + // + // + public void testHistoryReplaceNumberPrivate() throws Exception { + assertRefactoringSuccess(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantTestSuite.java deleted file mode 100644 index 6805442382a..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantTestSuite.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java index 0654b3fc02c..cf8065c3ddd 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java @@ -18,10 +18,8 @@ import java.util.Map; import junit.framework.Test; -import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; @@ -59,25 +57,12 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase { } @Override - public void setUp() throws Exception { - super.setUp(); - resetPreferences(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - resetPreferences(); - } - - private void resetPreferences() { + protected void resetPreferences() { + super.resetPreferences(); + getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT); getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER); } - private IPreferenceStore getPreferenceStore() { - return CUIPlugin.getDefault().getPreferenceStore(); - } - @Override protected Refactoring createRefactoring() { refactoringInfo = new ExtractFunctionInformation(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java index 4cfec842af2..c63817296ba 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Tom Ball (Google) - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable; @@ -15,14 +16,12 @@ import java.util.Collection; import java.util.Properties; import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring; /** @@ -32,7 +31,6 @@ import org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocal */ public class ExtractLocalVariableRefactoringTest extends RefactoringTest { protected String variableName; - protected boolean fatalError; public ExtractLocalVariableRefactoringTest(String name, Collection files) { super(name, files); @@ -40,22 +38,12 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTest { @Override protected void runTest() throws Throwable { - IFile refFile = project.getFile(fileName); - NameNVisibilityInformation info = new NameNVisibilityInformation(); - info.setName(variableName); - CRefactoring refactoring = new ExtractLocalVariableRefactoring( refFile, selection, info, cproject); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - - if (fatalError){ - assertConditionsFatalError(checkInitialConditions); - return; - } - - assertConditionsOk(checkInitialConditions); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(finalConditions); - createChange.perform(NULL_PROGRESS_MONITOR); + IFile file = project.getFile(fileName); + ICElement element = CoreModel.getDefault().create(file); + ExtractLocalVariableRefactoring refactoring = + new ExtractLocalVariableRefactoring(element, selection, cproject); + refactoring.getRefactoringInfo().setName(variableName); + executeRefactoring(refactoring); compareFiles(fileMap); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTest.java index 2cdeca22683..a7123d396c5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTest.java @@ -1,123 +1,1603 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik - * Rapperswil, University of applied sciences + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * 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: - * Emanuel Graf & Leo Buettiker - initial API and implementation - * Thomas Corbat - implementation + * Institute for Software - initial API and implementation * Sergey Prigogin (Google) - ******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.gettersandsetters; -import java.util.Collection; -import java.util.Properties; +import junit.framework.Test; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; -import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.AccessorDescriptor.AccessorKind; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GenerateGettersAndSettersRefactoring; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterContext; /** - * @author Thomas Corbat + * Tests for Generate Getters and Setters refactoring. */ -public class GenerateGettersAndSettersTest extends RefactoringTest { - protected boolean fatalError; - private int warnings; - private int infos; +public class GenerateGettersAndSettersTest extends RefactoringTestBase { private String[] selectedGetters; private String[] selectedSetters; - private GenerateGettersAndSettersRefactoring refactoring; private boolean definitionSeparate; - private String ascendingVisibilityOrder; + private GenerateGettersAndSettersRefactoring refactoring; - /** - * @param name - * @param files - */ - public GenerateGettersAndSettersTest(String name, Collection files) { - super(name, files); + public GenerateGettersAndSettersTest() { + super(); + } + + public GenerateGettersAndSettersTest(String name) { + super(name); + } + + public static Test suite() { + return suite(GenerateGettersAndSettersTest.class); } @Override - protected void runTest() throws Throwable { - try { - IFile file = project.getFile(fileName); - ICElement element = CoreModel.getDefault().create(file); - refactoring = new GenerateGettersAndSettersRefactoring(element, selection, cproject, astCache); - RefactoringStatus initialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); + public void setUp() throws Exception { + super.setUp(); + resetPreferences(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + resetPreferences(); + } - if (fatalError) { - assertConditionsFatalError(initialConditions); - return; - } else { - assertConditionsOk(initialConditions); - executeRefactoring(); - } - } finally { - IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore(); - store.setToDefault(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER); + @Override + protected Refactoring createRefactoring() { + if (ascendingVisibilityOrder) { + getPreferenceStore().setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, + ascendingVisibilityOrder); } + refactoring = new GenerateGettersAndSettersRefactoring(getSelectedTranslationUnit(), getSelection(), + getCProject()); + return refactoring; } - private void executeRefactoring() throws CoreException, Exception { - if (ascendingVisibilityOrder != null) { - IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore(); - store.setValue(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, ascendingVisibilityOrder); - } - selectFields(); - refactoring.getContext().setDefinitionSeparate(definitionSeparate); - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - if (warnings > 0) { - assertConditionsWarning(finalConditions, warnings); - } else if (infos > 0) { - assertConditionsInfo(finalConditions, infos); - } else { - assertConditionsOk(finalConditions); - } - - createChange.perform(NULL_PROGRESS_MONITOR); - compareFiles(fileMap); - } - - private void selectFields() { + @Override + protected void simulateUserInput() { GetterSetterContext context = refactoring.getContext(); - - for (String name : selectedGetters) { - context.selectAccessorForField(name, AccessorKind.GETTER); + + if (selectedGetters != null) { + for (String name : selectedGetters) { + context.selectAccessorForField(name, AccessorKind.GETTER); + } } - for (String name : selectedSetters) { - context.selectAccessorForField(name, AccessorKind.SETTER); + if (selectedSetters != null) { + for (String name : selectedSetters) { + context.selectAccessorForField(name, AccessorKind.SETTER); + } } + context.setDefinitionSeparate(definitionSeparate); } - - @Override - protected void configureRefactoring(Properties refactoringProperties) { - fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$ - warnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ - infos = new Integer(refactoringProperties.getProperty("infos", "0")); - String getters = refactoringProperties.getProperty("getters", ""); //$NON-NLS-1$ //$NON-NLS-2$ - String setters = refactoringProperties.getProperty("setters", ""); //$NON-NLS-1$ //$NON-NLS-2$ - definitionSeparate = Boolean.valueOf(refactoringProperties.getProperty("definitionSeparate", "false")); - ascendingVisibilityOrder = refactoringProperties.getProperty("ascendingVisibilityOrder", null); - - selectedGetters = getters.split(","); - selectedSetters = setters.split(","); + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // char* getName() const { + // return name; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + public void testOneGetterSelection() throws Exception { + selectedGetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //namespace Personal { + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //} + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //namespace Personal { + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // char* getName() const { + // return name; + // } + //}; + // + //} + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + public void testOneGetterSelectionWithNamespace() throws Exception { + selectedGetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // void setName(char* name) { + // this->name = name; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + public void testOneSetterSelection() throws Exception { + selectedSetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // char* getName() const { + // return name; + // } + // + // void setName(char* name) { + // this->name = name; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + public void testGetterAndSetterSelection() throws Exception { + selectedGetters = new String[] { "name" }; + selectedSetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // char* getName() const { + // return name; + // } + // + // void setName(char* name) { + // this->name = name; + // } + // + // int getSystemId() const { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + public void testMultipleSelection() throws Exception { + selectedGetters = new String[] { "name", "systemId" }; + selectedSetters = new String[] { "name", "systemId" }; + assertRefactoringSuccess(); + } + + //GaS.h + //#ifndef GAS_H_ + //#define GAS_H_ + // + //class GaS { + //public: + // GaS(); + // virtual ~GaS(); + // bool /*$*/ok/*$$*/; + // void method2(); + // + //private: + // int i; + //}; + // + //#endif + //==================== + //#ifndef GAS_H_ + //#define GAS_H_ + // + //class GaS { + //public: + // GaS(); + // virtual ~GaS(); + // bool ok; + // void method2(); + // + // int getI() const { + // return i; + // } + // + // void setI(int i) { + // this->i = i; + // } + // + // bool isOk() const { + // return ok; + // } + // + // void setOk(bool ok) { + // this->ok = ok; + // } + // + //private: + // int i; + //}; + // + //#endif + + //GaS.cpp + //#include "Getters.h" + // + //GaS::Getters() { + //} + // + //GaS::~Getters() { + //} + public void testVisibilityOrder() throws Exception { + selectedGetters = new String[] { "i", "ok" }; + selectedSetters = new String[] { "i", "ok" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int /*$*/id/*$$*/; + //}; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //public: + // int getId() const { + // return id; + // } + // + // void setId(int id) { + // this->id = id; + // } + // + //private: + // int id; + //}; + // + //#endif /* A_H_ */ + public void testNoMethods() throws Exception { + selectedGetters = new String[] { "id" }; + selectedSetters = new String[] { "id" }; + assertRefactoringSuccess(); + } + + //A.h + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + // int /*$*/i/*$$*/; //comment2 + // char* b; + // //comment3 + //}; + // + //#endif /* TEST_H_ */ + //==================== + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + // int i; //comment2 + // char* b; + // //comment3 + // + //public: + // int getI() const { + // return i; + // } + // + // void setI(int i) { + // this->i = i; + // } + //}; + // + //#endif /* TEST_H_ */ + public void testNoMethodsAscendingVisibilityOrder() throws Exception { + selectedGetters = new String[] { "i" }; + selectedSetters = new String[] { "i" }; + ascendingVisibilityOrder = true; + assertRefactoringSuccess(); + } + + //A.h + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + // void /*$*/test/*$$*/(); + // //comment3 + //}; + // + //#endif /* TEST_H_ */ + //==================== + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + // void test(); + // //comment3 + //}; + // + //#endif /* TEST_H_ */ + public void testNoFields() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //struct FullName { + // const char* first; + // const char* last; + // FullName(const FullName& other); + // ~FullName(); + //}; + // + //class Person { + //private: + // int systemId; + // + //protected: + // FullName name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId(); + // + // void setSystemId(int systemId); + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //struct FullName { + // const char* first; + // const char* last; + // FullName(const FullName& other); + // ~FullName(); + //}; + // + //class Person { + //private: + // int systemId; + // + //protected: + // FullName name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId(); + // + // void setSystemId(int systemId); + // const FullName& getName() const; + // void setName(const FullName& name); + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + //#include "A.h" + // + //const FullName& Person::getName() const { + // return name; + //} + // + //void Person::setName(const FullName& name) { + // this->name = name; + //} + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + public void testPassByReferenceSeparateDefinition() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "name" }; + selectedSetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //namespace Personal { + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //} + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //namespace Personal { + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // char* getName() const; + //}; + // + //} + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //namespace Personal { + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //} // namespace Personal + // + //int main(int argc, char** argv) { + //} + //==================== + //#include "A.h" + // + //namespace Personal { + // + //char* Person::getName() const { + // return name; + //} + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //} // namespace Personal + // + //int main(int argc, char** argv) { + //} + public void testOneGetterSelectionWithNamespaceSeparateDefinition() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // void setName(char* name); + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + //#include "A.h" + // + //void Person::setName(char* name) { + // this->name = name; + //} + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + public void testOneSetterSelectionSeparateDefinition() throws Exception { + definitionSeparate = true; + selectedSetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int /*$*/SocSecNo/*$$*/(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int systemId; + // + //protected: + // char* name; + // + //public: + // const int socSecNo; + // + // Person myFriend; + // + // Person(int socSecNo); // constructor + // + // ~Person(); // destructor + // + // char* Name(); + // + // void Print(); + // + // int SocSecNo(); + // + // int GetUniqueId(); + // + // int getSystemId() { + // return systemId; + // } + // + // void setSystemId(int systemId) { + // this->systemId = systemId; + // } + // + // char* getName() const; + // void setName(char* name); + //}; + // + //int gooo = 1; + // + //#endif /* A_H_ */ + + //A.cpp + //#include "A.h" + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + //==================== + //#include "A.h" + // + //char* Person::getName() const { + // return name; + //} + // + //void Person::setName(char* name) { + // this->name = name; + //} + // + //int Person::SocSecNo() { + // return socSecNo; + //} + // + //int main(int argc, char** argv) { + //} + public void testSelectionWithSeparateDefinition() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "name" }; + selectedSetters = new String[] { "name" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //private: + // int /*$*/id/*$$*/; + //}; + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class Person { + //public: + // int getId() const; + // void setId(int id); + // + //private: + // int id; + //}; + // + //inline int Person::getId() const { + // return id; + //} + // + //inline void Person::setId(int id) { + // this->id = id; + //} + // + //#endif /* A_H_ */ + public void testNoMethodsSeparateDefinition_1() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "id" }; + selectedSetters = new String[] { "id" }; + assertRefactoringSuccess(); + } + + //A.h + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + // int /*$*/i/*$$*/; //comment2 + // char* b; + // //comment3 + //}; + // + //#endif /* TEST_H_ */ + //==================== + ///* + // * test.h + // */ + // + //#ifndef TEST_H_ + //#define TEST_H_ + // + ////comment1 + //class test { + //public: + // int getI() const; + // void setI(int i); + // + //private: + // int i; //comment2 + // char* b; + // //comment3 + //}; + // + //inline int test::getI() const { + // return i; + //} + // + //inline void test::setI(int i) { + // this->i = i; + //} + // + //#endif /* TEST_H_ */ + public void testNoMethodsSeparateDefinition_2() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "i" }; + selectedSetters = new String[] { "i" }; + assertRefactoringSuccess(); + } + + //Test.h + //#ifndef TEST_H_ + //#define TEST_H_ + // + //namespace foo { + // + //class Test { + // int /*$*/testField/*$$*/; + // void foo(); + //}; + // + //} // namespace foo + // + //#endif + //==================== + //#ifndef TEST_H_ + //#define TEST_H_ + // + //namespace foo { + // + //class Test { + //public: + // int getTestField() const; + // void setTestField(int testField); + // + //private: + // int testField; + // void foo(); + //}; + // + //} // namespace foo + // + //#endif + + //Test.cpp + //#include "Test.h" + // + //namespace foo { + // + //void Test::foo() { + //} + // + //} + //==================== + //#include "Test.h" + // + //namespace foo { + // + //int Test::getTestField() const { + // return testField; + //} + // + //void Test::setTestField(int testField) { + // this->testField = testField; + //} + // + //void Test::foo() { + //} + // + //} + public void testBug323780() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "testField" }; + selectedSetters = new String[] { "testField" }; + assertRefactoringSuccess(); + } + + //Test.h + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class Test { + // int /*$*/testField/*$$*/; + //}; + // + //#endif + //==================== + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class Test { + //public: + // int getTestField() const; + // void setTestField(int testField); + // + //private: + // int testField; + //}; + // + //#endif + + //Test.cxx + //==================== + //int Test::getTestField() const { + // return testField; + //} + // + //void Test::setTestField(int testField) { + // this->testField = testField; + //} + public void testInsertDefinitionInEmptyImplementationFile_Bug337040_1() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "testField" }; + selectedSetters = new String[] { "testField" }; + assertRefactoringSuccess(); + } + + //component_b/public_headers/Test.h + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class Test { + // int /*$*/testField/*$$*/; + //}; + // + //#endif + //==================== + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class Test { + //public: + // int getTestField() const; + // void setTestField(int testField); + // + //private: + // int testField; + //}; + // + //#endif + + //component_b/implementation/Test.cpp + //==================== + //int Test::getTestField() const { + // return testField; + //} + // + //void Test::setTestField(int testField) { + // this->testField = testField; + //} + + //component_a/public_headers/Test.h + //==================== + + //component_a/implementation/Test.cpp + //==================== + public void testInsertDefinitionInEmptyImplementationFile_Bug337040_2() throws Exception { + definitionSeparate = true; + selectedGetters = new String[] { "testField" }; + selectedSetters = new String[] { "testField" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#define Typedef \ + // typedef int Int + // + //class Test + //{ + //public: + // Typedef; + // + // void Foo(); + // Test(); + // + // int /*$*/test/*$$*/; + //}; + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#define Typedef \ + // typedef int Int + // + //class Test + //{ + //public: + // Typedef; + // + // void Foo(); + // Test(); + // + // int getTest() const { + // return test; + // } + // + // int test; + //}; + //#endif /* A_H_ */ + public void testClassWithMacro_Bug363244() throws Exception { + selectedGetters = new String[] { "test" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //private: + // int /*$*/a[2]/*$$*/; + //}; + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // const int* getA() const { + // return a; + // } + // + //private: + // int a[2]; + //}; + //#endif /* A_H_ */ + public void testGetterForAnArrayField_Bug319278() throws Exception { + selectedGetters = new String[] { "a" }; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class getClass { + //private: + // int /*$*/mClass/*$$*/; + //}; + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class getClass { + //public: + // int getClass1() const { + // return mClass; + // } + // + // void setClass(int clazz) { + // mClass = clazz; + // } + // + //private: + // int mClass; + //}; + //#endif /* A_H_ */ + public void testAvoidingReservedNames_Bug352258() throws Exception { + selectedGetters = new String[] { "mClass" }; + selectedSetters = new String[] { "mClass" }; + assertRefactoringSuccess(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTestSuite.java deleted file mode 100644 index 32b524725d9..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/gettersandsetters/GenerateGettersAndSettersTestSuite.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodRefactoringTest.java index 125110811ca..fb7aee5b765 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.hidemethod; @@ -15,22 +16,17 @@ import java.util.Collection; import java.util.Properties; import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring; /** * @author Guido Zgraggen IFS */ public class HideMethodRefactoringTest extends RefactoringTest { - private int warnings; - private int errors; - private int fatalerrors; public HideMethodRefactoringTest(String name, Collection files) { super(name, files); @@ -39,32 +35,15 @@ public class HideMethodRefactoringTest extends RefactoringTest { @Override protected void runTest() throws Throwable { IFile refFile = project.getFile(fileWithSelection); - CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - if (errors > 0) { - assertConditionsError(checkInitialConditions, errors); - } else if (fatalerrors > 0) { - assertConditionsError(checkInitialConditions, errors); - return; - } else { - assertConditionsOk(checkInitialConditions); - } - - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - if (warnings > 0) { - assertConditionsWarning(finalConditions, warnings); - } else { - assertConditionsOk(finalConditions); - } - createChange.perform(NULL_PROGRESS_MONITOR); + Refactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject); + executeRefactoring(refactoring); compareFiles(fileMap); } @Override protected void configureRefactoring(Properties refactoringProperties) { - warnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ - errors = new Integer(refactoringProperties.getProperty("errors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ - fatalerrors = new Integer(refactoringProperties.getProperty("fatalerrors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ + fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$//$NON-NLS-2$ + finalWarnings = new Integer(refactoringProperties.getProperty("warnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ + initialErrors = new Integer(refactoringProperties.getProperty("errors", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java index 9d5d147179c..199b2aa73a2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Marc-Andre Laperle + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.implementmethod; @@ -16,8 +17,6 @@ import java.util.Collection; import java.util.Properties; import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; @@ -31,9 +30,6 @@ import org.eclipse.cdt.internal.ui.refactoring.implementmethod.ImplementMethodRe * @author Mirko Stocker */ public class ImplementMethodRefactoringTest extends RefactoringTest { - protected int finalWarnings; - private int initialWarnings; - private int infos; public ImplementMethodRefactoringTest(String name, Collection files) { super(name, files); @@ -43,28 +39,8 @@ public class ImplementMethodRefactoringTest extends RefactoringTest { protected void runTest() throws Throwable { IFile refFile = project.getFile(fileName); ICElement element = CoreModel.getDefault().create(refFile); - CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject, astCache); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - - if (initialWarnings == 0) { - assertConditionsOk(checkInitialConditions); - } else { - assertConditionsFatalError(checkInitialConditions, initialWarnings); - return; - } - - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - - if (finalWarnings > 0) { - assertConditionsWarning(finalConditions, finalWarnings); - } else if (infos > 0) { - assertConditionsInfo(finalConditions, infos); - } else { - assertConditionsOk(finalConditions); - } - - createChange.perform(NULL_PROGRESS_MONITOR); + CRefactoring2 refactoring = new ImplementMethodRefactoring(element, selection, cproject); + executeRefactoring(refactoring); compareFiles(fileMap); } @@ -72,6 +48,6 @@ public class ImplementMethodRefactoringTest extends RefactoringTest { protected void configureRefactoring(Properties refactoringProperties) { finalWarnings = new Integer(refactoringProperties.getProperty("finalWarnings", "0")).intValue(); //$NON-NLS-1$//$NON-NLS-2$ initialWarnings = Integer.parseInt(refactoringProperties.getProperty("initialWarnings", "0")); //$NON-NLS-1$//$NON-NLS-2$ - infos = Integer.parseInt(refactoringProperties.getProperty("infos", "0")); //$NON-NLS-1$//$NON-NLS-2$ + finalInfos = Integer.parseInt(refactoringProperties.getProperty("infos", "0")); //$NON-NLS-1$//$NON-NLS-2$ } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/MockToggleRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/MockToggleRefactoringTest.java deleted file mode 100644 index 27196fdda6b..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/MockToggleRefactoringTest.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java deleted file mode 100644 index 32cc7e37448..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java +++ /dev/null @@ -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 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); - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTestSuite.java deleted file mode 100644 index cc0ff4bc61e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTestSuite.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToogleRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToogleRefactoringTest.java new file mode 100644 index 00000000000..6e72349d1eb --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToogleRefactoringTest.java @@ -0,0 +1,2865 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring.togglefunction; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.ltk.core.refactoring.Refactoring; + +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; + +import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring; + +/** + * Tests for Generate Getters and Setters refactoring. + */ +public class ToogleRefactoringTest extends RefactoringTestBase { + private ToggleRefactoring refactoring; + + public ToogleRefactoringTest() { + super(); + } + + public ToogleRefactoringTest(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite = suite(ToogleRefactoringTest.class); + suite.addTestSuite(ToggleNodeHelperTest.class); + return suite; + } + + @Override + public void setUp() throws Exception { + createEmptyFiles = false; + super.setUp(); + } + + @Override + protected Refactoring createRefactoring() { + refactoring = new ToggleRefactoring(getSelectedFile(), getSelection(), getCProject()); + return refactoring; + } + + @Override + protected void simulateUserInput() { + refactoring.getContext().setSettedDefaultAnswer(true); + refactoring.getContext().setDefaultAnswer(true); + } + + //A.h + //void /*$*/freefunction/*$$*/() { + // return; + //} + //==================== + //void freefunction(); + + //A.cpp + //==================== + //#include "A.h" + // + //void freefunction() { + // return; + //} + public void testFileCreationFreeFunctionFromHeaderToImpl() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void /*$*/freefunction/*$$*/() { + // return; + //} + //==================== + //#include "A.h" + // + + //A.h + //==================== + //void freefunction() { + // return; + //} + public void testFileCreationFromImplToHeader() throws Exception { + createEmptyFiles = false; + assertRefactoringSuccess(); + } + + //A.h + //void /*$*/freefunction/*$$*/() { + // return; + //} + //==================== + //void freefunction(); + + //A.cpp + //==================== + //#include "A.h" + // + //void freefunction() { + // return; + //} + public void testFreeFunctionFromHeaderToImpl() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void /*$*/freefunction/*$$*/() { + // return; + //} + //==================== + //#include "A.h" + // + + //A.h + //==================== + //void freefunction() { + // return; + //} + public void testFreeFunctionFromImplToHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //public: + // void foo() { + // } + // + //private: + // int /*$*/x/*$$*/; + //}; + public void testTestNotSupportedVariableSelection() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#include + // + //class A { + //public: + // void /*$*/foo/*$$*/(); + //}; + + //A.cpp + //#include "A.h" + // + //int main() { + // return 0; + //} + public void testTestNotSupportedNoDefinition() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#include + // + //class A { + //public: + // void /*$*/foo/*$$*/(); + //}; + public void testTestNotSupportedNoTranslationunit() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#include + // + //class A { + // void /*$*/foo/*$$*/(); + // void foo(); + //}; + + //A.cpp + //#include "A.h" + // + //int main() { + // return 0; + //} + public void testTestMultipleDeclarations() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#include + // + //class A { + // void foo(); + // void /*$*/foo/*$$*/() { + // return; + // } + //}; + // + //void blah() { + //} + // + //inline void A::foo() { + // return; + //} + + //A.cpp + //#include "A.h" + // + //int main() { + // return 0; + //} + public void testTestMultipledefinitions() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //class A { + // void foo() { + // void /*$*/bar/*$$*/() { + // } + // } + //}; + public void testTestNotSupportedNestedFunctions() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //class A { + // void me/*$*//*$$*/mber() { + // return; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestZeroLengthSelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void m/*$*/e/*$$*/mber() { + // return; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestSubstringSelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void member() { + // r/*$*//*$$*/eturn; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestBodySelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void member() { + // int /*$*/abcd/*$$*/ = 42; + // return; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // int abcd = 42; + // return; + //} + public void testTestBodySelectionWithConfusingName() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // /*$*//*$$*/void member() { + // return; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestLeftBorderSelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void member() { + // return; + // }/*$*//*$$*/ + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestRightBorderSelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // vo/*$*/id member() { + // ret/*$$*/urn; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testTestOverlappingSelection() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //public: + // int /*$*/function/*$$*/() { + // return 0; + // } + // + //private: + // int a; + //}; + //==================== + //#include + // + //class A { + //public: + // int function(); + // + //private: + // int a; + //}; + // + //inline int A::function() { + // return 0; + //} + public void testTestSimpleFunctionInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //public: + // int function(); + // + //private: + // int a; + //}; + // + //inline int A::/*$*/function/*$$*/() { + // return 0; + //} + //==================== + //#include + // + //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; + //} + public void testTestSimpleFunctionInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //int A::/*$*/function/*$$*/() { + // return 0; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "A.h" + // + //int main() { + // return 0; + //} + + //A.h + //#include + // + //class A { + //public: + // int function(); + // + //private: + // int a; + //}; + //==================== + //#include + // + //class A { + //public: + // int function() { + // return 0; + // } + // + //private: + // int a; + //}; + public void testTestSimpleFunctionInImplementationToInClass() throws Exception { + assertRefactoringSuccess(); + } + + //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) { + // } + //}; + public void testTestDifferentParameterNames() throws Exception { + assertRefactoringSuccess(); + } + + //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) { + // } + //}; + public void testTestMissingParameterNames() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //template + //class A { + // class B { + // T /*$*/member/*$$*/() { + // return T(); + // } + // }; + //}; + //==================== + //#include + // + //template + //class A { + // class B { + // T member(); + // }; + //}; + // + //template + //inline T A::B::member() { + // return T(); + //} + public void testTestTemplateFunctionInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //template + //class A { + // class B { + // T member(); + // }; + //}; + // + //template + //inline T A::B::/*$*/member/*$$*/() { + // return T(); + //} + //==================== + //#include + // + //template + //class A { + // class B { + // T member() { + // return T(); + // } + // }; + //}; + public void testTestTemplateFunctionInHeaderToInClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // tem/*$*/plate/*$$*/ + // T foo() { + // return T(); + // } + //}; + //==================== + //class A { + // template + // T foo(); + //}; + // + //template + //inline T A::foo() { + // return T(); + //} + public void testTestTemplateFunctionInHeaderToInClassWithTemplateSelected() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + //public: + // template + // void /*$*/foo/*$$*/(const U& u, const V& v) { + // return; + // } + //}; + //==================== + //template + //class A { + //public: + // template + // void foo(const U& u, const V& v); + //}; + // + //template + //template + //inline void A::foo(const U& u, const V& v) { + // return; + //} + public void testTestComplexTemplateFunctionFromInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + //public: + // template + // void /*$*/foo/*$$*/(const U& u, const V& v); + //}; + // + //template + //template + //inline void A::foo(const U& u, const V& v) { + // return; + //} + //==================== + //template + //class A { + //public: + // template + // void foo(const U& u, const V& v) { + // return; + // } + //}; + public void testTestComplexTemplateFunctionFromInHeaderToInClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void /*$*/foo/*$$*/() { + // return; + // } + //}; + // + //} + //==================== + //#include + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //inline void A::foo() { + // return; + //} + // + //} + public void testTestSimpleNamespaceInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //inline void A::/*$*/foo/*$$*/() { + // return; + //} + // + //} + //==================== + //#include + //#include + // + //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; + //} + // + //} + public void testTestSimpleNamespaceInHeaderToImplementationWithinNamespaceDefinition() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //inline void A::/*$*/foo/*$$*/() { + // return; + //} + // + //} + //==================== + //#include + //#include + // + //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; + //} + // + //} + public void testTestSimpleNamespaceInHeaderToImplementationWithNamespaceDefinitionInImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //} + // + //inline void /*$*/N::A::foo/*$$*/() { + // return; + //} + //==================== + //#include + //#include + // + //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; + //} + // + //} + public void testTestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //void /*$*/N::A::foo/*$$*/() { + // return; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "A.h" + // + //int main() { + // return 0; + //} + + //A.h + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //} + //==================== + //#include + // + //namespace N { + // + //class A { + // void foo() { + // return; + // } + //}; + // + //} + public void testTestSimpleNamespaceFromImplementationToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //namespace N { + // + //void /*$*/A::foo/*$$*/() { + // return; + //} + // + //} + //==================== + //#include "A.h" + + //A.h + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //} + //==================== + //#include + // + //namespace N { + // + //class A { + // void foo() { + // return; + // } + //}; + // + //} + public void testTestRemoveEmptyNamespaceFromImplentation() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //class A { + // void /*$*/member/*$$*/(int a, int b) + // try { + // return; + // } + // catch (std::exception& e1){ + // return; + // } + //}; + //==================== + //#include + //#include + // + //class A { + // void member(int a, int b); + //}; + // + //inline void A::member(int a, int b) + //try { + // return; + //} + //catch (std::exception& e1) { + // return; + //} + public void testTestTryCatchFromInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //class A { + // void member(int a, int b); + //}; + // + //inline void /*$*/A::member/*$$*/(int a, int b) + //try { + // return; + //} + //catch (std::exception& e1) { + // return; + //} + //==================== + //#include + //#include + // + //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; + //} + public void testTestTryCatchFromInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include + //#include "A.h" + // + //void A::/*$*/member/*$$*/() + //try { + // return; + //} + //catch (std::exception& e1) { + // return; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include + //#include "A.h" + // + //int main() { + // return 0; + //} + + //A.h + //#include + // + //class A { + // void member(); + //}; + //==================== + //#include + // + //class A { + // void member() + // try { + // return; + // } + // catch (std::exception& e1) { + // return; + // } + //}; + public void testTestTryCatchFromInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //class A { + // void /*$*/member/*$$*/(int a, int b) + // try { + // return; + // } + // catch (std::exception& e1) { + // return; + // } + // catch (std::exception& e2) { + // return; + // } + //}; + //==================== + //#include + //#include + // + //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; + //} + public void testTestMultipleTryCatchFromInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //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 + //#include + // + //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; + //} + public void testTestMultipleTryCatchFromInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include + //#include "A.h" + // + //void A::/*$*/member/*$$*/() + //try { + // return; + //} + //catch (std::exception& e1) { + // return; + //} + //catch (std::exception& e2) { + // return; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include + //#include "A.h" + // + //int main() { + // return 0; + //} + + //A.h + //#include + // + //class A { + // void member(); + //}; + //==================== + //#include + // + //class A { + // void member() + // try { + // return; + // } + // catch (std::exception& e1) { + // return; + // } + // catch (std::exception& e2) { + // return; + // } + //}; + public void testTestMultipleTryCatchFromInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + // void /*$*/member/*$$*/(int a = 0, int b = 0) { + // return; + // } + //}; + //==================== + //#include + // + //class A { + // void member(int a = 0, int b = 0); + //}; + // + //inline void A::member(int a, int b) { + // return; + //} + public void testTestDefaultParameterInitializerInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + // void member(int a = 0, int b = 0); + //}; + // + //inline void /*$*/A::member/*$$*/(int a, int b) { + // return; + //} + //==================== + //#include + // + //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; + //} + public void testTestDefaultParameterInitializerInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //class A { + // void member(int a = 0, int b = 0); + //}; + //==================== + //#include + // + //class A { + // void member(int a = 0, int b = 0) { + // return; + // } + //}; + public void testTestDefaultParameterInitializerInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //private: + // int a; + // int b; + // + //public: + // /*$*/A/*$$*/(int x, int y) : + // a(x), b(y) { + // } + // ~A() { + // } + //}; + //==================== + //#include + // + //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) { + //} + public void testTestConstructorToggleInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //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 + // + //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) { + //} + public void testTestConstructorToggleInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //class A { + // A(int x, int y); + // ~A() { + // } + //}; + //==================== + //#include + // + //class A { + // A(int x, int y) : + // a(x), b(y) { + // } + // ~A() { + // } + //}; + public void testTestConstructorToggleInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //private: + // int a; + // int b; + // + //public: + // /*$*/~A/*$$*/() { + // } + //}; + //==================== + //#include + // + //class A { + //private: + // int a; + // int b; + // + //public: + // ~A(); + //}; + // + //inline A::~A() { + //} + public void testTestDestructorToggleInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //private: + // int a; + // int b; + // + //public: + // ~A(); + //}; + // + //inline /*$*/A::~A/*$$*/() { + //} + //==================== + //#include + // + //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() { + //} + public void testTestDestructorToggleInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //class A { + // A(int x, int y) : + // a(x), b(y) { + // } + // ~A(); + //}; + //==================== + //#include + // + //class A { + // A(int x, int y) : + // a(x), b(y) { + // } + // ~A() { + // int x; + // int y; + // return; + // } + //}; + public void testTestDestructorToggleInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + // class B { + // void /*$*/member/*$$*/(int a, int b) { + // return; + // } + // }; + //}; + //==================== + //#include + // + //class A { + // class B { + // void member(int a, int b); + // }; + //}; + // + //inline void A::B::member(int a, int b) { + // return; + //} + public void testTestNestedClassInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + // class B { + // void member(int a, int b); + // }; + //}; + // + //inline void A::B::/*$*/member/*$$*/(int a, int b) { + // return; + //} + //==================== + //#include + // + //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; + //} + public void testTestNestedClassInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //class A { + // class B { + // void member(int a, int b); + // }; + //}; + //==================== + //#include + // + //class A { + // class B { + // void member(int a, int b) { + // return; + // } + // }; + //}; + public void testTestNestedClassInImplementationToClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //int main() { + // return 0; + //} + // + //void N::A::/*$*/foo/*$$*/() { + // return; + //} + //==================== + //#include "A.h" + // + //int main() { + // return 0; + //} + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void foo(); + //}; + // + //} + //==================== + //#include + //#include + // + //namespace N { + // + //class A { + // void foo() { + // return; + // } + //}; + // + //} + public void testTestImplementationToClassWithDefintionSelected() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + //#include + // + //namespace N { + // + //class A { + // void /*$*/foo/*$$*/(); + //}; + // + //} + //==================== + //#include + //#include + // + //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; + //} + public void testTestImplementationToClassWithDeclarationSelected() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //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 + // + //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; + //} + public void testTestFreeFunctionToggleFromHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //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 + // + //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; + //} + public void testTestFreeFunctionToggleFromImplementationToHeaderWithDeclaration() throws Exception { + assertRefactoringSuccess(); + } + + //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 + // + //class A { + //private: + // int a; + // int b; + // + //public: + // A(int x, int y) : + // a(x), b(y) { + // } + // ~A() { + // } + //}; + //==================== + //#include + // + //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) { + //} + public void testTestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //int /*$*/freeFunction/*$$*/() { + // return 42; + //} + //==================== + //int freeFunction(); + + //A.cpp + //#include "A.h" + //==================== + //#include "A.h" + // + //int freeFunction() { + // return 42; + //} + public void testTestFreeFunction() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //int /*$*/A::freefunction/*$$*/() { + // return 42; + //} + //==================== + //#include "A.h" + // + //int A::freefunction() { + // return 42; + //} + public void testTestQualifiedNameToggle() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include + // + //namespace N { + // + //void /*$*/freefunction/*$$*/() { + // return; + //} + // + //} + // + //#endif /* A_H_ */ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include + // + //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; + //} + // + //} + public void testTestNamespacedFreeFunction() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + // + //class A { + // virtual int /*$*/foo/*$$*/() { + // return 0; + // } + //}; + //==================== + // + //class A { + // virtual int foo(); + //}; + // + //inline int A::foo() { + // return 0; + //} + public void testTestRemoveVirtualSpecifierFromClassToInheader() throws Exception { + assertRefactoringSuccess(); + } + + //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; + //} + public void testTestVirtualSpecifierFromInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //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; + //} + public void testTestVirtualSpecifierFromImplementationToHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //public: + // void func1(); + // void /*$*/func2/*$$*/() { + // } + // void func3(); + // void func4() { + // } + //}; + // + //inline void A::func1() { + //} + // + //inline void A::func3() { + //} + //==================== + //#include + // + //class A { + //public: + // void func1(); + // void func2(); + // void func3(); + // void func4() { + // } + //}; + // + //inline void A::func1() { + //} + // + //inline void A::func2() { + //} + // + //inline void A::func3() { + //} + public void testTestCorrectOrderingInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //class A { + //public: + // void func1(); + // void func2(); + // void func3(); + // void func4() { + // } + //}; + // + //inline void A::/*$*/func2/*$$*/() { + // return; + //} + //==================== + //#include + // + //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; + //} + public void testTestCorrectOrderingInHeaderToImplementation() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //template + //class A { + //public: + // void func1(); + // void /*$*/func2/*$$*/() { + // } + // void func3(); + // void func4() { + // } + //}; + // + //template + //inline void A::func1() { + //} + // + //template + //inline void A::func3() { + //} + //==================== + //#include + // + //template + //class A { + //public: + // void func1(); + // void func2(); + // void func3(); + // void func4() { + // } + //}; + // + //template + //inline void A::func1() { + //} + // + //template + //inline void A::func2() { + //} + // + //template + //inline void A::func3() { + //} + public void testTestCorrectTemplateOrderingInClassToInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#include + // + //template + //class A { + //public: + // void func1(); + // void func2(); + // void func3(); + // void func4() { + // } + //}; + // + //template + //inline void A::func1() { + //} + // + //template + //inline void A::/*$*/func2/*$$*/() { + //} + // + //template + //inline void A::func3() { + //} + //==================== + //#include + // + //template + //class A { + //public: + // void func1(); + // void func2() { + // } + // void func3(); + // void func4() { + // } + //}; + // + //template + //inline void A::func1() { + //} + // + //template + //inline void A::func3() { + //} + public void testTestCorrectTemplateOrderingInHeaderToInClass() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void /*$*/member/*$$*/() { + // // return comment + // return; + // } + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // // return comment + // return; + //} + public void testClassToHeaderBodyComment() throws Exception { + assertRefactoringSuccess(); + } + + //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; + //} + public void testClassToHeaderTopCommentOrder() throws Exception { + assertRefactoringSuccess(); + } + + //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 + //} + public void testClassToHeaderCatchComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // // Top comment + // void /*$*/member/*$$*/() { + // return; + // } + //}; + //==================== + //class A { + // // Top comment + // void member(); + //}; + // + //inline void A::member() { + // return; + //} + public void testClassToHeaderTopComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // // Top comment + // template + // T /*$*/member/*$$*/() { + // return T(); + // } + //}; + //==================== + //class A { + // // Top comment + // template + // T member(); + //}; + // + //// Top comment + //template + //inline T A::member() { + // return T(); + //} + public void testClassToHeaderTemplateTopComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //class A { + // void /*$*/member/*$$*/() { + // return; + // } // Trailing comment + //}; + //==================== + //class A { + // void member(); + //}; + // + //inline void A::member() { + // return; + //} // Trailing comment + public void testClassToHeaderTrailingComment() throws Exception { + assertRefactoringSuccess(); + } + + //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 + public void testClassToHeaderTrailingCommentWithTryBlock() throws Exception { + assertRefactoringSuccess(); + } + + //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 */ + public void testClassToHeaderTrailingMultipleCommentsInTryBlock() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + // T /*$*/member/*$$*/(); + //}; + // + //template + //inline T A::member() { + // // body comment + // return T(); + //} + //==================== + //template + //class A { + // T member() { + // // body comment + // return T(); + // } + //}; + public void testHeaderToClassBodyComment1() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + // // First comment + // // Second comment + // T /*$*/member/*$$*/(); + //}; + // + //// Third comment + //// Fourth comment + //template + //inline T A::member() { + // return T(); + //} + //==================== + //template + //class A { + // // First comment + // // Second comment + // // Third comment + // // Fourth comment + // T member() { + // return T(); + // } + //}; + public void testHeaderToClassRetainTopComments() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + // T /*$*/member/*$$*/(); + //}; + // + //template + //inline T A::member() + //try { + // // body comment + // return T(); + //} + //catch (int e) { + // // Catch 1 + //} + //catch (int e) { + // // Catch 2 + //} + //==================== + //template + //class A { + // T member() + // try { + // // body comment + // return T(); + // } + // catch (int e) { + // // Catch 1 + // } + // catch (int e) { + // // Catch 2 + // } + //}; + public void testHeaderToClassTryCatchComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + // // Top Comment + // template + // T /*$*/member/*$$*/(); + //}; + // + //// 2nd Top Comment + //template + //template + //inline T A::member() { + // // body comment + // return T(); + //} + //==================== + //template + //class A { + // // Top Comment + // template + // T member() { + // // body comment + // return T(); + // } + //}; + public void testHeaderToClassMultiTemplateComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //template + //class A { + // T /*$*/member/*$$*/(); + //}; + // + //// Top comment + //template + //inline T A::member() { + // return T(); + //} + //==================== + //template + //class A { + // // Top comment + // T member() { + // return T(); + // } + //}; + public void testHeaderToClassBodyComment() throws Exception { + assertRefactoringSuccess(); + } + + //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; + //} + public void testHeaderToImplBodyComment() throws Exception { + assertRefactoringSuccess(); + } + + //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*/ + //} + public void testHeaderToImplTryCatchComment() throws Exception { + assertRefactoringSuccess(); + } + + //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; + //} + public void testHeaderToImplTopComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //// Definition comment + //void /*$*/member/*$$*/() { + // return; + //} + //==================== + //// Definition comment + //void member(); + + //A.cpp + //#include "A.h" + //==================== + //#include "A.h" + // + //// Definition comment + //void member() { + // return; + //} + public void testHeaderToImplFreeFuncTopComment() throws Exception { + assertRefactoringSuccess(); + } + + //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; + // } + //}; + public void testImplToHeaderBodyComment() throws Exception { + assertRefactoringSuccess(); + } + + //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; + // } + //}; + public void testImplToHeaderTopComment() throws Exception { + assertRefactoringSuccess(); + } + + //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*/ + // } + //}; + public void testImplToHeaderTryCatchComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //void /*$*/member/*$$*/() { + // // body comment + // return; + //} + //==================== + //#include "A.h" + + //A.h + // + //==================== + //void member() { + // // body comment + // return; + //} + public void testImplToHeaderBodyCommentWithoutDeclaration() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //#include "A.h" + // + //// Top comment + //void /*$*/member/*$$*/() { + // // body comment + // return; + //} + //==================== + //#include "A.h" + + //A.h + // + //==================== + //// Top comment + //void member() { + // // body comment + // return; + //} + public void testImplToHeaderTopCommentWithoutDeclaration() throws Exception { + assertRefactoringSuccess(); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java index 0dfd365b5f3..854ad0d76c6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Marc-Andre Laperle and others. + * Copyright (c) 2011, 2012 Marc-Andre Laperle and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Marc-Andre Laperle - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.utils; @@ -14,16 +15,24 @@ import java.util.Collection; import java.util.Properties; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; +import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder; public class DefinitionFinderTest extends RefactoringTest { @@ -39,14 +48,36 @@ public class DefinitionFinderTest extends RefactoringTest { @Override protected void runTest() throws Throwable { IFile file = project.getFile(fileName); - ICElement element = CCorePlugin.getDefault().getCoreModel().create(file); - if (element instanceof ITranslationUnit) { - IASTTranslationUnit ast = astCache.getAST((ITranslationUnit) element, null); + ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file); + CRefactoring2 refactoring = new CRefactoring2(tu, null, tu.getCProject()) { + @Override + protected RefactoringStatus checkFinalConditions(IProgressMonitor progressMonitor, + CheckConditionsContext checkContext) throws CoreException, OperationCanceledException { + return null; + } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + return null; + } + + @Override + protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) + throws CoreException, OperationCanceledException { + } + }; + + CRefactoringContext refactoringContext = new CRefactoringContext(refactoring); + try { + IASTTranslationUnit ast = refactoringContext.getAST(tu, null); for (IASTDeclaration declaration : ast.getDeclarations()) { if (declaration instanceof IASTSimpleDeclaration) { - assertNotNull(DefinitionFinder.getDefinition((IASTSimpleDeclaration) declaration, astCache, NULL_PROGRESS_MONITOR)); + assertNotNull(DefinitionFinder.getDefinition((IASTSimpleDeclaration) declaration, + refactoringContext, NULL_PROGRESS_MONITOR)); } } + } finally { + refactoringContext.dispose(); } } } diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index 993b6f1a79d..0d66449820e 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -112,7 +112,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)", org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)", - org.eclipse.ltk.core.refactoring;bundle-version="3.4.0", + org.eclipse.ltk.core.refactoring;bundle-version="3.6.0", org.eclipse.ltk.ui.refactoring;bundle-version="3.4.0", org.eclipse.ui.navigator.resources;bundle-version="3.3.100" Bundle-ActivationPolicy: lazy diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java index 1bac52aad40..4c7487720f8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java @@ -52,7 +52,7 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** * A collection of static methods for finding the source file corresponding to a header @@ -330,7 +330,7 @@ public final class SourceHeaderPartnerFinder { } public static ITranslationUnit getPartnerTranslationUnit(ITranslationUnit tu, - RefactoringASTCache astCache) throws CoreException { + CRefactoringContext astCache) throws CoreException { ITranslationUnit partnerUnit= getPartnerFileFromFilename(tu); if (partnerUnit == null) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring2.java index 8ca463f7655..27266c4293a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring2.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.ui.refactoring; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -47,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -68,14 +70,12 @@ public abstract class CRefactoring2 extends Refactoring { protected String name = Messages.Refactoring_name; protected final ICProject project; protected final ITranslationUnit tu; - protected final RefactoringStatus initStatus; - protected final RefactoringASTCache astCache; protected Region selectedRegion; + protected final RefactoringStatus initStatus; + protected CRefactoringContext refactoringContext; - public CRefactoring2(ICElement element, ISelection selection, ICProject project, - RefactoringASTCache astCache) { + public CRefactoring2(ICElement element, ISelection selection, ICProject project) { this.project = project; - this.astCache = astCache; this.initStatus= new RefactoringStatus(); if (!(element instanceof ISourceReference)) { this.tu = null; @@ -98,70 +98,10 @@ public abstract class CRefactoring2 extends Refactoring { } } - private class ProblemFinder extends ASTVisitor { - private boolean problemFound = false; - private final RefactoringStatus status; - - public ProblemFinder(RefactoringStatus status) { - this.status = status; - } - { - shouldVisitProblems = true; - shouldVisitDeclarations = true; - shouldVisitExpressions = true; - shouldVisitStatements = true; - shouldVisitTypeIds = true; - } - - @Override - public int visit(IASTProblem problem) { - addWarningToState(); - return ASTVisitor.PROCESS_CONTINUE; - } - - @Override - public int visit(IASTDeclaration declaration) { - if (declaration instanceof IASTProblemDeclaration) { - addWarningToState(); - } - return ASTVisitor.PROCESS_CONTINUE; - } - - @Override - public int visit(IASTExpression expression) { - if (expression instanceof IASTProblemExpression) { - addWarningToState(); - } - return ASTVisitor.PROCESS_CONTINUE; - } - - @Override - public int visit(IASTStatement statement) { - if (statement instanceof IASTProblemStatement) { - addWarningToState(); - } - return ASTVisitor.PROCESS_CONTINUE; - } - - @Override - public int visit(IASTTypeId typeId) { - if (typeId instanceof IASTProblemTypeId) { - addWarningToState(); - } - return ASTVisitor.PROCESS_CONTINUE; - } - - public boolean hasProblem() { - return problemFound; - } - - private void addWarningToState() { - if (!problemFound) { - status.addWarning(Messages.Refactoring_CompileErrorInTU); - problemFound = true; - } - } + public void setContext(CRefactoringContext refactoringContext) { + Assert.isNotNull(refactoringContext); + this.refactoringContext = refactoringContext; } @Override @@ -248,7 +188,11 @@ public abstract class CRefactoring2 extends Refactoring { protected IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, OperationCanceledException { - return astCache.getAST(tu, pm); + return refactoringContext.getAST(tu, pm); + } + + protected IIndex getIndex() throws OperationCanceledException, CoreException { + return refactoringContext.getIndex(); } protected boolean checkAST(IASTTranslationUnit ast) { @@ -284,4 +228,70 @@ public abstract class CRefactoring2 extends Refactoring { result.add(new ResourceChangeChecker()); return result; } + + private class ProblemFinder extends ASTVisitor { + private boolean problemFound = false; + private final RefactoringStatus status; + + public ProblemFinder(RefactoringStatus status) { + this.status = status; + } + + { + shouldVisitProblems = true; + shouldVisitDeclarations = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; + } + + @Override + public int visit(IASTProblem problem) { + addWarningToState(); + return ASTVisitor.PROCESS_CONTINUE; + } + + @Override + public int visit(IASTDeclaration declaration) { + if (declaration instanceof IASTProblemDeclaration) { + addWarningToState(); + } + return ASTVisitor.PROCESS_CONTINUE; + } + + @Override + public int visit(IASTExpression expression) { + if (expression instanceof IASTProblemExpression) { + addWarningToState(); + } + return ASTVisitor.PROCESS_CONTINUE; + } + + @Override + public int visit(IASTStatement statement) { + if (statement instanceof IASTProblemStatement) { + addWarningToState(); + } + return ASTVisitor.PROCESS_CONTINUE; + } + + @Override + public int visit(IASTTypeId typeId) { + if (typeId instanceof IASTProblemTypeId) { + addWarningToState(); + } + return ASTVisitor.PROCESS_CONTINUE; + } + + public boolean hasProblem() { + return problemFound; + } + + private void addWarningToState() { + if (!problemFound) { + status.addWarning(Messages.Refactoring_CompileErrorInTU); + problemFound = true; + } + } + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringASTCache.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContext.java similarity index 80% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringASTCache.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContext.java index 8ae223e3f23..2bb1a923fbb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringASTCache.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Google, Inc and others. + * Copyright (c) 2010, 2012 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,10 @@ package org.eclipse.cdt.internal.ui.refactoring; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.ui.services.IDisposable; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -32,13 +31,13 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.cdt.internal.ui.editor.ASTProvider; /** - * Cache containing ASTs for the translation units participating in refactoring. - * The cache object has to be disposed of after use. Failure to do so may cause - * loss of index lock. + * A disposable context for C/C++ refactoring operations. Contains cache of ASTs of the translation + * units participating in refactoring. The context object has to be disposed of after use. Failure + * to do so may cause loss of index lock. *

* This class is not thread-safe. */ -public class RefactoringASTCache implements IDisposable { +public class CRefactoringContext extends RefactoringContext { private static final int PARSE_MODE = ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS @@ -47,9 +46,10 @@ public class RefactoringASTCache implements IDisposable { private final Map fASTCache; private IIndex fIndex; private IASTTranslationUnit fSharedAST; - private boolean fDisposed; - public RefactoringASTCache() { + public CRefactoringContext(CRefactoring2 refactoring) { + super(refactoring); + refactoring.setContext(this); fASTCache = new ConcurrentHashMap(); } @@ -69,7 +69,8 @@ public class RefactoringASTCache implements IDisposable { */ public IASTTranslationUnit getAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, OperationCanceledException { - Assert.isTrue(!fDisposed, "RefactoringASTCache is already disposed"); //$NON-NLS-1$ + if (isDisposed()) + throw new IllegalStateException("CRefactoringContext is already disposed."); //$NON-NLS-1$ getIndex(); // Make sure the index is locked. if (pm != null && pm.isCanceled()) throw new OperationCanceledException(); @@ -108,7 +109,8 @@ public class RefactoringASTCache implements IDisposable { * @return The index. */ public IIndex getIndex() throws CoreException, OperationCanceledException { - Assert.isTrue(!fDisposed, "RefactoringASTCache is already disposed"); //$NON-NLS-1$ + if (isDisposed()) + throw new IllegalStateException("CRefactoringContext is already disposed."); //$NON-NLS-1$ if (fIndex == null) { ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); IIndex index = CCorePlugin.getIndexManager().getIndex(projects); @@ -122,25 +124,27 @@ public class RefactoringASTCache implements IDisposable { return fIndex; } - /** - * @see IDisposable#dispose() - */ @Override public void dispose() { - Assert.isTrue(!fDisposed, "RefactoringASTCache.dispose() called more than once"); //$NON-NLS-1$ - fDisposed = true; + if (isDisposed()) + throw new IllegalStateException("CRefactoringContext.dispose() called more than once."); //$NON-NLS-1$ if (fSharedAST != null) { ASTProvider.getASTProvider().releaseSharedAST(fSharedAST); } if (fIndex != null) { fIndex.releaseReadLock(); } + super.dispose(); + } + + private boolean isDisposed() { + return getRefactoring() == null; } @Override protected void finalize() throws Throwable { - if (!fDisposed) - CUIPlugin.logError("RefactoringASTCache was not disposed"); //$NON-NLS-1$ + if (!isDisposed()) + CUIPlugin.logError("CRefactoringContext was not disposed"); //$NON-NLS-1$ super.finalize(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContribution.java index eca83abe692..f72aeda196e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContribution.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContribution.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2009, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software (IFS)- initial API and implementation + * Institute for Software (IFS)- initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring; @@ -28,7 +29,10 @@ public abstract class CRefactoringContribution extends RefactoringContribution { @SuppressWarnings("rawtypes") @Override public Map retrieveArgumentMap(RefactoringDescriptor descriptor) { - if (descriptor instanceof CRefactoringDescription) { + if (descriptor instanceof CRefactoringDescriptor) { + CRefactoringDescriptor refDesc = (CRefactoringDescriptor) descriptor; + return refDesc.getParameterMap(); + } if (descriptor instanceof CRefactoringDescription) { CRefactoringDescription refDesc = (CRefactoringDescription) descriptor; return refDesc.getParameterMap(); } else { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescription.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescription.java index ab6355e68e5..86999000b95 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescription.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescription.java @@ -29,16 +29,20 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.core.resources.ResourceLookup; + /** * @author Emanuel Graf IFS + * @deprecated Use {@link CRefactoringDescriptor} instead. */ +@Deprecated public abstract class CRefactoringDescription extends RefactoringDescriptor { public static final String FILE_NAME = "fileName"; //$NON-NLS-1$ public static final String SELECTION = "selection"; //$NON-NLS-1$ protected Map arguments; - public CRefactoringDescription(String id, String project, String description, String comment, int flags, - Map arguments) { + public CRefactoringDescription(String id, String project, String description, String comment, + int flags, Map arguments) { super(id, project, description, comment, flags); this.arguments = arguments; } @@ -48,35 +52,31 @@ public abstract class CRefactoringDescription extends RefactoringDescriptor { } protected ISelection getSelection() throws CoreException { - ISelection selection; String selectStrings[] = arguments.get(SELECTION).split(","); //$NON-NLS-1$ - if (selectStrings.length >= 2) { - int offset = Integer.parseInt(selectStrings[0]); - int length = Integer.parseInt(selectStrings[1]); - selection = new TextSelection(offset, length); - } else { - throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$ + if (selectStrings.length < 2) { + throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal selection")); //$NON-NLS-1$ } - return selection; + int offset = Integer.parseInt(selectStrings[0]); + int length = Integer.parseInt(selectStrings[1]); + return new TextSelection(offset, length); } protected ICProject getCProject() throws CoreException { - ICProject proj; - IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()); - proj = CoreModel.getDefault().create(iProject); - if (proj == null) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()); + ICProject cProject = CoreModel.getDefault().create(project); + if (cProject == null) { throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Unknown Project")); //$NON-NLS-1$ } - return proj; + return cProject; } protected IFile getFile() throws CoreException { - IFile file; try { - file = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI(arguments.get(FILE_NAME)))[0]; + String filename = arguments.get(FILE_NAME); + return ResourceLookup.selectFileForLocationURI(new URI(filename), + ResourcesPlugin.getWorkspace().getRoot().getProject(getProject())); } catch (URISyntaxException e) { throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, e.getMessage(), e)); } - return file; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescriptor.java new file mode 100644 index 00000000000..9d3824050f9 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescriptor.java @@ -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 arguments; + + public CRefactoringDescriptor(String id, String project, String description, String comment, + int flags, Map arguments) { + super(id, project, description, comment, flags); + this.arguments = arguments; + } + + public Map 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)); + } + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java index 22176b2c2fc..c6b11ecb7d2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java @@ -31,6 +31,8 @@ public final class Messages extends NLS { public static String CreateFileChange_FileExists; public static String CRefactoring_FileNotFound; public static String CRefactoring_checking_final_conditions; + public static String CRefactoringDescriptor_unknown_project; + public static String CRefactoringDescriptor_illegal_selection; public static String Refactoring_SelectionNotValid; public static String Refactoring_CantLoadTU; public static String Refactoring_Ambiguity; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties index c42894c574b..dd9fc9256bc 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties @@ -26,6 +26,8 @@ CreateFileChange_UnknownLoc=Unknown location: {0} CreateFileChange_FileExists=File already exists: {0} CRefactoring_FileNotFound=The file {0} is not on the build path of a C/C++ project. CRefactoring_checking_final_conditions=Checking preconditions... +CRefactoringDescriptor_unknown_project=Project ''{0}'' does not exist of is not a C/C++ project. +CRefactoringDescriptor_illegal_selection=Illegal selection. Refactoring_SelectionNotValid=Selection is not valid. Refactoring_CantLoadTU=Can not load translation unit. Refactoring_Ambiguity=Translation unit is ambiguous. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java index 95674e6c1fe..af1d227b4c3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring; @@ -17,10 +17,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; /** * Associate a name with a visibility and holds a list of used names. - * */ public class NameNVisibilityInformation { - private String name = ""; //$NON-NLS-1$ private VisibilityEnum visibility = VisibilityEnum.v_public; private final ArrayList usedNames = new ArrayList(); @@ -52,5 +50,4 @@ public class NameNVisibilityInformation { public void addNamesToUsedNames(ArrayList names) { usedNames.addAll(names); } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner2.java index 678114f384b..17e023f70fb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc and others. + * Copyright (c) 2011, 2012 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; +import org.eclipse.ltk.ui.refactoring.RefactoringWizard; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -23,27 +24,26 @@ import org.eclipse.cdt.core.model.ICProject; public abstract class RefactoringRunner2 { protected final ISelection selection; protected final ICElement element; - protected final IShellProvider shellProvider; protected final ICProject project; - protected final RefactoringStarter starter; + private final IShellProvider shellProvider; public RefactoringRunner2(ICElement element, ISelection selection, IShellProvider shellProvider, ICProject cProject) { this.selection = selection; this.element= element; - this.shellProvider= shellProvider; this.project = cProject; - this.starter = new RefactoringStarter(); + this.shellProvider= shellProvider; } - public final void run() { - RefactoringASTCache astCache = new RefactoringASTCache(); + public abstract void run(); + + protected final void run(RefactoringWizard wizard, CRefactoring2 refactoring, int saveMode) { + CRefactoringContext context = new CRefactoringContext(refactoring); try { - run(astCache); + RefactoringStarter starter = new RefactoringStarter(); + starter.activate(wizard, shellProvider.getShell(), refactoring.getName(), saveMode); } finally { - astCache.dispose(); + context.dispose(); } } - - protected abstract void run(RefactoringASTCache astCache); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringStarter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringStarter.java index e719c4d27aa..cdcb0c57429 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringStarter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringStarter.java @@ -11,16 +11,14 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring; -import org.eclipse.swt.widgets.Shell; - import org.eclipse.jface.dialogs.IDialogConstants; - import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.ui.refactoring.RefactoringWizard; import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; +import org.eclipse.swt.widgets.Shell; /** - * A helper class to activate the UI of a refactoring + * A helper class to activate the UI of a refactoring. */ public class RefactoringStarter { private RefactoringStatus fStatus; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java index 87f2d8f3737..fd5a43cb622 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java @@ -1,14 +1,13 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Google and others. All rights reserved. This program and + * Copyright (c) 2008, 2012 Google and others. All rights reserved. This program and * the accompanying materials are made available under the terms of the Eclipse * Public License v1.0 which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Google - initial API and implementation + * Tom Ball (Google) - Initial API and implementation * Sergey Prigogin (Google) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; import java.util.ArrayList; @@ -16,7 +15,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -27,6 +25,7 @@ import org.eclipse.jface.text.Region; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; import org.eclipse.text.edits.TextEditGroup; import org.eclipse.cdt.core.dom.ast.ASTVisitor; @@ -47,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.INodeFactory; @@ -55,6 +55,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; @@ -66,7 +67,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; @@ -82,7 +83,7 @@ import org.eclipse.cdt.internal.ui.util.NameComposer; * * @author Tom Ball */ -public class ExtractLocalVariableRefactoring extends CRefactoring { +public class ExtractLocalVariableRefactoring extends CRefactoring2 { public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$ @@ -90,10 +91,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { private final NameNVisibilityInformation info; private NodeContainer container; - public ExtractLocalVariableRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info, - ICProject project) { - super(file, selection, null, project); - this.info = info; + public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) { + super(element, selection, project); + info = new NameNVisibilityInformation(); name = Messages.ExtractLocalVariable; } @@ -101,54 +101,47 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { SubMonitor sm = SubMonitor.convert(pm, 9); - try { - lockIndex(); - try { - RefactoringStatus status = super.checkInitialConditions(sm.newChild(6)); - if (status.hasError()) { - return status; - } - container = findAllExpressions(); - if (container.size() < 1) { - initStatus.addFatalError(Messages.ExpressionMustBeSelected); - return initStatus; - } - - sm.worked(1); - if (isProgressMonitorCanceld(sm, initStatus)) - return initStatus; - - boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region); - if (!oneMarked) { - if (target == null) { - initStatus.addFatalError(Messages.NoExpressionSelected); - } else { - initStatus.addFatalError(Messages.TooManyExpressionsSelected); - } - return initStatus; - } - sm.worked(1); - - if (isProgressMonitorCanceld(sm, initStatus)) - return initStatus; - - sm.worked(1); - - info.addNamesToUsedNames(findAllDeclaredNames()); - sm.worked(1); - - NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); - sm.worked(1); - - info.setName(guessTempName()); - sm.done(); - } finally { - unlockIndex(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + RefactoringStatus status = super.checkInitialConditions(sm.newChild(6)); + if (status.hasError()) { + return status; } + + container = findAllExpressions(pm); + if (container.isEmpty()) { + initStatus.addFatalError(Messages.ExpressionMustBeSelected); + return initStatus; + } + + sm.worked(1); + if (isProgressMonitorCanceld(sm, initStatus)) + return initStatus; + + boolean oneMarked = selectedRegion != null && isOneMarked(container.getNodesToWrite(), selectedRegion); + if (!oneMarked) { + initStatus.addFatalError(target == null ? + Messages.NoExpressionSelected : Messages.TooManyExpressionsSelected); + return initStatus; + } + sm.worked(1); + + if (isProgressMonitorCanceld(sm, initStatus)) + return initStatus; + + sm.worked(1); + + container.getNames(); //XXX Is this needed? + sm.worked(1); + + info.addNamesToUsedNames(findAllDeclaredNames()); + sm.worked(1); + + NodeHelper.findMethodContext(container.getNodesToWrite().get(0), refactoringContext, sm); + sm.worked(1); + + info.setName(guessTempName()); + sm.done(); + return initStatus; } @@ -157,9 +150,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target); ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef); if (comTypeSpec != null) { - for (IASTDeclaration dec : comTypeSpec.getMembers()) { - if (dec instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) dec; + for (IASTDeclaration decl : comTypeSpec.getMembers()) { + if (decl instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) decl; for (IASTDeclarator decor : simpDec.getDeclarators()) { names.add(decor.getName().getRawSignature()); } @@ -169,6 +162,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { return names; } + @Override + protected RefactoringStatus checkFinalConditions(IProgressMonitor subProgressMonitor, + CheckConditionsContext checkContext) throws CoreException, OperationCanceledException { + return new RefactoringStatus(); + } + private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) { if (funcDef != null) { IBinding binding = funcDef.getDeclarator().getName().resolveBinding(); @@ -191,9 +190,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { for (IASTNode node : selectedNodes) { if (node instanceof IASTExpression) { IASTExpression expression = (IASTExpression) node; - boolean isInSameFileSelection = - SelectionHelper.isInSameFileSelection(textSelection, expression, file); - if (isInSameFileSelection && isExpressionInSelection(expression, textSelection)) { + if (expression.isPartOfTranslationUnitFile() && + isExpressionInSelection(expression, textSelection)) { if (target == null) { target = expression; oneMarked = true; @@ -208,11 +206,11 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { private boolean isExpressionInSelection(IASTExpression expression, Region selection) { IASTFileLocation location = expression.getFileLocation(); - int e1 = location.getNodeOffset(); - int e2 = location.getNodeOffset() + location.getNodeLength(); - int s1 = selection.getOffset(); - int s2 = selection.getOffset() + selection.getLength(); - return e1 >= s1 && e2 <= s2; + int expressionStart = location.getNodeOffset(); + int expressionEnd = expressionStart + location.getNodeLength(); + int selectionStart = selection.getOffset(); + int selectionEnd = selectionStart + selection.getLength(); + return expressionStart >= selectionStart && expressionEnd <= selectionEnd; } private boolean isTargetChild(IASTExpression child) { @@ -228,23 +226,28 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { return false; } - private NodeContainer findAllExpressions() { + private NodeContainer findAllExpressions(IProgressMonitor pm) + throws OperationCanceledException, CoreException { final NodeContainer container = new NodeContainer(); - ast.accept(new ASTVisitor() { - { - shouldVisitExpressions = true; - } - - @Override - public int visit(IASTExpression expression) { - if (SelectionHelper.isSelectedFile(region, expression, file)) { - container.add(expression); - return PROCESS_SKIP; + IASTTranslationUnit ast = getAST(tu, pm); + if (ast != null) { + ast.accept(new ASTVisitor() { + { + shouldVisitExpressions = true; } - return super.visit(expression); - } - }); + + @Override + public int visit(IASTExpression expression) { + if (expression.isPartOfTranslationUnitFile() && + SelectionHelper.isExpressionWhollyInSelection(selectedRegion, expression)) { + container.add(expression); + return PROCESS_SKIP; + } + return super.visit(expression); + } + }); + } return container; } @@ -252,29 +255,21 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { @Override protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException { - try { - lockIndex(); - try { - String variableName = info.getName(); - TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable); + String variableName = info.getName(); + TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable); - // Define temporary variable declaration and insert it - IASTStatement declInsertPoint = getParentStatement(target); - IASTDeclarationStatement declaration = getVariableNodes(variableName); - declaration.setParent(declInsertPoint.getParent()); - ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast); - rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup); + // Define temporary variable declaration and insert it + IASTStatement declInsertPoint = getParentStatement(target); + IASTTranslationUnit ast = getAST(tu, pm); + IASTDeclarationStatement declaration = getVariableNodes(ast, variableName); + declaration.setParent(declInsertPoint.getParent()); + ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast); + rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup); - // Replace target with reference to temporary variable - CPPASTIdExpression idExpression = - new CPPASTIdExpression(new CPPASTName(variableName.toCharArray())); - rewriter.replace(target, idExpression, editGroup); - } finally { - unlockIndex(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + // Replace target with reference to temporary variable + CPPASTIdExpression idExpression = + new CPPASTIdExpression(new CPPASTName(variableName.toCharArray())); + rewriter.replace(target, idExpression, editGroup); } private IASTStatement getParentStatement(IASTNode node) { @@ -286,8 +281,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { return null; } - private IASTDeclarationStatement getVariableNodes(String newName) { - INodeFactory factory = this.ast.getASTNodeFactory(); + private IASTDeclarationStatement getVariableNodes(IASTTranslationUnit ast, String newName) { + INodeFactory factory = ast.getASTNodeFactory(); IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null); @@ -438,7 +433,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { } } } - }); } if (guessedTempNames.isEmpty()) { @@ -491,7 +485,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { IBinding[] bindings = scope.find(name); return bindings == null || bindings.length == 0; } - return true; // no name references found + return true; // No name references found } private String makeTempName(List usedNames, IScope scope) { @@ -510,16 +504,20 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { @Override protected RefactoringDescriptor getRefactoringDescriptor() { Map arguments = getArgumentMap(); - RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescription(project.getProject().getName(), + RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescriptor(project.getProject().getName(), "Extract Local Variable Refactoring", "Extract " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$ return desc; } private Map getArgumentMap() { Map arguments = new HashMap(); - arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString()); - arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$ - arguments.put(ExtractLocalVariableRefactoringDescription.NAME, info.getName()); + arguments.put(CRefactoringDescription.FILE_NAME, tu.getLocationURI().toString()); + arguments.put(CRefactoringDescription.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$ + arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName()); return arguments; } + + public NameNVisibilityInformation getRefactoringInfo() { + return info; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringContribution.java index 4e5c892d650..230da75a6c4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringContribution.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringContribution.java @@ -27,7 +27,7 @@ public class ExtractLocalVariableRefactoringContribution extends CRefactoringCon public RefactoringDescriptor createDescriptor(String id, String project, String description, String comment, Map arguments, int flags) throws IllegalArgumentException { if (id.equals(ExtractLocalVariableRefactoring.ID)) { - return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments); + return new ExtractLocalVariableRefactoringDescriptor(project, description, comment, arguments); } else { return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescription.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescriptor.java similarity index 57% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescription.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescriptor.java index 82dac797e62..46a7ce73886 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescription.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescriptor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2009, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,51 +7,42 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software (IFS)- initial API and implementation + * Institute for Software (IFS)- initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; import java.util.Map; -import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor; /** * @author Emanuel Graf IFS - * */ -public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription { - +public class ExtractLocalVariableRefactoringDescriptor extends CRefactoringDescriptor { static protected final String NAME = "name"; //$NON-NLS-1$ - public ExtractLocalVariableRefactoringDescription(String project, String description, + public ExtractLocalVariableRefactoringDescriptor(String project, String description, String comment, Map arguments) { super(ExtractLocalVariableRefactoring.ID, project, description, comment, RefactoringDescriptor.MULTI_CHANGE, arguments); } @Override - public Refactoring createRefactoring(RefactoringStatus status) throws CoreException { - IFile file; - NameNVisibilityInformation info = new NameNVisibilityInformation(); - ICProject proj; - - info.setName(arguments.get(NAME)); - - proj = getCProject(); - - file = getFile(); - + public CRefactoring2 createRefactoring(RefactoringStatus status) throws CoreException { ISelection selection = getSelection(); - return new ExtractLocalVariableRefactoring(file, selection, info, proj); + ICProject proj = getCProject(); + ExtractLocalVariableRefactoring refactoring = + new ExtractLocalVariableRefactoring(getTranslationUnit(), selection, proj); + refactoring.getRefactoringInfo().setName(arguments.get(NAME)); + return refactoring; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringRunner.java index 238bd6601f3..78880a1dc67 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,45 +7,38 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Tom Ball (Google) - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; -import org.eclipse.core.resources.IFile; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; +import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2; +import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper; /** * Extract Local Variable refactoring runner. * * @author Tom Ball */ -public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner { +public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner2 { - public ExtractLocalVariableRefactoringRunner(IFile file, ISelection selection, + public ExtractLocalVariableRefactoringRunner(ICElement element, ISelection selection, IShellProvider shellProvider, ICProject cProject) { - super(file, selection, null, shellProvider, cProject); + super(element, selection, shellProvider, cProject); } @Override public void run() { - NameNVisibilityInformation info = new NameNVisibilityInformation(); - CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, selection, info, project); - ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard( - refactoring, info); - RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); - - try { - operator.run(shellProvider.getShell(), refactoring.getName()); - } catch (InterruptedException e) { - // initial condition checking got canceled by the user. - } + ExtractLocalVariableRefactoring refactoring = + new ExtractLocalVariableRefactoring(element, selection, project); + ExtractLocalVariableRefactoringWizard wizard = + new ExtractLocalVariableRefactoringWizard(refactoring); + run(wizard, refactoring, RefactoringSaveHelper.SAVE_NOTHING); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringWizard.java index f4d05a18cef..708078a662b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,15 +7,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Tom Ball (Google) - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; -import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; - /** * The wizard page for Extract Local Variable Refactoring, creates the UI page. * @@ -23,17 +21,15 @@ import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; */ public class ExtractLocalVariableRefactoringWizard extends RefactoringWizard { private InputPage page; - private final NameNVisibilityInformation info; - public ExtractLocalVariableRefactoringWizard(Refactoring refactoring, - NameNVisibilityInformation info) { + public ExtractLocalVariableRefactoringWizard(ExtractLocalVariableRefactoring refactoring) { super(refactoring, WIZARD_BASED_USER_INTERFACE); - this.info = info; } @Override protected void addUserInputPages() { - page = new InputPage(Messages.ExtractLocalVariable, info); + ExtractLocalVariableRefactoring refactoring = (ExtractLocalVariableRefactoring) getRefactoring(); + page = new InputPage(Messages.ExtractLocalVariable, refactoring.getRefactoringInfo()); addPage(page); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java index 813beba470f..0baea03846b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoring.java @@ -50,7 +50,6 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter; import org.eclipse.cdt.internal.ui.refactoring.Container; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; import org.eclipse.cdt.internal.ui.refactoring.implementmethod.InsertLocation; import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder; import org.eclipse.cdt.internal.ui.refactoring.utils.Checks; @@ -93,8 +92,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 { private InsertLocation definitionInsertLocation; public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection, - ICProject project, RefactoringASTCache astCache) { - super(element, selection, project, astCache); + ICProject project) { + super(element, selection, project); context = new GetterSetterContext(); } @@ -148,7 +147,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 { } private void initRefactoring(IProgressMonitor pm) throws OperationCanceledException, CoreException { - IASTTranslationUnit ast = astCache.getAST(tu, null); + IASTTranslationUnit ast = getAST(tu, null); context.selectedName = getSelectedName(ast); IASTCompositeTypeSpecifier compositeTypeSpecifier = null; if (context.selectedName != null) { @@ -279,7 +278,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 { IASTSimpleDeclaration decl = context.existingFields.get(0); MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder(); InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(), - astCache, pm); + refactoringContext, pm); if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) { location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoringRunner.java index 04684f8190c..f20eda89b80 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; +import org.eclipse.ltk.ui.refactoring.RefactoringWizard; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; @@ -22,7 +23,6 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper; /** @@ -36,14 +36,13 @@ public class GenerateGettersAndSettersRefactoringRunner extends RefactoringRunne } @Override - public void run(RefactoringASTCache astCache) { + public void run() { if (getActiveEditor() instanceof ITextEditor) { GenerateGettersAndSettersRefactoring refactoring = - new GenerateGettersAndSettersRefactoring(element, selection, project, astCache); - GenerateGettersAndSettersRefactoringWizard wizard = + new GenerateGettersAndSettersRefactoring(element, selection, project); + RefactoringWizard wizard = new GenerateGettersAndSettersRefactoringWizard(refactoring); - starter.activate(wizard, shellProvider.getShell(), refactoring.getName(), - RefactoringSaveHelper.SAVE_REFACTORING); + run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java index fde32199eaa..fff9e766f97 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Marc-Andre Laperle + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.implementmethod; @@ -59,7 +60,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; import org.eclipse.cdt.internal.ui.refactoring.utils.Checks; import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; @@ -78,8 +78,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 { private Map insertLocations; private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory(); - public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project, RefactoringASTCache astCache) { - super(element, selection, project, astCache); + public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project) { + super(element, selection, project); data = new ImplementMethodData(); methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder(); insertLocations = new HashMap(); @@ -99,7 +99,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 { data.setMethodDeclarations(unimplementedMethodDeclarations); if (selectedRegion.getLength() > 0) { - IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(selectedRegion, astCache.getAST(tu, pm)); + IASTSimpleDeclaration methodDeclaration = + SelectionHelper.findFirstSelectedDeclaration(selectedRegion, getAST(tu, pm)); if (NodeHelper.isMethodDeclaration(methodDeclaration)) { for (MethodToImplementConfig config : data.getMethodDeclarations()) { if (config.getDeclaration() == methodDeclaration) { @@ -114,8 +115,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 { return initStatus; } - private List findUnimplementedMethodDeclarations(IProgressMonitor pm) throws OperationCanceledException, CoreException { - IASTTranslationUnit ast = astCache.getAST(tu, pm); + private List findUnimplementedMethodDeclarations(IProgressMonitor pm) + throws OperationCanceledException, CoreException { + IASTTranslationUnit ast = getAST(tu, pm); final List list = new ArrayList(); ast.accept(new ASTVisitor() { { @@ -151,8 +153,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 { } try { - IIndexName[] indexNames = astCache.getIndex().findNames(binding, IIndex.FIND_DEFINITIONS - | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES); + IIndexName[] indexNames = getIndex().findNames(binding, + IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES); if (indexNames.length == 0) { return true; } @@ -166,7 +168,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 { @Override protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) - throws CoreException, OperationCanceledException { + throws CoreException, OperationCanceledException { List methodsToImplement = data.getMethodsToImplement(); SubMonitor sm = SubMonitor.convert(pm, 4 * methodsToImplement.size()); for (MethodToImplementConfig config : methodsToImplement) { @@ -174,8 +176,8 @@ public class ImplementMethodRefactoring extends CRefactoring2 { } } - protected void createDefinition(ModificationCollector collector, - MethodToImplementConfig config, IProgressMonitor subMonitor) throws CoreException, OperationCanceledException { + protected void createDefinition(ModificationCollector collector, MethodToImplementConfig config, + IProgressMonitor subMonitor) throws CoreException, OperationCanceledException { if (subMonitor.isCanceled()) { throw new OperationCanceledException(); } @@ -228,7 +230,9 @@ public class ImplementMethodRefactoring extends CRefactoring2 { if (insertLocations.containsKey(methodDeclaration)) { return insertLocations.get(methodDeclaration); } - InsertLocation insertLocation = methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(), methodDeclaration.getParent(), astCache, subMonitor); + InsertLocation insertLocation = + methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(), + methodDeclaration.getParent(), refactoringContext, subMonitor); if (insertLocation.getTranslationUnit() == null || NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) { insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu); @@ -286,7 +290,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 { int insertOffset = insertLocation.getInsertPosition(); return NameHelper.createQualifiedNameFor( functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(), - insertLocation.getTranslationUnit(), insertOffset, astCache); + insertLocation.getTranslationUnit(), insertOffset, refactoringContext); } public ImplementMethodData getRefactoringData() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoringRunner.java index 58cf32b1fca..3277463bfa6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,17 +9,18 @@ * Contributors: * Institute for Software - initial API and implementation * Marc-Andre Laperle + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.implementmethod; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; -import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; + import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner2; +import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper; /** * @author Lukas Felber @@ -32,15 +33,10 @@ public class ImplementMethodRefactoringRunner extends RefactoringRunner2 { } @Override - public void run(RefactoringASTCache astCache) { - ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(element, selection, project, astCache); + public void run() { + ImplementMethodRefactoring refactoring = + new ImplementMethodRefactoring(element, selection, project); ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring); - RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); - - try { - operator.run(shellProvider.getShell(), refactoring.getName()); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + run(wizard, refactoring, RefactoringSaveHelper.SAVE_REFACTORING); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder.java index f841aba62ff..00fdd0213a3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder.java @@ -34,7 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; @@ -53,7 +53,7 @@ public class MethodDefinitionInsertLocationFinder { new HashMap(); public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation, - IASTNode parent, RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException { + IASTNode parent, CRefactoringContext astCache, IProgressMonitor pm) throws CoreException { IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent); InsertLocation insertLocation = new InsertLocation(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/DeclaratorFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/DeclaratorFinder.java index fe09c6a4f00..147f3c65e00 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/DeclaratorFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/DeclaratorFinder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2011, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.togglefunction; @@ -18,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -29,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; * are skipped during search. */ public class DeclaratorFinder { - private IASTFunctionDeclarator foundDeclarator; public DeclaratorFinder(ITextSelection selection, IASTTranslationUnit unit) { @@ -47,16 +49,15 @@ public class DeclaratorFinder { return foundDeclarator.getName(); } - private IASTFunctionDeclarator findDeclaratorInSelection( -ITextSelection selection, + private IASTFunctionDeclarator findDeclaratorInSelection(ITextSelection selection, IASTTranslationUnit unit) { - IASTNode firstNodeInsideSelection = unit.getNodeSelector(null) - .findFirstContainedNode(selection.getOffset(), - selection.getLength()); + IASTNodeSelector nodeSelector = unit.getNodeSelector(null); + IASTNode firstNodeInsideSelection = + nodeSelector.findFirstContainedNode(selection.getOffset(), selection.getLength()); IASTFunctionDeclarator declarator = findDeclaratorInAncestors(firstNodeInsideSelection); if (declarator == null) { - firstNodeInsideSelection = unit.getNodeSelector(null).findEnclosingNode( + firstNodeInsideSelection = nodeSelector.findEnclosingNode( selection.getOffset(), selection.getLength()); declarator = findDeclaratorInAncestors(firstNodeInsideSelection); } @@ -65,6 +66,9 @@ ITextSelection selection, private IASTFunctionDeclarator findDeclaratorInAncestors(IASTNode node) { while (node != null) { + if (node instanceof IASTProblemStatement) { + return null; + } IASTFunctionDeclarator declarator = extractDeclarator(node); if (node instanceof ICPPASTTemplateDeclaration) { declarator = extractDeclarator(((ICPPASTTemplateDeclaration) node).getDeclaration()); @@ -93,8 +97,7 @@ ITextSelection selection, throw new NotSupportedException(Messages.DeclaratorFinder_MultipleDeclarators); } - if (declarators.length == 1 && - declarators[0] instanceof IASTFunctionDeclarator) + if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) return (IASTFunctionDeclarator) declarators[0]; } return null; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFileCreator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFileCreator.java index 0e8480badae..12685e93b9f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFileCreator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFileCreator.java @@ -65,19 +65,18 @@ public class ToggleFileCreator { } return result; } - + public void createNewFile() { - CreateFileChange change; String filename = getNewFileName(); try { - change = new CreateFileChange(filename, new Path(getPath() + filename), + CreateFileChange change = new CreateFileChange(filename, new Path(getPath() + filename), EMPTY_STRING, context.getSelectionFile().getCharset()); change.perform(new NullProgressMonitor()); } catch (CoreException e) { throw new NotSupportedException(Messages.ToggleFileCreator_CanNotCreateNewFile); } } - + public boolean askUserForFileCreation(final ToggleRefactoringContext context) { if (context.isSettedDefaultAnswer()) { return context.getDefaultAnswer(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java index bcfeee84ff8..6f1d44f84a4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java @@ -336,7 +336,7 @@ public class ToggleNodeHelper extends NodeHelper { for (IIndexFile thisFile : thisFileVariants) { for (IIndexInclude include : projectIndex.findIncludes(thisFile)) { if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) { - if (include.getIncludesLocation() == null){ + if (include.getIncludesLocation() == null) { throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$ } String loc = include.getIncludesLocation().getFullPath(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoring.java index 207b6cd5690..3fed98cbcc9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2011, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.togglefunction; @@ -38,17 +39,16 @@ import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; * position. */ public class ToggleRefactoring extends CRefactoring { - private ITextSelection selection; private IToggleRefactoringStrategy strategy; - protected ToggleRefactoringContext context; + private ToggleRefactoringContext context; private IIndex fIndex; public ToggleRefactoring(IFile file, ITextSelection selection, ICProject proj) { super(file, selection, null, proj); if (selection == null || file == null || project == null) initStatus.addFatalError(Messages.ToggleRefactoring_InvalidSelection); - if (!IDE.saveAllEditors(new IResource[] {ResourcesPlugin.getWorkspace().getRoot()}, false)) + if (!IDE.saveAllEditors(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, false)) initStatus.addFatalError(Messages.ToggleRefactoring_CanNotSaveFiles); this.selection = selection; } @@ -97,4 +97,8 @@ public class ToggleRefactoring extends CRefactoring { protected RefactoringDescriptor getRefactoringDescriptor() { return new EmptyRefactoringDescription(); } + + public ToggleRefactoringContext getContext() { + return context; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java index f74cb2193df..82956e9ce33 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java @@ -35,7 +35,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; import org.eclipse.cdt.internal.ui.util.EditorUtility; /** @@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility; public class DefinitionFinder { public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration, - RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException { + CRefactoringContext astCache, IProgressMonitor pm) throws CoreException { IIndex index = astCache.getIndex(); IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0]; if (index == null) { @@ -58,7 +58,7 @@ public class DefinitionFinder { } private static IASTName getDefinition(IIndexBinding binding, - RefactoringASTCache astCache, IIndex index, IProgressMonitor pm) throws CoreException { + CRefactoringContext astCache, IIndex index, IProgressMonitor pm) throws CoreException { Set searchedFiles = new HashSet(); List definitions = new ArrayList(); IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true); @@ -91,7 +91,7 @@ public class DefinitionFinder { } private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu, - RefactoringASTCache astCache, List definitions, IProgressMonitor pm) + CRefactoringContext astCache, List definitions, IProgressMonitor pm) throws OperationCanceledException, CoreException { IASTTranslationUnit ast = astCache.getAST(tu, pm); findDefinitionsInAST(binding, ast, tu, definitions); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java index a1b0ad6b310..2b9c52311a9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** * Helps with IASTNames. @@ -68,7 +68,7 @@ public class NameHelper { */ public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName, ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu, - int insertLocation, RefactoringASTCache astCache) throws CoreException { + int insertLocation, CRefactoringContext astCache) throws CoreException { ICPPASTQualifiedName qname = new CPPASTQualifiedName(); IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java index ef1ae37ef84..802a1e8d873 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleTypeTemplatePara import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** * Helper class to find Namespace informations. @@ -48,7 +48,7 @@ public class NamespaceHelper { * @return ICPPASTQualifiedName with the names of all namespaces * @throws CoreException */ - public static ICPPASTQualifiedName getSurroundingNamespace(final ITranslationUnit translationUnit, final int offset, RefactoringASTCache astCache) + public static ICPPASTQualifiedName getSurroundingNamespace(final ITranslationUnit translationUnit, final int offset, CRefactoringContext astCache) throws CoreException { final CPPASTQualifiedName qualifiedName = new CPPASTQualifiedName(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java index a2fb7e085be..633372ca9b2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,15 +8,18 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.utils; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -30,7 +33,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition; @@ -38,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.ui.refactoring.MethodContext; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; /** * General class for common Node operations. @@ -99,7 +107,72 @@ public class NodeHelper { return null; } - public static MethodContext findMethodContext(IASTNode node, IIndex index) throws CoreException{ + public static MethodContext findMethodContext(IASTNode node, CRefactoringContext astCache, + IProgressMonitor pm) throws CoreException { + IASTTranslationUnit translationUnit = node.getTranslationUnit(); + boolean found = false; + MethodContext context = new MethodContext(); + context.setType(MethodContext.ContextType.NONE); + IASTName name = null; + while (node != null && !found) { + node = node.getParent(); + if (node instanceof IASTFunctionDeclarator) { + name = ((IASTFunctionDeclarator) node).getName(); + found = true; + context.setType(MethodContext.ContextType.FUNCTION); + } else if (node instanceof IASTFunctionDefinition) { + name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()).getName(); + found = true; + context.setType(MethodContext.ContextType.FUNCTION); + } + } + getMethodContexWithIndex(astCache, translationUnit, name, context, pm); + return context; + } + + private static void getMethodContexWithIndex(CRefactoringContext astCache, + IASTTranslationUnit ast, IASTName name, MethodContext context, IProgressMonitor pm) + throws CoreException { + if (name instanceof ICPPASTQualifiedName) { + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; + context.setMethodQName(qname); + } + IBinding binding = name.resolveBinding(); + if (binding instanceof ICPPMethod) { + context.setType(MethodContext.ContextType.METHOD); + IIndex index = astCache.getIndex(); + IIndexName[] declarations = index.findDeclarations(binding); + if (declarations.length == 0) { + context.setMethodDeclarationName(name); + } else { + IASTFileLocation tuFileLocation = ast.getFileLocation(); + ICProject cProject = ast.getOriginatingTranslationUnit().getCProject(); + for (IIndexName decl : declarations) { + IASTTranslationUnit ast2 = ast; + if (!tuFileLocation.equals(decl.getFileLocation())) { + IIndexFileLocation fileLocation = decl.getFile().getLocation(); + ITranslationUnit locTu = + CoreModelUtil.findTranslationUnitForLocation(fileLocation, cProject); + astCache.getAST(locTu, pm); + } + IASTName declName = DeclarationFinder.findDeclarationInTranslationUnit(ast2, decl); + if (declName != null) { + IASTNode methodDeclaration = declName.getParent().getParent(); + if (methodDeclaration instanceof IASTSimpleDeclaration || + methodDeclaration instanceof IASTFunctionDefinition) { + context.setMethodDeclarationName(declName); + } + } + } + } + } + } + + /** + * @deprecated Use #findMethodContext(IASTNode, RefactoringASTCache, IProgressMonitor pm) + */ + @Deprecated + public static MethodContext findMethodContext(IASTNode node, IIndex index) throws CoreException { IASTTranslationUnit translationUnit = node.getTranslationUnit(); boolean found = false; MethodContext context = new MethodContext(); @@ -125,23 +198,7 @@ public class NodeHelper { return context; } - private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context, - IASTName name) { - if (name instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; - context.setMethodQName(qname); - IBinding bind = qname.resolveBinding(); - IASTName[] decl = translationUnit.getDeclarationsInAST(bind); - for (IASTName tmpname : decl) { - IASTNode methodDefinition = tmpname.getParent().getParent(); - if (methodDefinition instanceof IASTSimpleDeclaration) { - context.setMethodDeclarationName(tmpname); - context.setType(MethodContext.ContextType.METHOD); - } - } - } - } - + @Deprecated private static void getMethodContexWithIndex(IIndex index, IASTTranslationUnit translationUnit, MethodContext context, IASTName name) throws CoreException { IBinding bind = name.resolveBinding(); @@ -174,6 +231,23 @@ public class NodeHelper { } } + private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context, + IASTName name) { + if (name instanceof ICPPASTQualifiedName) { + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; + context.setMethodQName(qname); + IBinding bind = qname.resolveBinding(); + IASTName[] decl = translationUnit.getDeclarationsInAST(bind); + for (IASTName tmpname : decl) { + IASTNode methodDefinition = tmpname.getParent().getParent(); + if (methodDefinition instanceof IASTSimpleDeclaration) { + context.setMethodDeclarationName(tmpname); + context.setType(MethodContext.ContextType.METHOD); + } + } + } + } + public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) { while (node != null) { if (node instanceof IASTCompoundStatement) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractLocalVariableAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractLocalVariableAction.java index b269b35294e..6fd7993a400 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractLocalVariableAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractLocalVariableAction.java @@ -1,18 +1,17 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 Wind River Systems, Inc. + * Copyright (c) 2005, 2011 Wind River Systems, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.refactoring.actions; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.window.IShellProvider; @@ -38,9 +37,8 @@ public class ExtractLocalVariableAction extends RefactoringAction { @Override public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) { - IResource res= wc.getResource(); - if (res instanceof IFile) { - new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run(); + if (wc.getResource() != null) { + new ExtractLocalVariableRefactoringRunner(wc, selection, shellProvider, wc.getCProject()).run(); } }