1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

FIXED - bug 282843: Create a Refactoring-History for the CDT Refactorings

https://bugs.eclipse.org/bugs/show_bug.cgi?id=282843
This commit is contained in:
Emanuel Graf 2009-07-09 07:55:53 +00:00
parent 81ff9fe6a8
commit 3740766643
49 changed files with 1765 additions and 356 deletions

View file

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

View file

@ -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
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Extract 5 + 2" description="Extract Local Variable Refactoring"
fileName="file:$$projectPath$$/main.cpp" flags="4"
id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"
name="i" project="RegressionTestProject" selection="25,5"/>
</session>

View file

@ -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
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/A.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="56,25" visibility="private"/>
</session>
//!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
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/A.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="79,13" visibility="private"/>
</session>
//!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
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/main.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="35,5" visibility="private"/>
</session>
//!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
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/main.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="23,5" visibility="private"/>
</session>

View file

@ -0,0 +1,44 @@
//!HideMethodSimple
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@A.h
#ifndef A_H_
#define A_H_
#include <iostream>
class A{
public:
A();
void method2();
std::string toString();
private:
int i;
};
#endif /*A_H_*/
//=
#ifndef A_H_
#define A_H_
#include <iostream>
class A{
public:
A();
std::string toString();
private:
int i;
void method2();
};
#endif /*A_H_*/
//@refScript.xml
<?xml version="1.0" encoding="UTF-8"?>
<session version="1.0">
<refactoring comment="Hide Method method2" description="Hide Method Refactoring"
fileName="file:$$projectPath$$/A.h" flags="2"
id="org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring"
project="RegressionTestProject" selection="83,7"/>
</session>

View file

@ -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<TestSourceFile> 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);
}
}
}
}

View file

@ -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,9 +42,7 @@ 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();
CRefactoring refactoring = new ExtractConstantRefactoring(refFile, selection, info, cproject);
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(checkInitialConditions);
info.setName("theAnswer"); //$NON-NLS-1$
@ -52,11 +51,7 @@ public class ExtractConstantRefactoringTest extends RefactoringTest {
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
assertConditionsOk(finalConditions);
createChange.perform(NULL_PROGRESS_MONITOR);
}finally {
refactoring.unlockIndex();
}
compareFiles(fileMap);
}
@Override

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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){

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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);
@ -64,10 +62,6 @@ public class HideMethodRefactoringTest extends RefactoringTest {
compareFiles(fileMap);
}
finally {
refactoring.unlockIndex();
}
}
@Override
protected void configureRefactoring(Properties refactoringProperties) {

View file

@ -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;
}
}

View file

@ -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();

View file

@ -1222,6 +1222,9 @@
<separator name="typeGroup2"/>
<separator name="codingGroup2"/>
<separator name="typeGroup3"/>
<separator
name="historyGroup">
</separator>
</menu>
<!-- reorg group -->
<action
@ -1273,6 +1276,30 @@
id="org.eclipse.cdt.ui.actions.ImplementMethod"
retarget="true">
</action>
<action
class="org.eclipse.ltk.ui.refactoring.actions.ShowRefactoringHistoryAction"
definitionId="org.eclipse.ltk.ui.refactor.show.refactoring.history"
id="org.eclipse.cdt.ui.actions.RefactoringHistory"
label="History..."
menubarPath="org.eclipse.jdt.ui.refactoring.menu/historyGroup"
retarget="false">
</action>
<action
class="org.eclipse.ltk.ui.refactoring.actions.CreateRefactoringScriptAction"
definitionId="org.eclipse.ltk.ui.refactor.create.refactoring.script"
id="org.eclipse.cdt.ui.actions.createRefactoringScript"
label="Create Script..."
menubarPath="org.eclipse.jdt.ui.refactoring.menu/historyGroup"
retarget="false">
</action>
<action
class="org.eclipse.ltk.ui.refactoring.actions.ApplyRefactoringScriptAction"
definitionId="org.eclipse.ltk.ui.refactor.apply.refactoring.script"
id="org.eclipse.cdt.ui.actions.applyRefactoringScript"
label="Apply Script..."
menubarPath="org.eclipse.jdt.ui.refactoring.menu/historyGroup"
retarget="false">
</action>
<menu
id="org.eclipse.jdt.ui.source.menu"
label="%Source.menu.label"
@ -3163,4 +3190,23 @@
</enabledWhen>
</page>
</extension>
<extension
point="org.eclipse.ltk.core.refactoring.refactoringContributions">
<contribution
class="org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoringContribution"
id="org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring">
</contribution>
<contribution
class="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringContribution"
id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring">
</contribution>
<contribution
class="org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoringContribution"
id="org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring">
</contribution>
<contribution
class="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoringContribution"
id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring">
</contribution>
</extension>
</plugin>

View file

@ -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;
}
}
}

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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<String, String> arguments;
public CRefactoringDescription(String id, String project, String description, String comment, int flags, Map<String, String> arguments) {
super(id, project, description, comment, flags);
this.arguments = arguments;
}
public Map<String, String> 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;
}
}

View file

@ -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)

View file

@ -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();

View file

@ -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,19 +79,26 @@ 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<IASTExpression> literalsToReplace = new ArrayList<IASTExpression>();
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);
try {
lockIndex();
try {
super.checkInitialConditions(sm.newChild(6));
Collection<IASTLiteralExpression> literalExpressionCollection = findAllLiterals();
@ -94,7 +106,6 @@ public class ExtractConstantRefactoring extends CRefactoring {
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
return initStatus;
}
sm.worked(1);
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
@ -117,9 +128,18 @@ public class ExtractConstantRefactoring extends CRefactoring {
findAllNodesForReplacement(literalExpressionCollection);
info.addNamesToUsedNames(findAllDeclaredNames());
if(info.getName().length() == 0) {
info.setName(getDefaultName(target));
}
info.setMContext(NodeHelper.findMethodContext(target, getIndex()));
sm.done();
}
finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return initStatus;
}
@ -252,7 +272,9 @@ public class ExtractConstantRefactoring extends CRefactoring {
@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException{
try {
lockIndex();
try {
MethodContext context = info.getMContext();
Collection<IASTExpression> locLiteralsToReplace = new ArrayList<IASTExpression>();
@ -299,6 +321,29 @@ public class ExtractConstantRefactoring extends CRefactoring {
rewriter.insertBefore(unit, TranslationUnitHelper.getFirstNode(unit), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant));
}
}
finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> 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<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractConstantRefactoringDescription.NAME, info.getName());
arguments.put(ExtractConstantRefactoringDescription.VISIBILITY, info.getVisibility().toString());
return arguments;
}
private void createLiteralToConstantChanges(String constName, Iterable<? extends IASTExpression> literals, ModificationCollector collector) {

View file

@ -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;
}
}
}

View file

@ -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<String, String> 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);
}
}

View file

@ -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();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (CoreException e) {
CUIPlugin.log(e);
}
}
}

View file

@ -54,7 +54,6 @@ public class ChooserComposite extends Composite {
boolean hasNoPredefinedReturnValue = true;
if (info.getInScopeDeclaredVariable() != null) {
info.getInScopeDeclaredVariable().setUserSetIsReturnValue(true);
hasNoPredefinedReturnValue = false;
}

View file

@ -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;
@ -107,6 +110,8 @@ 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<String, Integer>();
@ -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<String, String> 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<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractFunctionRefactoringDescription.NAME, info.getMethodName());
arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY, info.getVisibility().toString());
return arguments;
}
}

View file

@ -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;
}
}
}

View file

@ -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<String, String> 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);
}
}

View file

@ -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);

View file

@ -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,13 +76,16 @@ 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;
}
@ -86,6 +94,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException {
SubMonitor sm = SubMonitor.convert(pm, 9);
try {
lockIndex();
try {
super.checkInitialConditions(sm.newChild(6));
container = findAllExpressions();
@ -126,6 +137,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
info.setName(guessTempName());
sm.done();
}finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return initStatus;
}
@ -240,6 +257,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
protected void collectModifications(IProgressMonitor pm,
ModificationCollector collector) throws CoreException,
OperationCanceledException {
try {
lockIndex();
try {
String variableName = info.getName();
TextEditGroup editGroup = new TextEditGroup(
Messages.CreateLocalVariable);
@ -256,6 +276,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
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<String, String> 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<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractLocalVariableRefactoringDescription.NAME, info.getName());
return arguments;
}
}

View file

@ -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;
}
}
}

View file

@ -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<String, String> 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);
}
}

View file

@ -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);

View file

@ -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
@ -196,4 +198,10 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
public Region getRegion() {
return region;
}
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
// TODO egraf add Descriptor
return null;
}
}

View file

@ -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);

View file

@ -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;
@ -58,18 +63,23 @@ 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);
try {
lockIndex();
try {
super.checkInitialConditions(sm.newChild(6));
if(initStatus.hasFatalError()){
@ -141,6 +151,13 @@ public class HideMethodRefactoring extends CRefactoring {
initStatus.addError(Messages.HideMethodRefactoring_IsAlreadyPrivate);
}
sm.done();
}
finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return initStatus;
}
@ -170,7 +187,11 @@ 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();
@ -204,6 +225,15 @@ public class HideMethodRefactoring extends CRefactoring {
break;
}
}
return finalConditions;
}
finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return finalConditions;
}
@ -245,6 +275,9 @@ public class HideMethodRefactoring extends CRefactoring {
@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
try {
lockIndex();
try {
ASTRewrite rewriter = collector.rewriterForTranslationUnit(declData.transUnit);
TextEditGroup editGroup = new TextEditGroup(Messages.HideMethodRefactoring_FILE_CHANGE_TEXT+ methodToHide.getRawSignature());
@ -253,4 +286,25 @@ public class HideMethodRefactoring extends CRefactoring {
rewriter.remove(methodToHideDecl, editGroup);
}
finally {
unlockIndex();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> 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<String, String> getArgumentMap() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
return arguments;
}
}

View file

@ -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;
}
}
}

View file

@ -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<String, String> 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);
}
}

View file

@ -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();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (CoreException e) {
CUIPlugin.log(e);
}
}
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}