diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariable.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariable.rts deleted file mode 100644 index 35bf54d93f3..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariable.rts +++ /dev/null @@ -1,622 +0,0 @@ -//!ExtractLocalVariableRefactoringTest int -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - return /*$*/42/*$$*/; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 42; - return i; -} - -//!ExtractLocalVariableRefactoringTest char -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - return /*$*/'c'/*$$*/; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - char temp = 'c'; - return temp; -} - -//!ExtractLocalVariableRefactoringTest float -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - float foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - float foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::foo() { - return /*$*/42.0f/*$$*/; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::foo() { - float f = 42.0f; - return f; -} - -//!ExtractLocalVariableRefactoringTest double -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - float foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - float foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::foo() { - return /*$*/42.0/*$$*/; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::foo() { - double f = 42.0; - return f; -} - -//!ExtractLocalVariableRefactoringTest parentheses -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - return /*$*/(42)/*$$*/; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 42; - return i; -} - -//!ExtractLocalVariableRefactoringTest proposed name in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int x = 3; - return /*$*/(x + 2)/*$$*/ * 15; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int x = 3; - int i = x + 2; - return i * 15; -} - -//!Bug #277065 extract local variable fails to extract from for loop -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -void foo() { - for (int n = /*$*/5 + 2/*$$*/; n < 10; ++n) - ; -} - -//= -void foo() { - int i = 5 + 2; - for (int n = i; n < 10; ++n) - ; -} - -//!ExtractLocalVariableRefactoringTest expression -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -void foo() { - int a = 0; - float b = 0.1f; - double c = /*$*/(a + b)/*$$*/ * 0.2; -} - -//= -void foo() { - int a = 0; - float b = 0.1f; - float a0 = a + b; - double c = a0 * 0.2; -} - -//!ExtractLocalVariableRefactoringTest pointer -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -void foo() { - int a[2]; - int b = */*$*/(a + 1)/*$$*/; -} - -//= -void foo() { - int a[2]; - int* i = a + 1; - int b = *i; -} - -//!ExtractLocalVariableRefactoringTest qualifiers -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -const volatile int* k; - -void foo() { - /*$*/k;/*$$*/ -} - -//= -const volatile int* k; - -void foo() { - const volatile int* k0 = k; - k0; -} - -//!ExtractLocalVariableRefactoringTest overloaded operators -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -class K { -public: - bool operator+(int b) { return true; } - float operator+(unsigned u) { return 1.0f; } -}; -void foo() { - K k; - /*$*/k+3u/*$$*/; -} - -//= -class K { -public: - bool operator+(int b) { return true; } - float operator+(unsigned u) { return 1.0f; } -}; -void foo() { - K k; - float i = k + 3u; - i; -} - -//!Bug 318784 DeclarationGenerator fails for some cases -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -void func() { - int* (*a)[2]; - /*$*/a/*$$*/; -} - -//= - -void func() { - int* (*a)[2]; - int* (*a0)[2] = a; - a0; -} - -//!Bug 331963 Extract local variable doesn't put template type parameters -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -template -class Foo { -}; - -Foo getFoo(); - -int main() { - /*$*/getFoo()/*$$*/; - return 0; -} - -//= - -template -class Foo { -}; - -Foo getFoo(); - -int main() { - Foo foo = getFoo(); - foo; - return 0; -} - -//!Bug 331963 Extract local variable doesn't put template type parameters Namespace -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp -namespace bar { - -template -class Foo { -}; - -} - -bar::Foo getFoo(); - -int main() { - /*$*/getFoo()/*$$*/; - return 0; -} - -//= -namespace bar { - -template -class Foo { -}; - -} - -bar::Foo getFoo(); - -int main() { - bar::Foo foo = getFoo(); - foo; - return 0; -} - -//!Bug 330693 Improve suggested variable name in Extract Local Variable -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -struct Foo { - int getVarWithLongName(); -}; - -void bar() { - Foo f; - /*$*/f.getVarWithLongName()/*$$*/; -} - -//= - -struct Foo { - int getVarWithLongName(); -}; - -void bar() { - Foo f; - int varWithLongName = f.getVarWithLongName(); - varWithLongName; -} - -//!Bug 330693 Improve suggested variable name in Extract Local Variable: name == prefix -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -struct Foo { - int get(); -}; - -void bar() { - Foo f; - /*$*/f.get()/*$$*/; -} - -//= - -struct Foo { - int get(); -}; - -void bar() { - Foo f; - int get = f.get(); - get; -} - -//!Bug 335202 Suggested name is wrong for nested function calls - outer function call -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -int getA() { - return 0; -}; - -int getB(int a) { - return a; -} - -void bar() { - /*$*/getB(getA())/*$$*/; -} - -//= - -int getA() { - return 0; -}; - -int getB(int a) { - return a; -} - -void bar() { - int b = getB(getA()); - b; -} - -//!Bug 335202 Suggested name is wrong for nested function calls - inner function call -//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest -//@A.cpp - -int getA() { - return 0; -}; - -int getB(int a) { - return a; -} - -int getC(int a) { - return a; -} - -void bar() { - getB(/*$*/getC(getA())/*$$*/); -} - -//= - -int getA() { - return 0; -}; - -int getB(int a) { - return a; -} - -int getC(int a) { - return a; -} - -void bar() { - int c = getC(getA()); - getB(c); -} - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariableHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariableHistory.rts deleted file mode 100644 index ecbc8bbafdb..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariableHistory.rts +++ /dev/null @@ -1,23 +0,0 @@ -//!extract local variable from for loop -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@main.cpp -void foo() { - for (int n = 5 + 2; n < 10; ++n) - ; -} - -//= -void foo() { - int i = 5 + 2; - for (int n = i; n < 10; ++n) - ; -} - -//@refScript.xml - - - - 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 79c696ce73f..c0a5fbcac4c 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 @@ -18,7 +18,7 @@ import junit.framework.TestSuite; 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.extractlocalvariable.ExtractLocalVariableRefactoringTest; 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; @@ -40,7 +40,7 @@ public class RefactoringTestSuite extends TestSuite { suite.addTest(HideMethodTestSuite.suite()); suite.addTest(GenerateGettersAndSettersTest.suite()); suite.addTest(ImplementMethodTestSuite.suite()); - suite.addTest(ExtractLocalVariableTestSuite.suite()); + suite.addTest(ExtractLocalVariableRefactoringTest.suite()); suite.addTest(ToogleRefactoringTest.suite()); return suite; } 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 c63817296ba..50ab430807b 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 @@ -7,48 +7,537 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tom Ball (Google) - initial API and implementation + * Institute for Software - initial API and implementation * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable; -import java.util.Collection; -import java.util.Properties; +import junit.framework.Test; -import org.eclipse.core.resources.IFile; +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.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.extractlocalvariable.ExtractLocalVariableRefactoring; /** - * Test harness for Extract Local Variable refactoring tests. - * - * @author Tom Ball + * Tests for Extract Local Variable refactoring. */ -public class ExtractLocalVariableRefactoringTest extends RefactoringTest { - protected String variableName; +public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase { + private String extractedVariableName; + private ExtractLocalVariableRefactoring refactoring; - public ExtractLocalVariableRefactoringTest(String name, Collection files) { - super(name, files); + public ExtractLocalVariableRefactoringTest() { + super(); + } + + public ExtractLocalVariableRefactoringTest(String name) { + super(name); + } + + public static Test suite() { + return suite(ExtractLocalVariableRefactoringTest.class); } @Override - protected void runTest() throws Throwable { - 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); + protected Refactoring createRefactoring() { + refactoring = new ExtractLocalVariableRefactoring(getSelectedTranslationUnit(), + getSelection(), getCProject()); + return refactoring; } @Override - protected void configureRefactoring(Properties refactoringProperties) { - variableName = refactoringProperties.getProperty("variablename", "temp"); //$NON-NLS-1$ //$NON-NLS-2$ + protected void simulateUserInput() { + if (extractedVariableName != null) + refactoring.getRefactoringInfo().setName(extractedVariableName); + } + + //A.cpp + //int foo() { + // return /*$*/42/*$$*/; + //} + //==================== + //int foo() { + // int i = 42; + // return i; + //} + public void testIntLiteral() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //int foo() { + // return /*$*/'c'/*$$*/; + //} + //==================== + //int foo() { + // char c = 'c'; + // return c; + //} + public void testCharLiteral() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //const char* foo() { + // return /*$*/"Hello World!"/*$$*/; + //} + //==================== + //const char* foo() { + // const char* helloWorld = "Hello World!"; + // return helloWorld; + //} + public void testStringLiteral() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //double foo() { + // return /*$*/42.0f/*$$*/; + //} + //==================== + //double foo() { + // float f = 42.0f; + // return f; + //} + public void testFloatLiteral() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //double foo() { + // return /*$*/42./*$$*/; + //} + //==================== + //double foo() { + // double f = 42.; + // return f; + //} + public void testDoubleLiteral() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // return /*$*/(42)/*$$*/; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 42; + // return i; + //} + public void testParentheses() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int x = 3; + // return /*$*/(x + 2)/*$$*/ * 15; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int x = 3; + // int i = x + 2; + // return i * 15; + //} + public void testSuggestedNameInScope() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void foo() { + // for (int n = /*$*/5 + 2/*$$*/; n < 10; ++n) + // ; + //} + //==================== + //void foo() { + // int i = 5 + 2; + // for (int n = i; n < 10; ++n) + // ; + //} + public void testForStatement_Bug277065() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void foo() { + // int a = 0; + // float b = 0.1f; + // double c = /*$*/(a + b)/*$$*/ * 0.2; + //} + //==================== + //void foo() { + // int a = 0; + // float b = 0.1f; + // float a0 = a + b; + // double c = a0 * 0.2; + //} + public void testExpression() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void foo() { + // int a[2]; + // int b = */*$*/(a + 1)/*$$*/; + //} + //==================== + //void foo() { + // int a[2]; + // int* i = a + 1; + // int b = *i; + //} + public void testPointer() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //const volatile int* k; + // + //void foo() { + // /*$*/k;/*$$*/ + //} + //==================== + //const volatile int* k; + // + //void foo() { + // const volatile int* k0 = k; + // k0; + //} + public void testQualifiers() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //class K { + //public: + // bool operator+(int b) { return true; } + // float operator+(unsigned u) { return 1.0f; } + //}; + //void foo() { + // K k; + // /*$*/k+3u/*$$*/; + //} + //==================== + //class K { + //public: + // bool operator+(int b) { return true; } + // float operator+(unsigned u) { return 1.0f; } + //}; + //void foo() { + // K k; + // float i = k + 3u; + // i; + //} + public void testOverloadedOperators() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //void func() { + // int* (*a)[2]; + // /*$*/a/*$$*/; + //} + //==================== + // + //void func() { + // int* (*a)[2]; + // int* (*a0)[2] = a; + // a0; + //} + public void testArrayOfFunctionPointers_Bug318784() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //template + //class Foo { + //}; + // + //Foo getFoo(); + // + //int main() { + // /*$*/getFoo()/*$$*/; + // return 0; + //} + //==================== + // + //template + //class Foo { + //}; + // + //Foo getFoo(); + // + //int main() { + // Foo foo = getFoo(); + // foo; + // return 0; + //} + public void testTemplateTypeParameters_Bug331963() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //namespace bar { + // + //template + //class Foo { + //}; + // + //} + // + //bar::Foo getFoo(); + // + //int main() { + // /*$*/getFoo()/*$$*/; + // return 0; + //} + //==================== + //namespace bar { + // + //template + //class Foo { + //}; + // + //} + // + //bar::Foo getFoo(); + // + //int main() { + // bar::Foo foo = getFoo(); + // foo; + // return 0; + //} + public void testTemplateTypeParametersWithNamespace_Bug331963() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //struct Foo { + // int getVarWithLongName(); + //}; + // + //void bar() { + // Foo f; + // /*$*/f.getVarWithLongName()/*$$*/; + //} + //==================== + // + //struct Foo { + // int getVarWithLongName(); + //}; + // + //void bar() { + // Foo f; + // int varWithLongName = f.getVarWithLongName(); + // varWithLongName; + //} + public void testSuggestedName_Bug330693_1() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //struct Foo { + // int get(); + //}; + // + //void bar() { + // Foo f; + // /*$*/f.get()/*$$*/; + //} + //==================== + // + //struct Foo { + // int get(); + //}; + // + //void bar() { + // Foo f; + // int get = f.get(); + // get; + //} + public void testSuggestedName_Bug330693_2() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //int getA() { + // return 0; + //}; + // + //int getB(int a) { + // return a; + //} + // + //void bar() { + // /*$*/getB(getA())/*$$*/; + //} + //==================== + // + //int getA() { + // return 0; + //}; + // + //int getB(int a) { + // return a; + //} + // + //void bar() { + // int b = getB(getA()); + // b; + //} + public void testSuggestedName_Bug335202_1() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + // + //int getA() { + // return 0; + //}; + // + //int getB(int a) { + // return a; + //} + // + //int getC(int a) { + // return a; + //} + // + //void bar() { + // getB(/*$*/getC(getA())/*$$*/); + //} + //==================== + // + //int getA() { + // return 0; + //}; + // + //int getB(int a) { + // return a; + //} + // + //int getC(int a) { + // return a; + //} + // + //void bar() { + // int c = getC(getA()); + // getB(c); + //} + public void testSuggestedName_Bug335202_2() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //void foo() { + // for (int n = 5 + 2; n < 10; ++n) + // ; + //} + //==================== + //void foo() { + // int i = 5 + 2; + // for (int n = i; n < 10; ++n) + // ; + //} + + //refScript.xml + // + // + // + // + public void testLocalVariableFromForLoop() throws Exception { + assertRefactoringSuccess(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableTestSuite.java deleted file mode 100644 index 99395704841..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableTestSuite.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik - * Rapperswil, University of applied sciences and others - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Institute for Software - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester; - -/** - * Test suite to run just the Extract Local Variable unit tests. - * - * @author Tom Ball - */ -public class ExtractLocalVariableTestSuite extends TestSuite { - @SuppressWarnings("nls") - public static Test suite() throws Exception { - TestSuite suite = new ExtractLocalVariableTestSuite(); - suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringTests", - "resources/refactoring/ExtractLocalVariable.rts")); - suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringHistoryTests", - "resources/refactoring/ExtractLocalVariableHistory.rts")); - return suite; - } -} 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/NameAndVisibilityInformation.java similarity index 86% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameAndVisibilityInformation.java index af1d227b4c3..a3388f9f916 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/NameAndVisibilityInformation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,17 +8,19 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring; import java.util.ArrayList; +import java.util.List; 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 { +public class NameAndVisibilityInformation { private String name = ""; //$NON-NLS-1$ private VisibilityEnum visibility = VisibilityEnum.v_public; private final ArrayList usedNames = new ArrayList(); @@ -39,7 +41,7 @@ public class NameNVisibilityInformation { this.visibility = visibility; } - public ArrayList getUsedNames(){ + public List getUsedNames(){ return usedNames; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java index baef008a8c0..0081f99a733 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java @@ -22,7 +22,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; @@ -37,11 +37,11 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; public abstract class ExtractInputPage extends UserInputWizardPage { protected NameAndVisibilityComposite control; - protected NameNVisibilityInformation info; + protected NameAndVisibilityInformation info; protected String label = Messages.ExtractInputPage_ReplaceInSubclass; protected String errorLabel = Messages.ExtractInputPage_EnterName; - public ExtractInputPage(String name, NameNVisibilityInformation info) { + public ExtractInputPage(String name, NameAndVisibilityInformation info) { super(name); this.info = info; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantInfo.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantInfo.java index 29cf04b64db..244f7da02d1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantInfo.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantInfo.java @@ -12,13 +12,13 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant; import org.eclipse.cdt.internal.ui.refactoring.MethodContext; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation; /** * @author Emanuel Graf IFS * */ -public class ExtractConstantInfo extends NameNVisibilityInformation{ +public class ExtractConstantInfo extends NameAndVisibilityInformation{ private MethodContext mContext; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java index 5baa300e989..8f093a8bc61 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,36 +7,34 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractconstant; -import java.util.ArrayList; +import java.util.List; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage; public class InputPage extends ExtractInputPage { - - private final ArrayList usedNames; + private final List usedNames; private boolean showVisibilityPane; - public InputPage(String name, NameNVisibilityInformation info) { + public InputPage(String name, NameAndVisibilityInformation info) { this(name, info, true); } - public InputPage(String name, NameNVisibilityInformation info, boolean showVisibilityPane) { + public InputPage(String name, NameAndVisibilityInformation info, boolean showVisibilityPane) { super(name, info); label = Messages.InputPage_ConstName; errorLabel = Messages.InputPage_EnterContName; usedNames = info.getUsedNames(); this.showVisibilityPane = showVisibilityPane; } - - @Override public void createControl(Composite parent) { 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 fd5a43cb622..8e0c46425d0 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 @@ -68,9 +68,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring2; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper; @@ -88,12 +88,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 { "org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$ private IASTExpression target; - private final NameNVisibilityInformation info; + private final NameAndVisibilityInformation info; private NodeContainer container; public ExtractLocalVariableRefactoring(ICElement element, ISelection selection, ICProject project) { super(element, selection, project); - info = new NameNVisibilityInformation(); + info = new NameAndVisibilityInformation(); name = Messages.ExtractLocalVariable; } @@ -343,7 +343,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 { IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target); final IScope scope; if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) { - IASTCompoundStatement body = (IASTCompoundStatement)funcDef.getBody(); + IASTCompoundStatement body = (IASTCompoundStatement) funcDef.getBody(); scope = body.getScope(); } else { scope = null; @@ -383,10 +383,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 { if (expression instanceof CPPASTLiteralExpression) { CPPASTLiteralExpression literal = (CPPASTLiteralExpression) expression; String name = null; - char[] value = literal.getValue(); switch (literal.getKind()) { case IASTLiteralExpression.lk_char_constant: - name = Character.toString(value[0]); + name = "c"; //$NON-NLS-1$ break; case IASTLiteralExpression.lk_float_constant: name = "f"; //$NON-NLS-1$ @@ -511,13 +510,13 @@ public class ExtractLocalVariableRefactoring extends CRefactoring2 { private Map getArgumentMap() { Map arguments = new HashMap(); - arguments.put(CRefactoringDescription.FILE_NAME, tu.getLocationURI().toString()); - arguments.put(CRefactoringDescription.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$ + arguments.put(CRefactoringDescriptor.FILE_NAME, tu.getLocationURI().toString()); + arguments.put(CRefactoringDescriptor.SELECTION, selectedRegion.getOffset() + "," + selectedRegion.getLength()); //$NON-NLS-1$ arguments.put(ExtractLocalVariableRefactoringDescriptor.NAME, info.getName()); return arguments; } - public NameNVisibilityInformation getRefactoringInfo() { + public NameAndVisibilityInformation getRefactoringInfo() { return info; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/InputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/InputPage.java index 198bd5b5140..67b460397d5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/InputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/InputPage.java @@ -22,7 +22,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; -import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; +import org.eclipse.cdt.internal.ui.refactoring.NameAndVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.dialogs.LabeledTextField; import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult; @@ -35,10 +35,10 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult; */ public class InputPage extends UserInputWizardPage { private String label = Messages.VariableName; - private final NameNVisibilityInformation info; + private final NameAndVisibilityInformation info; private InputForm control; - public InputPage(String name, NameNVisibilityInformation info) { + public InputPage(String name, NameAndVisibilityInformation info) { super(name); this.info = info; }