diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts new file mode 100644 index 00000000000..ad7301cdaea --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts @@ -0,0 +1,232 @@ +//!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; //Hallo +} + +void A::bar() +{ + int a = 42; + int b = 42; +} + +//= +#include "A.h" + +A::A() +{ +} + +A::~A() +{ +} + +int A::foo() +{ + return theAnswer; //Hallo +} + +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/ExtractLocalVariableHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariableHistory.rts new file mode 100644 index 00000000000..b01f4096137 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractLocalVariableHistory.rts @@ -0,0 +1,21 @@ +//!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/resources/refactoring/ExtractMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts new file mode 100644 index 00000000000..d359fd5bcc4 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts @@ -0,0 +1,263 @@ +//!ExtractFunctionHistoryRefactoringTest variable defined in scope +//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest +//@A.h +#ifndef A_H_ +#define A_H_ + +class A +{ +public: + A(); + virtual ~A(); + int foo(); + +private: + int help(); +}; + +#endif /*A_H_*/ + +//= +#ifndef A_H_ +#define A_H_ + +class A +{ +public: + A(); + virtual ~A(); + int foo(); + +private: + int help(); + int exp(); +}; + +#endif /*A_H_*/ + +//@A.cpp +#include "A.h" + +A::A() +{ +} + +A::~A() +{ +} +int A::foo() +{ + int i = 2; + ++i; + help(); + return i; +} + +int A::help() +{ + return 42; +} + +//= +#include "A.h" + +A::A() +{ +} + +A::~A() +{ +} +int A::exp() +{ + int i = 2; + ++i; + help(); + return i; +} + +int A::foo() +{ + int i = exp(); + return i; +} + +int A::help() +{ + return 42; +} + +//@refScript.xml + + + + + + +//!ExtractFunctionHistoryRefactoringTest +//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest +//@A.h +#ifndef A_H_ +#define A_H_ + +class A +{ +public: + A(); + virtual ~A(); + int foo(); + +private: + int help(); +}; + +#endif /*A_H_*/ + +//= +#ifndef A_H_ +#define A_H_ + +class A +{ +public: + A(); + virtual ~A(); + int foo(); + +private: + int help(); + void exp(int & i); +}; + +#endif /*A_H_*/ + +//@A.cpp +#include "A.h" + +A::A() +{ +} + +A::~A() +{ +} +int A::foo() +{ + int i = 2; + //comment + ++i; + help(); + return i; +} + +int A::help() +{ + return 42; +} + +//= +#include "A.h" + +A::A() +{ +} + +A::~A() +{ +} +void A::exp(int & i) +{ + //comment + ++i; + help(); +} + +int A::foo() +{ + int i = 2; + exp(i); + return i; +} + +int A::help() +{ + return 42; +} + +//@refScript.xml + + + + + +//!Extract Function History first extracted statement with leading comment +//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest +//@main.cpp +int main(){ + + int i; + // Comment + i= 7; + return i; +} + +//= +void exp(int & i) +{ + // Comment + i = 7; +} + +int main(){ + + int i; + exp(i); + return i; +} + +//@refScript.xml + + + + + +//!Extract Function History extracted statement with trailling comment +//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest +//@main.cpp +int main(){ + + int i; + i= 7; // Comment + return i; +} + +//= +void exp(int & i) +{ + i = 7; // Comment +} + +int main(){ + + int i; + exp(i); + return i; +} + +//@refScript.xml + + + + diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts new file mode 100644 index 00000000000..70f04a80d94 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts @@ -0,0 +1,44 @@ +//!HideMethodSimple +//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest +//@A.h +#ifndef A_H_ +#define A_H_ + +#include + +class A{ +public: + A(); + void method2(); + std::string toString(); +private: + int i; +}; + +#endif /*A_H_*/ + +//= +#ifndef A_H_ +#define A_H_ + +#include + +class A{ +public: + A(); + std::string toString(); +private: + int i; + void method2(); +}; + +#endif /*A_H_*/ + +//@refScript.xml + + + + 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 new file mode 100644 index 00000000000..042688b2d51 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring; + +import java.io.ByteArrayInputStream; +import java.util.Properties; +import java.util.Vector; + +import org.eclipse.core.runtime.NullProgressMonitor; +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; + +import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; + +/** + * @author Emanuel Graf IFS + * + */ +public class RefactoringHistoryTest extends + ExtractFunctionRefactoringTest { + + private TestSourceFile scriptFile; + + public RefactoringHistoryTest(String name, + Vector files) { + super(name, files); + } + + @Override + protected void configureRefactoring(Properties refactoringProperties) { + scriptFile = fileMap.get(refactoringProperties.getProperty( + "scriptFile", "refScript.xml")); + + } + + @Override + protected void runTest() throws Throwable { + String xmlSource = scriptFile.getSource(); + xmlSource = xmlSource.replaceAll("\\$\\$projectPath\\$\\$", project.getLocation().toOSString()); + RefactoringHistory refHist = RefactoringHistoryService.getInstance() + .readRefactoringHistory( + new ByteArrayInputStream(xmlSource + .getBytes()), 0); + for (RefactoringDescriptorProxy proxy : refHist.getDescriptors()) { + RefactoringStatus status = new RefactoringStatus(); + CRefactoring ref = (CRefactoring) proxy + .requestDescriptor(new NullProgressMonitor()) + .createRefactoring(status); + assertTrue(status.isOK()); + RefactoringStatus checkInitialConditions = ref.checkInitialConditions(NULL_PROGRESS_MONITOR); + + if(fatalError){ + assertConditionsFatalError(checkInitialConditions); + return; + } + else{ + assertConditionsOk(checkInitialConditions); + executeRefactoring(ref); + } + } + } + +} 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 5f022792c4b..f5dfeb8b74a 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -21,6 +21,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus; 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.extractconstant.ExtractConstantInfo; import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; @@ -41,22 +42,16 @@ public class ExtractConstantRefactoringTest extends RefactoringTest { protected void runTest() throws Throwable { IFile refFile = project.getFile(fileName); ExtractConstantInfo info = new ExtractConstantInfo(); - ExtractConstantRefactoring refactoring = new ExtractConstantRefactoring( refFile, selection, info); - try { - refactoring.lockIndex(); - 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); - }finally { - refactoring.unlockIndex(); - } + 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); - } @Override 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 index 33008093668..6805442382a 100644 --- 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 @@ -27,6 +27,8 @@ public class ExtractConstantTestSuite extends TestSuite { 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 ad5832fec45..e2929b5fc1f 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -40,6 +40,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest { protected int returnParameterIndex; protected boolean fatalError; private VisibilityEnum visibility; + private static int nr = 1; /** * @param name @@ -53,7 +54,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest { protected void runTest() throws Throwable { IFile refFile = project.getFile(fileName); ExtractFunctionInformation info = new ExtractFunctionInformation(); - CRefactoring refactoring = new ExtractFunctionRefactoring( refFile, selection, info); + CRefactoring refactoring = new ExtractFunctionRefactoring( refFile, selection, info, cproject); RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); if(fatalError){ @@ -62,18 +63,28 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest { } else{ assertConditionsOk(checkInitialConditions); - executeRefactoring(info, refactoring); + setValues(info); + executeRefactoring(refactoring); } } - private void executeRefactoring(ExtractFunctionInformation info, CRefactoring refactoring) throws CoreException, Exception { + protected void executeRefactoring(CRefactoring refactoring) throws CoreException, Exception { + RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); + assertConditionsOk(finalConditions); + Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); + createChange.perform(NULL_PROGRESS_MONITOR); + compareFiles(fileMap); + } + + private void setValues(ExtractFunctionInformation info) { info.setMethodName(methodName); info.setReplaceDuplicates(replaceDuplicates); if(info.getInScopeDeclaredVariable() == null){ if(returnValue) { info.setReturnVariable(info.getAllAfterUsedNames().get(returnParameterIndex)); + info.getAllAfterUsedNames().get(returnParameterIndex).setUserSetIsReference(false); } } else { info.setReturnVariable( info.getInScopeDeclaredVariable() ); @@ -85,13 +96,6 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest { name.setUserSetIsReference(name.isReference()); } } - - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(finalConditions); - createChange.perform(NULL_PROGRESS_MONITOR); - - compareFiles(fileMap); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java index 0f9e6a8911f..816fe41c6d6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -29,6 +29,7 @@ public class ExtractFunctionTestSuite extends TestSuite { suite.addTest(RefactoringTester.suite("Extract Expression", "resources/refactoring/ExtractExpression.rts")); suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.rts")); suite.addTest(RefactoringTester.suite("Extract Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts")); + suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts")); 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 c59b91e563b..40555be621b 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -43,7 +43,7 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTest { IFile refFile = project.getFile(fileName); NameNVisibilityInformation info = new NameNVisibilityInformation(); info.setName(variableName); - CRefactoring refactoring = new ExtractLocalVariableRefactoring( refFile, selection, info); + CRefactoring refactoring = new ExtractLocalVariableRefactoring( refFile, selection, info, cproject); RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); if(fatalError){ 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 index dc3f7d36fb4..40bacfe0a48 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -28,6 +28,8 @@ public class ExtractLocalVariableTestSuite extends TestSuite { 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.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 7bb838c0647..4cd19b043e3 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,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -52,7 +52,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest { @Override protected void runTest() throws Throwable { IFile refFile = project.getFile(fileName); - refactoring = new GenerateGettersAndSettersRefactoring(refFile, selection, null); + refactoring = new GenerateGettersAndSettersRefactoring(refFile, selection, null, cproject); RefactoringStatus initialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); 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 06a4238a0f2..678ac57cb30 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -40,9 +40,7 @@ public class HideMethodRefactoringTest extends RefactoringTest { protected void runTest() throws Throwable { IFile refFile = project.getFile(fileWithSelection); - CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null); - try { - refactoring.lockIndex(); + CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject); RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); if(errors > 0) { assertConditionsError(checkInitialConditions, errors); @@ -52,7 +50,7 @@ public class HideMethodRefactoringTest extends RefactoringTest { }else { assertConditionsOk(checkInitialConditions); } - + Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); if(warnings > 0){ @@ -63,10 +61,6 @@ public class HideMethodRefactoringTest extends RefactoringTest { createChange.perform(NULL_PROGRESS_MONITOR); compareFiles(fileMap); - } - finally { - refactoring.unlockIndex(); - } } @Override diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodTestSuite.java index 10dd0f5d670..283f530108a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/hidemethod/HideMethodTestSuite.java @@ -27,6 +27,8 @@ public class HideMethodTestSuite extends TestSuite { TestSuite suite = new HideMethodTestSuite(); suite.addTest(RefactoringTester.suite("HideMethodRefactoringTests", "resources/refactoring/HideMethod.rts")); + suite.addTest(RefactoringTester.suite("HideMethodRefactoringHistoryTests", + "resources/refactoring/HideMethodHistory.rts")); return suite; } } 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 b78474b0f14..f1f1a82b932 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -42,7 +42,7 @@ public class ImplementMethodRefactoringTest extends RefactoringTest { IFile refFile = project.getFile(fileName); - CRefactoring refactoring = new ImplementMethodRefactoring(refFile, selection, null); + CRefactoring refactoring = new ImplementMethodRefactoring(refFile, selection, null, cproject); try { refactoring.lockIndex(); diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 713f45ea7da..9cd4a99660e 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1221,7 +1221,10 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CCompositeChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CCompositeChange.java new file mode 100644 index 00000000000..d1c036de860 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CCompositeChange.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring; + +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.ChangeDescriptor; +import org.eclipse.ltk.core.refactoring.CompositeChange; +import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor; + +/** + * @author Emanuel Graf IFS + * + */ +public class CCompositeChange extends CompositeChange { + + private RefactoringChangeDescriptor desc; + + public CCompositeChange(String name, Change[] children) { + super(name, children); + } + + public CCompositeChange(String name) { + super(name); + } + + public void setDescription(RefactoringChangeDescriptor descriptor) { + desc = descriptor; + } + + @Override + public ChangeDescriptor getDescriptor() { + if(desc == null) { + return super.getDescriptor(); + }else { + return desc; + } + } + + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java index 18a1c55b4ae..5bf5a364ecf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -23,6 +23,8 @@ import org.eclipse.jface.text.Region; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.cdt.core.CCorePlugin; @@ -68,7 +70,10 @@ public abstract class CRefactoring extends Refactoring { protected IASTTranslationUnit unit; private IIndex fIndex; - public CRefactoring(IFile file, ISelection selection, ICElement element) { + protected ICProject project; + + public CRefactoring(IFile file, ISelection selection, ICElement element, ICProject proj) { + project = proj; if (element instanceof ISourceReference) { ISourceReference sourceRef= (ISourceReference) element; ITranslationUnit tu= sourceRef.getTranslationUnit(); @@ -207,9 +212,13 @@ public abstract class CRefactoring extends Refactoring { public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { ModificationCollector collector = new ModificationCollector(); collectModifications(pm, collector); - return collector.createFinalChange(); + CCompositeChange finalChange = collector.createFinalChange(); + finalChange.setDescription(new RefactoringChangeDescriptor(getRefactoringDescriptor())); + return finalChange; } + abstract protected RefactoringDescriptor getRefactoringDescriptor(); + abstract protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException; 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 new file mode 100644 index 00000000000..fa6d1c9ba9c --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringContribution.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring; + +import java.util.Map; + +import org.eclipse.ltk.core.refactoring.RefactoringContribution; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; + +/** + * @author Emanuel Graf IFS + * + */ +public abstract class CRefactoringContribution extends RefactoringContribution { + + public CRefactoringContribution() { + super(); + } + + @SuppressWarnings("unchecked") + @Override + public Map retrieveArgumentMap(RefactoringDescriptor descriptor) { + if (descriptor instanceof CRefactoringDescription) { + CRefactoringDescription refDesc = (CRefactoringDescription) descriptor; + return refDesc.getParameterMap(); + }else { + return super.retrieveArgumentMap(descriptor); + } + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000000..09e17311303 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoringDescription.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +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.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.ui.CUIPlugin; + +/** + * @author Emanuel Graf IFS + * + */ +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) { + super(id, project, description, comment, flags); + this.arguments = arguments; + } + + public Map getParameterMap() { + return arguments; + } + + 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$ + } + return selection; + } + + protected ICProject getCProject() throws CoreException { + ICProject proj; + IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject()); + proj = CoreModel.getDefault().create(iProject); + if(proj == null) { + throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Unknown Project")); //$NON-NLS-1$ + } + return proj; + } + + protected IFile getFile() throws CoreException { + IFile file; + try { + file = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI(arguments.get(FILE_NAME)))[0]; + } 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/ModificationCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java index f5c5a927d05..691cd24e136 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; @@ -52,9 +51,9 @@ public class ModificationCollector { changes.add(change); } - public CompositeChange createFinalChange() { + public CCompositeChange createFinalChange() { // Synthetic changes aren't displayed and therefore don't need a name - CompositeChange result = new CompositeChange(""); //$NON-NLS-1$ + CCompositeChange result = new CCompositeChange(""); //$NON-NLS-1$ result.markAsSynthetic(); if(changes != null) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java index 08e93c87011..fd145b016be 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -16,6 +16,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; /** * Base class for all refactoring runners. @@ -29,12 +30,14 @@ public abstract class RefactoringRunner { protected ISelection selection; protected ICElement celement; protected IShellProvider shellProvider; + protected ICProject project; - public RefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) { + public RefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) { this.file = file; this.selection = selection; this.celement= element; this.shellProvider= shellProvider; + this.project = cProject; } public abstract void run(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java index 399f3271fe3..398db84af8f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -24,6 +26,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubMonitor; 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.text.edits.TextEditGroup; @@ -46,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; @@ -59,6 +63,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.MethodContext; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; @@ -74,52 +79,67 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper; */ public class ExtractConstantRefactoring extends CRefactoring { + public static final String ID = "org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring"; //$NON-NLS-1$ + private IASTLiteralExpression target = null; private final ArrayList literalsToReplace = new ArrayList(); private final ExtractConstantInfo info; - public ExtractConstantRefactoring(IFile file, ISelection selection, ExtractConstantInfo info){ - super(file,selection, null); + + public ExtractConstantRefactoring(IFile file, ISelection selection, ExtractConstantInfo info, ICProject proj){ + super(file,selection, null, proj); this.info = info; + this.project = proj; name = Messages.ExtractConstantRefactoring_ExtractConst; } @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { SubMonitor sm = SubMonitor.convert(pm, 9); - super.checkInitialConditions(sm.newChild(6)); + try { + lockIndex(); + try { + super.checkInitialConditions(sm.newChild(6)); - Collection literalExpressionCollection = findAllLiterals(); - if(literalExpressionCollection.isEmpty()){ - initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected); - return initStatus; - } - - sm.worked(1); - if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; - - boolean oneMarked = region != null && isOneMarked(literalExpressionCollection, region); - if(!oneMarked){ - //No or more than one marked - if(target == null){ - //No Selection found; - initStatus.addFatalError(Messages.ExtractConstantRefactoring_NoLiteralSelected); - } else { - //To many selection found - initStatus.addFatalError(Messages.ExtractConstantRefactoring_TooManyLiteralSelected); + Collection literalExpressionCollection = findAllLiterals(); + if(literalExpressionCollection.isEmpty()){ + initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected); + return initStatus; + } + sm.worked(1); + if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; + + boolean oneMarked = region != null && isOneMarked(literalExpressionCollection, region); + if(!oneMarked){ + //No or more than one marked + if(target == null){ + //No Selection found; + initStatus.addFatalError(Messages.ExtractConstantRefactoring_NoLiteralSelected); + } else { + //To many selection found + initStatus.addFatalError(Messages.ExtractConstantRefactoring_TooManyLiteralSelected); + } + return initStatus; + } + sm.worked(1); + + if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; + + findAllNodesForReplacement(literalExpressionCollection); + + info.addNamesToUsedNames(findAllDeclaredNames()); + if(info.getName().length() == 0) { + info.setName(getDefaultName(target)); + } + info.setMContext(NodeHelper.findMethodContext(target, getIndex())); + sm.done(); } - return initStatus; + finally { + unlockIndex(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - sm.worked(1); - - if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; - - findAllNodesForReplacement(literalExpressionCollection); - - info.addNamesToUsedNames(findAllDeclaredNames()); - info.setName(getDefaultName(target)); - info.setMContext(NodeHelper.findMethodContext(target, getIndex())); - sm.done(); return initStatus; } @@ -251,54 +271,79 @@ public class ExtractConstantRefactoring extends CRefactoring { @Override protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) - throws CoreException, OperationCanceledException{ - - MethodContext context = info.getMContext(); - Collection locLiteralsToReplace = new ArrayList(); + throws CoreException, OperationCanceledException{ + try { + lockIndex(); + try { + MethodContext context = info.getMContext(); + Collection locLiteralsToReplace = new ArrayList(); - if(context.getType() == MethodContext.ContextType.METHOD){ - - for (IASTExpression expression : literalsToReplace) { - MethodContext exprContext = NodeHelper.findMethodContext(expression, getIndex()); - if(exprContext.getType() == MethodContext.ContextType.METHOD){ - if(context.getMethodQName() != null) { - if( MethodContext.isSameClass(exprContext.getMethodQName(), context.getMethodQName())){ - locLiteralsToReplace.add(expression); + if(context.getType() == MethodContext.ContextType.METHOD){ + + for (IASTExpression expression : literalsToReplace) { + MethodContext exprContext = NodeHelper.findMethodContext(expression, getIndex()); + if(exprContext.getType() == MethodContext.ContextType.METHOD){ + if(context.getMethodQName() != null) { + if( MethodContext.isSameClass(exprContext.getMethodQName(), context.getMethodQName())){ + locLiteralsToReplace.add(expression); + } + }else { + if( MethodContext.isSameClass(exprContext.getMethodDeclarationName(), context.getMethodDeclarationName())){ + locLiteralsToReplace.add(expression); + } + } } - }else { - if( MethodContext.isSameClass(exprContext.getMethodDeclarationName(), context.getMethodDeclarationName())){ + } + + } else { + + for (IASTExpression expression : literalsToReplace) { + IPath path = new Path(expression.getContainingFilename()); + IFile expressionFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + //expressionFile may be null if the file is NOT in the workspace + if( expressionFile != null && expressionFile.equals(file) ){ locLiteralsToReplace.add(expression); } } + + } + + //Create all Changes for literals + String constName = info.getName(); + createLiteralToConstantChanges(constName, locLiteralsToReplace, collector); + + if(context.getType() == MethodContext.ContextType.METHOD) { + ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) context.getMethodDeclaration().getParent(); + AddDeclarationNodeToClassChange.createChange(classDefinition, info.getVisibility(), getConstNodesClass(constName), true, collector); + } else { + IASTDeclaration nodes = getConstNodesGlobal(constName); + ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit); + rewriter.insertBefore(unit, TranslationUnitHelper.getFirstNode(unit), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant)); } } - - } else { - - for (IASTExpression expression : literalsToReplace) { - IPath path = new Path(expression.getContainingFilename()); - IFile expressionFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); - //expressionFile may be null if the file is NOT in the workspace - if( expressionFile != null && expressionFile.equals(file) ){ - locLiteralsToReplace.add(expression); - } + finally { + unlockIndex(); } - - } - - //Create all Changes for literals - String constName = info.getName(); - createLiteralToConstantChanges(constName, locLiteralsToReplace, collector); - - if(context.getType() == MethodContext.ContextType.METHOD) { - ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) context.getMethodDeclaration().getParent(); - AddDeclarationNodeToClassChange.createChange(classDefinition, info.getVisibility(), getConstNodesClass(constName), true, collector); - } else { - IASTDeclaration nodes = getConstNodesGlobal(constName); - ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit); - rewriter.insertBefore(unit, TranslationUnitHelper.getFirstNode(unit), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + Map arguments = getArgumentMap(); + RefactoringDescriptor desc = new ExtractConstantRefactoringDescription( project.getProject().getName(), "Extract Constant Refactoring", "Create constant for " + 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(ExtractConstantRefactoringDescription.NAME, info.getName()); + arguments.put(ExtractConstantRefactoringDescription.VISIBILITY, info.getVisibility().toString()); + return arguments; + } private void createLiteralToConstantChanges(String constName, Iterable literals, ModificationCollector collector) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringContribution.java new file mode 100644 index 00000000000..0458f13487e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringContribution.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.extractconstant; + +import java.util.Map; + +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractConstantRefactoringContribution extends + CRefactoringContribution { + + @SuppressWarnings("unchecked") + @Override + public RefactoringDescriptor createDescriptor(String id, String project, + String description, String comment, Map arguments, int flags) + throws IllegalArgumentException { + if(id.equals(ExtractConstantRefactoring.ID)) { + return new ExtractConstantRefactoringDescription(project, description, comment, arguments); + }else { + return null; + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringDescription.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringDescription.java new file mode 100644 index 00000000000..33db1624c39 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringDescription.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.extractconstant; + +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.utils.VisibilityEnum; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractConstantRefactoringDescription extends + CRefactoringDescription { + protected static final String NAME = "name"; //$NON-NLS-1$ + protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$ + + protected ExtractConstantRefactoringDescription(String project, + String description, String comment, Map arguments) { + super(ExtractConstantRefactoring.ID, project, description, comment, RefactoringDescriptor.MULTI_CHANGE, arguments); + } + + @Override + public Refactoring createRefactoring(RefactoringStatus status) + throws CoreException { + IFile file; + ExtractConstantInfo info = new ExtractConstantInfo(); + ICProject proj; + + info.setName(arguments.get(NAME)); + info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(arguments.get(VISIBILITY))); + + proj = getCProject(); + + file = getFile(); + + ISelection selection = getSelection(); + return new ExtractConstantRefactoring(file, selection, info, proj); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringRunner.java index 604b1dbdf38..e101dec2571 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -12,12 +12,11 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant; import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.IShellProvider; import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; -import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; @@ -28,29 +27,22 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; */ public class ExtractConstantRefactoringRunner extends RefactoringRunner { - public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) { - super(file, selection, null, shellProvider); + public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, null, shellProvider, cProject); } @Override public void run() { ExtractConstantInfo info = new ExtractConstantInfo(); - CRefactoring refactoring = new ExtractConstantRefactoring(file,selection,info); + CRefactoring refactoring = new ExtractConstantRefactoring(file,selection,info, project); ExtractConstantRefactoringWizard wizard = new ExtractConstantRefactoringWizard(refactoring, info); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); - + try { - refactoring.lockIndex(); - try { - operator.run(shellProvider.getShell(), refactoring.getName()); - } - finally { - refactoring.unlockIndex(); - } + operator.run(shellProvider.getShell(), refactoring.getName()); + } catch (InterruptedException e) { Thread.currentThread().interrupt(); - } catch (CoreException e) { - CUIPlugin.log(e); - } + } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java index b2dacd08a90..7a1373127e1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java @@ -54,7 +54,6 @@ public class ChooserComposite extends Composite { boolean hasNoPredefinedReturnValue = true; if (info.getInScopeDeclaredVariable() != null) { - info.getInScopeDeclaredVariable().setUserSetIsReturnValue(true); hasNoPredefinedReturnValue = false; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index a6d2786d6a0..8f14212aee0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -30,6 +30,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.text.edits.TextEditGroup; @@ -70,6 +71,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression; @@ -95,6 +97,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.Container; import org.eclipse.cdt.internal.ui.refactoring.MethodContext; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; @@ -106,6 +109,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper; public class ExtractFunctionRefactoring extends CRefactoring { + + public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"; //$NON-NLS-1$ static final Integer NULL_INTEGER = Integer.valueOf(0); static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$ @@ -127,8 +132,8 @@ public class ExtractFunctionRefactoring extends CRefactoring { private INodeFactory factory = CPPNodeFactory.getDefault(); public ExtractFunctionRefactoring(IFile file, ISelection selection, - ExtractFunctionInformation info) { - super(file, selection, null); + ExtractFunctionInformation info, ICProject project) { + super(file, selection, null, project); this.info = info; name = Messages.ExtractFunctionRefactoring_ExtractFunction; names = new HashMap(); @@ -166,15 +171,13 @@ public class ExtractFunctionRefactoring extends CRefactoring { info.setAllUsedNames(container.getUsedNamesUnique()); if (container.size() < 1) { - status - .addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected); + status.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected); sm.done(); return status; } if (container.getAllDeclaredInScope().size() > 1) { - status - .addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected); + status.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected); } else if (container.getAllDeclaredInScope().size() == 1) { info.setInScopeDeclaredVariable(container.getAllDeclaredInScope().get(0)); } @@ -188,6 +191,19 @@ public class ExtractFunctionRefactoring extends CRefactoring { info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0))); MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex()); info.setMethodContext(context); + + if (info.getInScopeDeclaredVariable() != null) { + info.getInScopeDeclaredVariable().setUserSetIsReturnValue(true); + } + for (int i = 0; i < info.getAllUsedNames().size(); i++) { + if (!info.getAllUsedNames().get(i).isDeclarationInScope()) { + NameInformation name = info.getAllUsedNames().get(i); + if(!name.isReturnValue()) { + name.setUserSetIsReference(name.isReference()); + } + } + } + sm.done(); return status; } @@ -212,12 +228,10 @@ public class ExtractFunctionRefactoring extends CRefactoring { for (IASTNode node : cont.getNodesToWrite()) { node.accept(vis); if (vis.containsContinue()) { - initStatus - .addFatalError(Messages.ExtractFunctionRefactoring_Error_Continue); + initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Continue); break; } else if (vis.containsBreak()) { - initStatus - .addFatalError(Messages.ExtractFunctionRefactoring_Error_Break); + initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Break); break; } } @@ -226,8 +240,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { for (IASTNode node : cont.getNodesToWrite()) { node.accept(rFinder); if (rFinder.containsReturn()) { - initStatus - .addFatalError(Messages.ExtractFunctionRefactoring_Error_Return); + initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Return); break; } } @@ -751,4 +764,20 @@ public class ExtractFunctionRefactoring extends CRefactoring { } } + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + Map arguments = getArgumentMap(); + RefactoringDescriptor desc = new ExtractFunctionRefactoringDescription( project.getProject().getName(), "Extract Method Refactoring", "Create method " + info.getMethodName(), 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(ExtractFunctionRefactoringDescription.NAME, info.getMethodName()); + arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY, info.getVisibility().toString()); + return arguments; + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringContribution.java new file mode 100644 index 00000000000..a8397179d8c --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringContribution.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.extractfunction; + +import java.util.Map; + +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractFunctionRefactoringContribution extends CRefactoringContribution { + + @SuppressWarnings("unchecked") + @Override + public RefactoringDescriptor createDescriptor(String id, String project, String description, + String comment, Map arguments, int flags) throws IllegalArgumentException { + if(id.equals(ExtractFunctionRefactoring.ID)) { + return new ExtractFunctionRefactoringDescription(project, description, comment, arguments); + }else { + return null; + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringDescription.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringDescription.java new file mode 100644 index 00000000000..2f034329f75 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringDescription.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.extractfunction; + +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.utils.VisibilityEnum; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractFunctionRefactoringDescription extends CRefactoringDescription { + protected static final String NAME = "name"; //$NON-NLS-1$ + protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$ + + public ExtractFunctionRefactoringDescription(String project, String description, + String comment, Map arguments) { + super(ExtractFunctionRefactoring.ID, project, description, comment, RefactoringDescriptor.MULTI_CHANGE, arguments); + } + + @Override + public Refactoring createRefactoring(RefactoringStatus status) throws CoreException { + IFile file; + ExtractFunctionInformation info = new ExtractFunctionInformation(); + ICProject proj; + + info.setMethodName(arguments.get(NAME)); + info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(arguments.get(VISIBILITY))); + + proj = getCProject(); + file = getFile(); + + ISelection selection = getSelection(); + return new ExtractFunctionRefactoring(file, selection, info, proj); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringRunner.java index 5e453713bf7..2886c0d747c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -16,6 +16,8 @@ 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.ICProject; + import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; @@ -25,15 +27,15 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; */ public class ExtractFunctionRefactoringRunner extends RefactoringRunner { - public ExtractFunctionRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) { - super(file, selection, null, shellProvider); + public ExtractFunctionRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, null, shellProvider, cProject); } @Override public void run() { ExtractFunctionInformation info = new ExtractFunctionInformation(); - CRefactoring refactoring = new ExtractFunctionRefactoring(file,selection,info); + CRefactoring refactoring = new ExtractFunctionRefactoring(file,selection,info, project); ExtractFunctionRefactoringWizard wizard = new ExtractFunctionRefactoringWizard(refactoring,info); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); 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 baccfce2df9..790506449e8 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,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Google and others. All rights reserved. This program and + * Copyright (c) 2008, 2009 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 @@ -11,7 +11,9 @@ package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -20,6 +22,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; 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.text.edits.TextEditGroup; @@ -45,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; @@ -56,6 +60,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; 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.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer; @@ -71,61 +76,73 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper; * @author Tom Ball */ public class ExtractLocalVariableRefactoring extends CRefactoring { + + public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$ + private IASTExpression target = null; private final NameNVisibilityInformation info; private NodeContainer container; public ExtractLocalVariableRefactoring(IFile file, ISelection selection, - NameNVisibilityInformation info) { - super(file, selection, null); + NameNVisibilityInformation info, ICProject project) { + super(file, selection, null, project); this.info = info; name = Messages.ExtractLocalVariable; } @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) - throws CoreException, OperationCanceledException { + throws CoreException, OperationCanceledException { SubMonitor sm = SubMonitor.convert(pm, 9); - super.checkInitialConditions(sm.newChild(6)); + try { + lockIndex(); + try { + super.checkInitialConditions(sm.newChild(6)); - container = findAllExpressions(); - if (container.size() < 1) { - initStatus.addFatalError(Messages.ExpressionMustBeSelected); - return initStatus; - } + container = findAllExpressions(); + if (container.size() < 1) { + initStatus.addFatalError(Messages.ExpressionMustBeSelected); + return initStatus; + } - sm.worked(1); - if (isProgressMonitorCanceld(sm, initStatus)) - return initStatus; + sm.worked(1); + if (isProgressMonitorCanceld(sm, initStatus)) + return initStatus; - boolean oneMarked = region != null + boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region); - if (!oneMarked) { - if (target == null) { - initStatus.addFatalError(Messages.NoExpressionSelected); - } else { - initStatus.addFatalError(Messages.TooManyExpressionsSelected); + 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; + + container.findAllNames(); + sm.worked(1); + + container.getAllAfterUsedNames(); + info.addNamesToUsedNames(findAllDeclaredNames()); + sm.worked(1); + + NodeHelper.findMethodContext(container.getNodesToWrite().get(0), + getIndex()); + sm.worked(1); + + info.setName(guessTempName()); + sm.done(); + }finally { + unlockIndex(); } - return initStatus; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - sm.worked(1); - - if (isProgressMonitorCanceld(sm, initStatus)) - return initStatus; - - container.findAllNames(); - sm.worked(1); - - container.getAllAfterUsedNames(); - info.addNamesToUsedNames(findAllDeclaredNames()); - sm.worked(1); - - NodeHelper.findMethodContext(container.getNodesToWrite().get(0), - getIndex()); - sm.worked(1); - - info.setName(guessTempName()); - sm.done(); return initStatus; } @@ -240,22 +257,31 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException { - String variableName = info.getName(); - TextEditGroup editGroup = new TextEditGroup( - Messages.CreateLocalVariable); + try { + lockIndex(); + try { + 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(unit); - rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, - declaration, editGroup); + // Define temporary variable declaration and insert it + IASTStatement declInsertPoint = getParentStatement(target); + IASTDeclarationStatement declaration = getVariableNodes(variableName); + declaration.setParent(declInsertPoint.getParent()); + ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit); + 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); + // 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(); + } } private IASTStatement getParentStatement(IASTNode node) { @@ -430,4 +456,19 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { } return null; } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + Map arguments = getArgumentMap(); + RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescription(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()); + return arguments; + } } 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 new file mode 100644 index 00000000000..45854aa4044 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringContribution.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; + +import java.util.Map; + +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractLocalVariableRefactoringContribution extends CRefactoringContribution { + + @SuppressWarnings("unchecked") + @Override + 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); + }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/ExtractLocalVariableRefactoringDescription.java new file mode 100644 index 00000000000..8a850236bcc --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringDescription.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +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.RefactoringStatus; + +import org.eclipse.cdt.core.model.ICProject; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; +import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; + +/** + * @author Emanuel Graf IFS + * + */ +public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription { + + static protected final String NAME = "name"; //$NON-NLS-1$ + + public ExtractLocalVariableRefactoringDescription(String project, String description, + String comment, Map arguments) { + super(ExtractLocalVariableRefactoring.ID, project, description, comment, CRefactoringDescription.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(); + + ISelection selection = getSelection(); + return new ExtractLocalVariableRefactoring(file, selection, info, proj); + } + +} 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 19ecc480592..12e6396fbd9 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -16,6 +16,8 @@ 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.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; @@ -28,15 +30,15 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner { public ExtractLocalVariableRefactoringRunner(IFile file, - ISelection selection, IShellProvider shellProvider) { - super(file, selection, null, shellProvider); + ISelection selection, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, null, shellProvider, cProject); } @Override public void run() { NameNVisibilityInformation info = new NameNVisibilityInformation(); CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, - selection, info); + selection, info, project); ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard( refactoring, info); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); 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 908de7bee85..87da5257acd 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; 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.cdt.core.dom.ast.ASTNodeProperty; @@ -37,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; @@ -81,8 +83,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring { private static final String MEMBER_DECLARATION = "MEMBER_DECLARATION"; //$NON-NLS-1$ private final GetterAndSetterContext context = new GetterAndSetterContext(); - public GenerateGettersAndSettersRefactoring(IFile file, ISelection selection, ICElement element) { - super(file, selection, element); + public GenerateGettersAndSettersRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) { + super(file, selection, element, project); } @Override @@ -195,5 +197,11 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring { public Region getRegion() { return region; + } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + // TODO egraf add Descriptor + return null; } } 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 0d8d8ca1744..d0dc48ffbb7 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -19,6 +19,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; @@ -28,14 +29,14 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; */ public class GenerateGettersAndSettersRefactoringRunner extends RefactoringRunner { - public GenerateGettersAndSettersRefactoringRunner(IFile file, ISelection selection, ICElement elem, IShellProvider shellProvider) { - super(file, selection, elem, shellProvider); + public GenerateGettersAndSettersRefactoringRunner(IFile file, ISelection selection, ICElement elem, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, elem, shellProvider, cProject); } @Override public void run() { if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof ITextEditor) { - GenerateGettersAndSettersRefactoring refactoring = new GenerateGettersAndSettersRefactoring(file, selection, celement); + GenerateGettersAndSettersRefactoring refactoring = new GenerateGettersAndSettersRefactoring(file, selection, celement, project); GenerateGettersAndSettersRefactoringWizard wizard = new GenerateGettersAndSettersRefactoringWizard(refactoring); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java index 05db53a4898..29bb93700e3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.ui.refactoring.hidemethod; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -19,6 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.text.edits.TextEditGroup; @@ -38,12 +41,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.utils.DeclarationFinder; import org.eclipse.cdt.internal.ui.refactoring.utils.DeclarationFinderDO; @@ -57,90 +62,102 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; * */ public class HideMethodRefactoring extends CRefactoring { + + public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring"; //$NON-NLS-1$ private IASTName methodToHide; private IASTDeclaration methodToHideDecl; private DeclarationFinderDO declData; - public HideMethodRefactoring(IFile file, ISelection selection, ICElement element) { - super(file, selection, element); + public HideMethodRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) { + super(file, selection, element, project); name = Messages.HideMethodRefactoring_HIDE_METHOD; } @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { SubMonitor sm = SubMonitor.convert(pm, 10); - super.checkInitialConditions(sm.newChild(6)); - - if(initStatus.hasFatalError()){ - return initStatus; - } - - if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; - - IASTName name; - ArrayList names = findAllMarkedNames(); - if (names.size() < 1) { - initStatus.addFatalError(Messages.HideMethodRefactoring_NoNameSelected); - return initStatus; - } - name = names.get(names.size()-1); - sm.worked(1); - if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; - - declData = DeclarationFinder.getDeclaration(name, getIndex()); - - if(declData == null || declData.name == null) { - initStatus.addFatalError(Messages.HideMethodRefactoring_NoMethodNameSelected); - return initStatus; - } - - methodToHide = declData.name; - sm.worked(1); - methodToHideDecl = NodeHelper.findSimpleDeclarationInParents(methodToHide); - if(methodToHideDecl == null) { - initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); - return initStatus; - } - if(!(methodToHideDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier)) { - methodToHideDecl = NodeHelper.findFunctionDefinitionInAncestors(methodToHide); - } + try { + lockIndex(); + try { + super.checkInitialConditions(sm.newChild(6)); - if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; - sm.worked(1); - if(methodToHideDecl instanceof IASTFunctionDefinition) { - IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator(); - if(CPPVisitor.findInnermostDeclarator(declarator).getName().getRawSignature().equals(name.getRawSignature())) { - if (!(declarator instanceof IASTFunctionDeclarator)) { + if(initStatus.hasFatalError()){ + return initStatus; + } + + if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; + + IASTName name; + ArrayList names = findAllMarkedNames(); + if (names.size() < 1) { + initStatus.addFatalError(Messages.HideMethodRefactoring_NoNameSelected); + return initStatus; + } + name = names.get(names.size()-1); + sm.worked(1); + if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; + + declData = DeclarationFinder.getDeclaration(name, getIndex()); + + if(declData == null || declData.name == null) { + initStatus.addFatalError(Messages.HideMethodRefactoring_NoMethodNameSelected); + return initStatus; + } + + methodToHide = declData.name; + sm.worked(1); + methodToHideDecl = NodeHelper.findSimpleDeclarationInParents(methodToHide); + if(methodToHideDecl == null) { initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); return initStatus; } - } - }else if (methodToHideDecl instanceof IASTSimpleDeclaration) { - for(IASTDeclarator declarator : ((IASTSimpleDeclaration) methodToHideDecl).getDeclarators()) { - if(declarator.getName().getRawSignature().equals(name.getRawSignature())) { - if (!(declarator instanceof IASTFunctionDeclarator)) { - initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); - return initStatus; - } + if(!(methodToHideDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier)) { + methodToHideDecl = NodeHelper.findFunctionDefinitionInAncestors(methodToHide); } - } - }else { - initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); - return initStatus; - } - - sm.worked(1); - IASTCompositeTypeSpecifier classNode = NodeHelper.findClassInAncestors(methodToHide); - if(classNode == null) { - initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound); + if(isProgressMonitorCanceld(sm, initStatus)) return initStatus; + sm.worked(1); + if(methodToHideDecl instanceof IASTFunctionDefinition) { + IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator(); + if(CPPVisitor.findInnermostDeclarator(declarator).getName().getRawSignature().equals(name.getRawSignature())) { + if (!(declarator instanceof IASTFunctionDeclarator)) { + initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); + return initStatus; + } + } + }else if (methodToHideDecl instanceof IASTSimpleDeclaration) { + for(IASTDeclarator declarator : ((IASTSimpleDeclaration) methodToHideDecl).getDeclarators()) { + if(declarator.getName().getRawSignature().equals(name.getRawSignature())) { + if (!(declarator instanceof IASTFunctionDeclarator)) { + initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); + return initStatus; + } + } + } + }else { + initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods); + return initStatus; + } + + sm.worked(1); + + IASTCompositeTypeSpecifier classNode = NodeHelper.findClassInAncestors(methodToHide); + if(classNode == null) { + initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound); + } + + if(checkIfPrivate(classNode, methodToHideDecl)) { + initStatus.addError(Messages.HideMethodRefactoring_IsAlreadyPrivate); + } + sm.done(); + } + finally { + unlockIndex(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - - if(checkIfPrivate(classNode, methodToHideDecl)) { - initStatus.addError(Messages.HideMethodRefactoring_IsAlreadyPrivate); - } - sm.done(); return initStatus; } @@ -170,41 +187,54 @@ public class HideMethodRefactoring extends CRefactoring { @Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { - RefactoringStatus finalConditions = super.checkFinalConditions(pm); + RefactoringStatus finalConditions = null; + try { + lockIndex(); + try { + finalConditions = super.checkFinalConditions(pm); - for(IIndexName pdomref : declData.allNamesPDom) { - declData.filename = pdomref.getFileLocation().getFileName(); + for(IIndexName pdomref : declData.allNamesPDom) { + declData.filename = pdomref.getFileLocation().getFileName(); - if(pdomref instanceof PDOMName) { - PDOMName pdomName = (PDOMName)pdomref; - if(pdomName.isDeclaration()) { - continue; + if(pdomref instanceof PDOMName) { + PDOMName pdomName = (PDOMName)pdomref; + if(pdomName.isDeclaration()) { + continue; + } + if(pdomName.isDefinition()) { + continue; + } + } + + IASTTranslationUnit transUtmp = TranslationUnitHelper.loadTranslationUnit(declData.filename, false); + IASTName expName = ExpressionFinder.findExpressionInTranslationUnit(transUtmp, pdomref); + + IASTFunctionDeclarator funcDec = findEnclosingFunction(expName); + IASTCompositeTypeSpecifier encClass2; + if(funcDec == null) { + encClass2 = NodeHelper.findClassInAncestors(expName); + } + else { + encClass2 = NodeHelper.findClassInAncestors(funcDec); + } + + IASTCompositeTypeSpecifier encClass = NodeHelper.findClassInAncestors(methodToHide); + + if(!NodeHelper.isSameNode(encClass, encClass2)) { + finalConditions.addWarning(Messages.HideMethodRefactoring_HasExternalReferences); + break; + } } - if(pdomName.isDefinition()) { - continue; - } - } - - IASTTranslationUnit transUtmp = TranslationUnitHelper.loadTranslationUnit(declData.filename, false); - IASTName expName = ExpressionFinder.findExpressionInTranslationUnit(transUtmp, pdomref); - - IASTFunctionDeclarator funcDec = findEnclosingFunction(expName); - IASTCompositeTypeSpecifier encClass2; - if(funcDec == null) { - encClass2 = NodeHelper.findClassInAncestors(expName); - } - else { - encClass2 = NodeHelper.findClassInAncestors(funcDec); - } - - IASTCompositeTypeSpecifier encClass = NodeHelper.findClassInAncestors(methodToHide); - if(!NodeHelper.isSameNode(encClass, encClass2)) { - finalConditions.addWarning(Messages.HideMethodRefactoring_HasExternalReferences); - break; + return finalConditions; } + finally { + unlockIndex(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - return finalConditions; + return finalConditions; } private IASTFunctionDeclarator findEnclosingFunction(IASTNode node) throws CoreException { @@ -245,12 +275,36 @@ public class HideMethodRefactoring extends CRefactoring { @Override protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException { - ASTRewrite rewriter = collector.rewriterForTranslationUnit(declData.transUnit); - TextEditGroup editGroup = new TextEditGroup(Messages.HideMethodRefactoring_FILE_CHANGE_TEXT+ methodToHide.getRawSignature()); - - ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) methodToHideDecl.getParent(); - AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_private, methodToHideDecl, false, collector); + try { + lockIndex(); + try { + ASTRewrite rewriter = collector.rewriterForTranslationUnit(declData.transUnit); + TextEditGroup editGroup = new TextEditGroup(Messages.HideMethodRefactoring_FILE_CHANGE_TEXT+ methodToHide.getRawSignature()); - rewriter.remove(methodToHideDecl, editGroup); + ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) methodToHideDecl.getParent(); + AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_private, methodToHideDecl, false, collector); + + rewriter.remove(methodToHideDecl, editGroup); + } + finally { + unlockIndex(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + Map arguments = getArgumentMap(); + RefactoringDescriptor desc = new HideMethodRefactoringDescription( project.getProject().getName(), "Hide Method Refactoring", "Hide Method " + methodToHide.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$ + return arguments; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringContribution.java new file mode 100644 index 00000000000..ae1d979e5de --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringContribution.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.hidemethod; + +import java.util.Map; + +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; + +import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution; + +/** + * @author Emanuel Graf IFS + * + */ +public class HideMethodRefactoringContribution extends CRefactoringContribution { + + @SuppressWarnings("unchecked") + @Override + public RefactoringDescriptor createDescriptor(String id, String project, String description, + String comment, Map arguments, int flags) throws IllegalArgumentException { + if(id.equals(HideMethodRefactoring.ID)) { + return new HideMethodRefactoringDescription(project, description, comment, arguments); + }else { + return null; + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringDescription.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringDescription.java new file mode 100644 index 00000000000..b20cc696623 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringDescription.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 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 (IFS)- initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.hidemethod; + +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; + +/** + * @author Emanuel Graf IFS + * + */ +public class HideMethodRefactoringDescription extends CRefactoringDescription { + + public HideMethodRefactoringDescription(String project, String description, String comment, + Map arguments) { + super(HideMethodRefactoring.ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE, arguments); + } + + @Override + public Refactoring createRefactoring(RefactoringStatus status) throws CoreException { + IFile file; + ICProject proj; + + proj = getCProject(); + file = getFile(); + ISelection selection = getSelection(); + return new HideMethodRefactoring(file, selection, null, proj); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringRunner.java index 87ee6269072..d2f277d4f10 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringRunner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoringRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -12,13 +12,12 @@ package org.eclipse.cdt.internal.ui.refactoring.hidemethod; import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; 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.ui.CUIPlugin; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; @@ -29,29 +28,20 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; */ public class HideMethodRefactoringRunner extends RefactoringRunner { - public HideMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) { - super(file, selection, element, shellProvider); + public HideMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, element, shellProvider, cProject); } @Override public void run() { - CRefactoring refactoring= new HideMethodRefactoring(file, selection, celement); + CRefactoring refactoring= new HideMethodRefactoring(file, selection, celement, project); HideMethodRefactoringWizard wizard = new HideMethodRefactoringWizard(refactoring); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); - try { - refactoring.lockIndex(); - try { - operator.run(shellProvider.getShell(), refactoring.getName()); - } - finally { - refactoring.unlockIndex(); - } + operator.run(shellProvider.getShell(), refactoring.getName()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - } catch (CoreException e) { - CUIPlugin.log(e); - } + } } } 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 e78eeb0972c..499524bbfcf 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 @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.cdt.core.dom.ast.ASTVisitor; @@ -40,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; @@ -66,8 +68,8 @@ public class ImplementMethodRefactoring extends CRefactoring { private CPPASTFunctionDeclarator createdMethodDeclarator; private ImplementMethodData data; - public ImplementMethodRefactoring(IFile file, ISelection selection, ICElement element) { - super(file, selection, element); + public ImplementMethodRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) { + super(file, selection, element, project); data = new ImplementMethodData(); } @@ -246,4 +248,10 @@ public class ImplementMethodRefactoring extends CRefactoring { public ImplementMethodData getRefactoringData() { return data; } + + @Override + protected RefactoringDescriptor getRefactoringDescriptor() { + // TODO egraf add Descriptor + return null; + } } 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 a63ec8b646c..e205505fee9 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 Institute for Software, HSR Hochschule fuer Technik + * 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 @@ -18,6 +18,7 @@ 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.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; @@ -28,13 +29,13 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; */ public class ImplementMethodRefactoringRunner extends RefactoringRunner { - public ImplementMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) { - super(file, selection, element, shellProvider); + public ImplementMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) { + super(file, selection, element, shellProvider, cProject); } @Override public void run() { - ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(file, selection, celement); + ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(file, selection, celement, project); ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractConstantAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractConstantAction.java index 91af8e4ba77..0083a534c95 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractConstantAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractConstantAction.java @@ -41,7 +41,7 @@ public class ExtractConstantAction extends RefactoringAction { public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) { IResource res= wc.getResource(); if (res instanceof IFile) { - new ExtractConstantRefactoringRunner((IFile) res, selection, shellProvider).run(); + new ExtractConstantRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractFunctionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractFunctionAction.java index 96cd385eaaa..2d7d38e0d29 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractFunctionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractFunctionAction.java @@ -45,7 +45,7 @@ public class ExtractFunctionAction extends RefactoringAction { IResource res = wc.getResource(); if (res instanceof IFile) { final ISelection selection = fEditor.getSelectionProvider().getSelection(); - new ExtractFunctionRefactoringRunner((IFile) res, selection, fEditor.getSite()).run(); + new ExtractFunctionRefactoringRunner((IFile) res, selection, fEditor.getSite(), wc.getCProject()).run(); } } 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 7b2454245bc..f6386b22031 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 @@ -40,7 +40,7 @@ public class ExtractLocalVariableAction extends RefactoringAction { public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) { IResource res= wc.getResource(); if (res instanceof IFile) { - new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider).run(); + new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/GettersAndSettersAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/GettersAndSettersAction.java index 86e060473ba..1ea55ac0729 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/GettersAndSettersAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/GettersAndSettersAction.java @@ -45,14 +45,14 @@ public class GettersAndSettersAction extends RefactoringAction { @Override public void run(IShellProvider shellProvider, ICElement elem) { - new GenerateGettersAndSettersRefactoringRunner(null, null, elem, shellProvider).run(); + new GenerateGettersAndSettersRefactoringRunner(null, null, elem, shellProvider, elem.getCProject()).run(); } @Override public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s) { IResource res= wc.getResource(); if (res instanceof IFile) { - new GenerateGettersAndSettersRefactoringRunner((IFile) res, s, null, shellProvider).run(); + new GenerateGettersAndSettersRefactoringRunner((IFile) res, s, null, shellProvider, wc.getCProject()).run(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/HideMethodAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/HideMethodAction.java index 2008ad4d4cf..537c3f51dcb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/HideMethodAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/HideMethodAction.java @@ -38,7 +38,7 @@ public class HideMethodAction extends RefactoringAction { @Override public void run(IShellProvider shellProvider, ICElement elem) { if (elem instanceof ISourceReference) { - new HideMethodRefactoringRunner(null, null, elem, shellProvider).run(); + new HideMethodRefactoringRunner(null, null, elem, shellProvider, elem.getCProject()).run(); } } @@ -48,7 +48,7 @@ public class HideMethodAction extends RefactoringAction { if (res instanceof IFile) { new HideMethodRefactoringRunner((IFile) res, fEditor.getSelectionProvider().getSelection(), null, - fEditor.getSite().getWorkbenchWindow()).run(); + fEditor.getSite().getWorkbenchWindow(), wc.getCProject()).run(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ImplementMethodAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ImplementMethodAction.java index 636ac95ff2c..f20c30f6c9f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ImplementMethodAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ImplementMethodAction.java @@ -48,14 +48,14 @@ public class ImplementMethodAction extends RefactoringAction { @Override public void run(IShellProvider shellProvider, ICElement elem) { - new ImplementMethodRefactoringRunner(null, null, elem, shellProvider).run(); + new ImplementMethodRefactoringRunner(null, null, elem, shellProvider, elem.getCProject()).run(); } @Override public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) { IResource res = wc.getResource(); if (res instanceof IFile) { - new ImplementMethodRefactoringRunner((IFile) res, selection, null, shellProvider).run(); + new ImplementMethodRefactoringRunner((IFile) res, selection, null, shellProvider, wc.getCProject()).run(); } }