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:
parent
81ff9fe6a8
commit
3740766643
49 changed files with 1765 additions and 356 deletions
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -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.RefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantInfo;
|
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantInfo;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
|
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
|
@ -41,22 +42,16 @@ public class ExtractConstantRefactoringTest extends RefactoringTest {
|
||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
IFile refFile = project.getFile(fileName);
|
IFile refFile = project.getFile(fileName);
|
||||||
ExtractConstantInfo info = new ExtractConstantInfo();
|
ExtractConstantInfo info = new ExtractConstantInfo();
|
||||||
ExtractConstantRefactoring refactoring = new ExtractConstantRefactoring( refFile, selection, info);
|
CRefactoring refactoring = new ExtractConstantRefactoring(refFile, selection, info, cproject);
|
||||||
try {
|
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||||
refactoring.lockIndex();
|
assertConditionsOk(checkInitialConditions);
|
||||||
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
info.setName("theAnswer"); //$NON-NLS-1$
|
||||||
assertConditionsOk(checkInitialConditions);
|
info.setVisibility(visibility);
|
||||||
info.setName("theAnswer"); //$NON-NLS-1$
|
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||||
info.setVisibility(visibility);
|
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
assertConditionsOk(finalConditions);
|
||||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
createChange.perform(NULL_PROGRESS_MONITOR);
|
||||||
assertConditionsOk(finalConditions);
|
|
||||||
createChange.perform(NULL_PROGRESS_MONITOR);
|
|
||||||
}finally {
|
|
||||||
refactoring.unlockIndex();
|
|
||||||
}
|
|
||||||
compareFiles(fileMap);
|
compareFiles(fileMap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,6 +27,8 @@ public class ExtractConstantTestSuite extends TestSuite {
|
||||||
TestSuite suite = new ExtractConstantTestSuite();
|
TestSuite suite = new ExtractConstantTestSuite();
|
||||||
suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTest",
|
suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTest",
|
||||||
"resources/refactoring/ExtractConstant.rts"));
|
"resources/refactoring/ExtractConstant.rts"));
|
||||||
|
suite.addTest(RefactoringTester.suite("ExtractConstantHistoryRefactoringTest",
|
||||||
|
"resources/refactoring/ExtractConstantHistory.rts"));
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -40,6 +40,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
||||||
protected int returnParameterIndex;
|
protected int returnParameterIndex;
|
||||||
protected boolean fatalError;
|
protected boolean fatalError;
|
||||||
private VisibilityEnum visibility;
|
private VisibilityEnum visibility;
|
||||||
|
private static int nr = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -53,7 +54,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
IFile refFile = project.getFile(fileName);
|
IFile refFile = project.getFile(fileName);
|
||||||
ExtractFunctionInformation info = new ExtractFunctionInformation();
|
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);
|
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||||
|
|
||||||
if(fatalError){
|
if(fatalError){
|
||||||
|
@ -62,18 +63,28 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
assertConditionsOk(checkInitialConditions);
|
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.setMethodName(methodName);
|
||||||
info.setReplaceDuplicates(replaceDuplicates);
|
info.setReplaceDuplicates(replaceDuplicates);
|
||||||
if(info.getInScopeDeclaredVariable() == null){
|
if(info.getInScopeDeclaredVariable() == null){
|
||||||
if(returnValue) {
|
if(returnValue) {
|
||||||
info.setReturnVariable(info.getAllAfterUsedNames().get(returnParameterIndex));
|
info.setReturnVariable(info.getAllAfterUsedNames().get(returnParameterIndex));
|
||||||
|
info.getAllAfterUsedNames().get(returnParameterIndex).setUserSetIsReference(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info.setReturnVariable( info.getInScopeDeclaredVariable() );
|
info.setReturnVariable( info.getInScopeDeclaredVariable() );
|
||||||
|
@ -85,13 +96,6 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
||||||
name.setUserSetIsReference(name.isReference());
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -29,6 +29,7 @@ public class ExtractFunctionTestSuite extends TestSuite {
|
||||||
suite.addTest(RefactoringTester.suite("Extract Expression", "resources/refactoring/ExtractExpression.rts"));
|
suite.addTest(RefactoringTester.suite("Extract Expression", "resources/refactoring/ExtractExpression.rts"));
|
||||||
suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.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 Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts"));
|
||||||
|
suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts"));
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -43,7 +43,7 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTest {
|
||||||
IFile refFile = project.getFile(fileName);
|
IFile refFile = project.getFile(fileName);
|
||||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||||
info.setName(variableName);
|
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);
|
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||||
|
|
||||||
if(fatalError){
|
if(fatalError){
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -28,6 +28,8 @@ public class ExtractLocalVariableTestSuite extends TestSuite {
|
||||||
TestSuite suite = new ExtractLocalVariableTestSuite();
|
TestSuite suite = new ExtractLocalVariableTestSuite();
|
||||||
suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringTests",
|
suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringTests",
|
||||||
"resources/refactoring/ExtractLocalVariable.rts"));
|
"resources/refactoring/ExtractLocalVariable.rts"));
|
||||||
|
suite.addTest(RefactoringTester.suite("ExtractLocalVariableRefactoringHistoryTests",
|
||||||
|
"resources/refactoring/ExtractLocalVariableHistory.rts"));
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -52,7 +52,7 @@ public class GenerateGettersAndSettersTest extends RefactoringTest {
|
||||||
@Override
|
@Override
|
||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
IFile refFile = project.getFile(fileName);
|
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);
|
RefactoringStatus initialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -40,9 +40,7 @@ public class HideMethodRefactoringTest extends RefactoringTest {
|
||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
|
|
||||||
IFile refFile = project.getFile(fileWithSelection);
|
IFile refFile = project.getFile(fileWithSelection);
|
||||||
CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null);
|
CRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null, cproject);
|
||||||
try {
|
|
||||||
refactoring.lockIndex();
|
|
||||||
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||||
if(errors > 0) {
|
if(errors > 0) {
|
||||||
assertConditionsError(checkInitialConditions, errors);
|
assertConditionsError(checkInitialConditions, errors);
|
||||||
|
@ -52,7 +50,7 @@ public class HideMethodRefactoringTest extends RefactoringTest {
|
||||||
}else {
|
}else {
|
||||||
assertConditionsOk(checkInitialConditions);
|
assertConditionsOk(checkInitialConditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||||
if(warnings > 0){
|
if(warnings > 0){
|
||||||
|
@ -63,10 +61,6 @@ public class HideMethodRefactoringTest extends RefactoringTest {
|
||||||
createChange.perform(NULL_PROGRESS_MONITOR);
|
createChange.perform(NULL_PROGRESS_MONITOR);
|
||||||
|
|
||||||
compareFiles(fileMap);
|
compareFiles(fileMap);
|
||||||
}
|
|
||||||
finally {
|
|
||||||
refactoring.unlockIndex();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,6 +27,8 @@ public class HideMethodTestSuite extends TestSuite {
|
||||||
TestSuite suite = new HideMethodTestSuite();
|
TestSuite suite = new HideMethodTestSuite();
|
||||||
suite.addTest(RefactoringTester.suite("HideMethodRefactoringTests",
|
suite.addTest(RefactoringTester.suite("HideMethodRefactoringTests",
|
||||||
"resources/refactoring/HideMethod.rts"));
|
"resources/refactoring/HideMethod.rts"));
|
||||||
|
suite.addTest(RefactoringTester.suite("HideMethodRefactoringHistoryTests",
|
||||||
|
"resources/refactoring/HideMethodHistory.rts"));
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -42,7 +42,7 @@ public class ImplementMethodRefactoringTest extends RefactoringTest {
|
||||||
|
|
||||||
IFile refFile = project.getFile(fileName);
|
IFile refFile = project.getFile(fileName);
|
||||||
|
|
||||||
CRefactoring refactoring = new ImplementMethodRefactoring(refFile, selection, null);
|
CRefactoring refactoring = new ImplementMethodRefactoring(refFile, selection, null, cproject);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
refactoring.lockIndex();
|
refactoring.lockIndex();
|
||||||
|
|
|
@ -1221,7 +1221,10 @@
|
||||||
<separator name="typeGroup"/>
|
<separator name="typeGroup"/>
|
||||||
<separator name="typeGroup2"/>
|
<separator name="typeGroup2"/>
|
||||||
<separator name="codingGroup2"/>
|
<separator name="codingGroup2"/>
|
||||||
<separator name="typeGroup3"/>
|
<separator name="typeGroup3"/>
|
||||||
|
<separator
|
||||||
|
name="historyGroup">
|
||||||
|
</separator>
|
||||||
</menu>
|
</menu>
|
||||||
<!-- reorg group -->
|
<!-- reorg group -->
|
||||||
<action
|
<action
|
||||||
|
@ -1273,6 +1276,30 @@
|
||||||
id="org.eclipse.cdt.ui.actions.ImplementMethod"
|
id="org.eclipse.cdt.ui.actions.ImplementMethod"
|
||||||
retarget="true">
|
retarget="true">
|
||||||
</action>
|
</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
|
<menu
|
||||||
id="org.eclipse.jdt.ui.source.menu"
|
id="org.eclipse.jdt.ui.source.menu"
|
||||||
label="%Source.menu.label"
|
label="%Source.menu.label"
|
||||||
|
@ -3163,4 +3190,23 @@
|
||||||
</enabledWhen>
|
</enabledWhen>
|
||||||
</page>
|
</page>
|
||||||
</extension>
|
</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>
|
</plugin>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -23,6 +23,8 @@ import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.ltk.core.refactoring.Change;
|
import org.eclipse.ltk.core.refactoring.Change;
|
||||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -68,7 +70,10 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
protected IASTTranslationUnit unit;
|
protected IASTTranslationUnit unit;
|
||||||
private IIndex fIndex;
|
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) {
|
if (element instanceof ISourceReference) {
|
||||||
ISourceReference sourceRef= (ISourceReference) element;
|
ISourceReference sourceRef= (ISourceReference) element;
|
||||||
ITranslationUnit tu= sourceRef.getTranslationUnit();
|
ITranslationUnit tu= sourceRef.getTranslationUnit();
|
||||||
|
@ -207,9 +212,13 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
ModificationCollector collector = new ModificationCollector();
|
ModificationCollector collector = new ModificationCollector();
|
||||||
collectModifications(pm, collector);
|
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)
|
abstract protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||||
throws CoreException, OperationCanceledException;
|
throws CoreException, OperationCanceledException;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -18,7 +18,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.ltk.core.refactoring.Change;
|
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.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
|
@ -52,9 +51,9 @@ public class ModificationCollector {
|
||||||
changes.add(change);
|
changes.add(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompositeChange createFinalChange() {
|
public CCompositeChange createFinalChange() {
|
||||||
// Synthetic changes aren't displayed and therefore don't need a name
|
// 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();
|
result.markAsSynthetic();
|
||||||
|
|
||||||
if(changes != null)
|
if(changes != null)
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -16,6 +16,7 @@ import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all refactoring runners.
|
* Base class for all refactoring runners.
|
||||||
|
@ -29,12 +30,14 @@ public abstract class RefactoringRunner {
|
||||||
protected ISelection selection;
|
protected ISelection selection;
|
||||||
protected ICElement celement;
|
protected ICElement celement;
|
||||||
protected IShellProvider shellProvider;
|
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.file = file;
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
this.celement= element;
|
this.celement= element;
|
||||||
this.shellProvider= shellProvider;
|
this.shellProvider= shellProvider;
|
||||||
|
this.project = cProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void run();
|
public abstract void run();
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
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.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
import org.eclipse.text.edits.TextEditGroup;
|
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.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
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.CPPASTDeclarator;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
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.AddDeclarationNodeToClassChange;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
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.MethodContext;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
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 class ExtractConstantRefactoring extends CRefactoring {
|
||||||
|
|
||||||
|
public static final String ID = "org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring"; //$NON-NLS-1$
|
||||||
|
|
||||||
private IASTLiteralExpression target = null;
|
private IASTLiteralExpression target = null;
|
||||||
private final ArrayList<IASTExpression> literalsToReplace = new ArrayList<IASTExpression>();
|
private final ArrayList<IASTExpression> literalsToReplace = new ArrayList<IASTExpression>();
|
||||||
private final ExtractConstantInfo info;
|
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.info = info;
|
||||||
|
this.project = proj;
|
||||||
name = Messages.ExtractConstantRefactoring_ExtractConst;
|
name = Messages.ExtractConstantRefactoring_ExtractConst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
SubMonitor sm = SubMonitor.convert(pm, 9);
|
SubMonitor sm = SubMonitor.convert(pm, 9);
|
||||||
super.checkInitialConditions(sm.newChild(6));
|
try {
|
||||||
|
lockIndex();
|
||||||
|
try {
|
||||||
|
super.checkInitialConditions(sm.newChild(6));
|
||||||
|
|
||||||
Collection<IASTLiteralExpression> literalExpressionCollection = findAllLiterals();
|
Collection<IASTLiteralExpression> literalExpressionCollection = findAllLiterals();
|
||||||
if(literalExpressionCollection.isEmpty()){
|
if(literalExpressionCollection.isEmpty()){
|
||||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
sm.worked(1);
|
||||||
sm.worked(1);
|
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
|
||||||
|
boolean oneMarked = region != null && isOneMarked(literalExpressionCollection, region);
|
||||||
boolean oneMarked = region != null && isOneMarked(literalExpressionCollection, region);
|
if(!oneMarked){
|
||||||
if(!oneMarked){
|
//No or more than one marked
|
||||||
//No or more than one marked
|
if(target == null){
|
||||||
if(target == null){
|
//No Selection found;
|
||||||
//No Selection found;
|
initStatus.addFatalError(Messages.ExtractConstantRefactoring_NoLiteralSelected);
|
||||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_NoLiteralSelected);
|
} else {
|
||||||
} else {
|
//To many selection found
|
||||||
//To many selection found
|
initStatus.addFatalError(Messages.ExtractConstantRefactoring_TooManyLiteralSelected);
|
||||||
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;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,54 +271,79 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||||
throws CoreException, OperationCanceledException{
|
throws CoreException, OperationCanceledException{
|
||||||
|
try {
|
||||||
MethodContext context = info.getMContext();
|
lockIndex();
|
||||||
Collection<IASTExpression> locLiteralsToReplace = new ArrayList<IASTExpression>();
|
try {
|
||||||
|
MethodContext context = info.getMContext();
|
||||||
|
Collection<IASTExpression> locLiteralsToReplace = new ArrayList<IASTExpression>();
|
||||||
|
|
||||||
if(context.getType() == MethodContext.ContextType.METHOD){
|
if(context.getType() == MethodContext.ContextType.METHOD){
|
||||||
|
|
||||||
for (IASTExpression expression : literalsToReplace) {
|
for (IASTExpression expression : literalsToReplace) {
|
||||||
MethodContext exprContext = NodeHelper.findMethodContext(expression, getIndex());
|
MethodContext exprContext = NodeHelper.findMethodContext(expression, getIndex());
|
||||||
if(exprContext.getType() == MethodContext.ContextType.METHOD){
|
if(exprContext.getType() == MethodContext.ContextType.METHOD){
|
||||||
if(context.getMethodQName() != null) {
|
if(context.getMethodQName() != null) {
|
||||||
if( MethodContext.isSameClass(exprContext.getMethodQName(), context.getMethodQName())){
|
if( MethodContext.isSameClass(exprContext.getMethodQName(), context.getMethodQName())){
|
||||||
locLiteralsToReplace.add(expression);
|
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);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
} else {
|
unlockIndex();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
}
|
Thread.currentThread().interrupt();
|
||||||
|
|
||||||
//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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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) {
|
private void createLiteralToConstantChanges(String constName, Iterable<? extends IASTExpression> literals, ModificationCollector collector) {
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -12,12 +12,11 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
import org.eclipse.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.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class ExtractConstantRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) {
|
public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, null, shellProvider);
|
super(file, selection, null, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ExtractConstantInfo info = new ExtractConstantInfo();
|
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);
|
ExtractConstantRefactoringWizard wizard = new ExtractConstantRefactoringWizard(refactoring, info);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
refactoring.lockIndex();
|
operator.run(shellProvider.getShell(), refactoring.getName());
|
||||||
try {
|
|
||||||
operator.run(shellProvider.getShell(), refactoring.getName());
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
refactoring.unlockIndex();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (CoreException e) {
|
}
|
||||||
CUIPlugin.log(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,6 @@ public class ChooserComposite extends Composite {
|
||||||
|
|
||||||
boolean hasNoPredefinedReturnValue = true;
|
boolean hasNoPredefinedReturnValue = true;
|
||||||
if (info.getInScopeDeclaredVariable() != null) {
|
if (info.getInScopeDeclaredVariable() != null) {
|
||||||
info.getInScopeDeclaredVariable().setUserSetIsReturnValue(true);
|
|
||||||
hasNoPredefinedReturnValue = false;
|
hasNoPredefinedReturnValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.SubMonitor;
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
import org.eclipse.text.edits.TextEditGroup;
|
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.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
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.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression;
|
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.AddDeclarationNodeToClassChange;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
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.Container;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
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;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||||
|
|
||||||
public class ExtractFunctionRefactoring extends CRefactoring {
|
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 Integer NULL_INTEGER = Integer.valueOf(0);
|
||||||
static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$
|
static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$
|
||||||
|
@ -127,8 +132,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
private INodeFactory factory = CPPNodeFactory.getDefault();
|
private INodeFactory factory = CPPNodeFactory.getDefault();
|
||||||
|
|
||||||
public ExtractFunctionRefactoring(IFile file, ISelection selection,
|
public ExtractFunctionRefactoring(IFile file, ISelection selection,
|
||||||
ExtractFunctionInformation info) {
|
ExtractFunctionInformation info, ICProject project) {
|
||||||
super(file, selection, null);
|
super(file, selection, null, project);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
name = Messages.ExtractFunctionRefactoring_ExtractFunction;
|
name = Messages.ExtractFunctionRefactoring_ExtractFunction;
|
||||||
names = new HashMap<String, Integer>();
|
names = new HashMap<String, Integer>();
|
||||||
|
@ -166,15 +171,13 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
info.setAllUsedNames(container.getUsedNamesUnique());
|
info.setAllUsedNames(container.getUsedNamesUnique());
|
||||||
|
|
||||||
if (container.size() < 1) {
|
if (container.size() < 1) {
|
||||||
status
|
status.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
|
||||||
.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
|
|
||||||
sm.done();
|
sm.done();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container.getAllDeclaredInScope().size() > 1) {
|
if (container.getAllDeclaredInScope().size() > 1) {
|
||||||
status
|
status.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
|
||||||
.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
|
|
||||||
} else if (container.getAllDeclaredInScope().size() == 1) {
|
} else if (container.getAllDeclaredInScope().size() == 1) {
|
||||||
info.setInScopeDeclaredVariable(container.getAllDeclaredInScope().get(0));
|
info.setInScopeDeclaredVariable(container.getAllDeclaredInScope().get(0));
|
||||||
}
|
}
|
||||||
|
@ -188,6 +191,19 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0)));
|
info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0)));
|
||||||
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
|
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
|
||||||
info.setMethodContext(context);
|
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();
|
sm.done();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -212,12 +228,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
for (IASTNode node : cont.getNodesToWrite()) {
|
for (IASTNode node : cont.getNodesToWrite()) {
|
||||||
node.accept(vis);
|
node.accept(vis);
|
||||||
if (vis.containsContinue()) {
|
if (vis.containsContinue()) {
|
||||||
initStatus
|
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Continue);
|
||||||
.addFatalError(Messages.ExtractFunctionRefactoring_Error_Continue);
|
|
||||||
break;
|
break;
|
||||||
} else if (vis.containsBreak()) {
|
} else if (vis.containsBreak()) {
|
||||||
initStatus
|
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Break);
|
||||||
.addFatalError(Messages.ExtractFunctionRefactoring_Error_Break);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,8 +240,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
for (IASTNode node : cont.getNodesToWrite()) {
|
for (IASTNode node : cont.getNodesToWrite()) {
|
||||||
node.accept(rFinder);
|
node.accept(rFinder);
|
||||||
if (rFinder.containsReturn()) {
|
if (rFinder.containsReturn()) {
|
||||||
initStatus
|
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_Error_Return);
|
||||||
.addFatalError(Messages.ExtractFunctionRefactoring_Error_Return);
|
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -16,6 +16,8 @@ import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
import org.eclipse.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.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class ExtractFunctionRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public ExtractFunctionRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) {
|
public ExtractFunctionRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, null, shellProvider);
|
super(file, selection, null, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ExtractFunctionInformation info = new ExtractFunctionInformation();
|
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);
|
ExtractFunctionRefactoringWizard wizard = new ExtractFunctionRefactoringWizard(refactoring,info);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
||||||
|
|
|
@ -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
|
* the accompanying materials are made available under the terms of the Eclipse
|
||||||
* Public License v1.0 which accompanies this distribution, and is available at
|
* Public License v1.0 which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
@ -11,7 +11,9 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
import org.eclipse.text.edits.TextEditGroup;
|
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.CPPASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
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.CPPASTDeclarationStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
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.core.dom.parser.cpp.CPPFunction;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
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.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NodeContainer;
|
import org.eclipse.cdt.internal.ui.refactoring.NodeContainer;
|
||||||
|
@ -71,61 +76,73 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||||
* @author Tom Ball
|
* @author Tom Ball
|
||||||
*/
|
*/
|
||||||
public class ExtractLocalVariableRefactoring extends CRefactoring {
|
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 IASTExpression target = null;
|
||||||
private final NameNVisibilityInformation info;
|
private final NameNVisibilityInformation info;
|
||||||
private NodeContainer container;
|
private NodeContainer container;
|
||||||
|
|
||||||
public ExtractLocalVariableRefactoring(IFile file, ISelection selection,
|
public ExtractLocalVariableRefactoring(IFile file, ISelection selection,
|
||||||
NameNVisibilityInformation info) {
|
NameNVisibilityInformation info, ICProject project) {
|
||||||
super(file, selection, null);
|
super(file, selection, null, project);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
name = Messages.ExtractLocalVariable;
|
name = Messages.ExtractLocalVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
||||||
throws CoreException, OperationCanceledException {
|
throws CoreException, OperationCanceledException {
|
||||||
SubMonitor sm = SubMonitor.convert(pm, 9);
|
SubMonitor sm = SubMonitor.convert(pm, 9);
|
||||||
super.checkInitialConditions(sm.newChild(6));
|
try {
|
||||||
|
lockIndex();
|
||||||
|
try {
|
||||||
|
super.checkInitialConditions(sm.newChild(6));
|
||||||
|
|
||||||
container = findAllExpressions();
|
container = findAllExpressions();
|
||||||
if (container.size() < 1) {
|
if (container.size() < 1) {
|
||||||
initStatus.addFatalError(Messages.ExpressionMustBeSelected);
|
initStatus.addFatalError(Messages.ExpressionMustBeSelected);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.worked(1);
|
sm.worked(1);
|
||||||
if (isProgressMonitorCanceld(sm, initStatus))
|
if (isProgressMonitorCanceld(sm, initStatus))
|
||||||
return initStatus;
|
return initStatus;
|
||||||
|
|
||||||
boolean oneMarked = region != null
|
boolean oneMarked = region != null
|
||||||
&& isOneMarked(container.getNodesToWrite(), region);
|
&& isOneMarked(container.getNodesToWrite(), region);
|
||||||
if (!oneMarked) {
|
if (!oneMarked) {
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
initStatus.addFatalError(Messages.NoExpressionSelected);
|
initStatus.addFatalError(Messages.NoExpressionSelected);
|
||||||
} else {
|
} else {
|
||||||
initStatus.addFatalError(Messages.TooManyExpressionsSelected);
|
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;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,22 +257,31 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
||||||
protected void collectModifications(IProgressMonitor pm,
|
protected void collectModifications(IProgressMonitor pm,
|
||||||
ModificationCollector collector) throws CoreException,
|
ModificationCollector collector) throws CoreException,
|
||||||
OperationCanceledException {
|
OperationCanceledException {
|
||||||
String variableName = info.getName();
|
try {
|
||||||
TextEditGroup editGroup = new TextEditGroup(
|
lockIndex();
|
||||||
Messages.CreateLocalVariable);
|
try {
|
||||||
|
String variableName = info.getName();
|
||||||
|
TextEditGroup editGroup = new TextEditGroup(
|
||||||
|
Messages.CreateLocalVariable);
|
||||||
|
|
||||||
// Define temporary variable declaration and insert it
|
// Define temporary variable declaration and insert it
|
||||||
IASTStatement declInsertPoint = getParentStatement(target);
|
IASTStatement declInsertPoint = getParentStatement(target);
|
||||||
IASTDeclarationStatement declaration = getVariableNodes(variableName);
|
IASTDeclarationStatement declaration = getVariableNodes(variableName);
|
||||||
declaration.setParent(declInsertPoint.getParent());
|
declaration.setParent(declInsertPoint.getParent());
|
||||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||||
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint,
|
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint,
|
||||||
declaration, editGroup);
|
declaration, editGroup);
|
||||||
|
|
||||||
// Replace target with reference to temporary variable
|
// Replace target with reference to temporary variable
|
||||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(
|
CPPASTIdExpression idExpression = new CPPASTIdExpression(
|
||||||
new CPPASTName(variableName.toCharArray()));
|
new CPPASTName(variableName.toCharArray()));
|
||||||
rewriter.replace(target, idExpression, editGroup);
|
rewriter.replace(target, idExpression, editGroup);
|
||||||
|
}finally {
|
||||||
|
unlockIndex();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTStatement getParentStatement(IASTNode node) {
|
private IASTStatement getParentStatement(IASTNode node) {
|
||||||
|
@ -430,4 +456,19 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
||||||
}
|
}
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -16,6 +16,8 @@ import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
import org.eclipse.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.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class ExtractLocalVariableRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public ExtractLocalVariableRefactoringRunner(IFile file,
|
public ExtractLocalVariableRefactoringRunner(IFile file,
|
||||||
ISelection selection, IShellProvider shellProvider) {
|
ISelection selection, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, null, shellProvider);
|
super(file, selection, null, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||||
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file,
|
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file,
|
||||||
selection, info);
|
selection, info, project);
|
||||||
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
|
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
|
||||||
refactoring, info);
|
refactoring, info);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -20,6 +20,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.SubMonitor;
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
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.CPPASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
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 static final String MEMBER_DECLARATION = "MEMBER_DECLARATION"; //$NON-NLS-1$
|
||||||
private final GetterAndSetterContext context = new GetterAndSetterContext();
|
private final GetterAndSetterContext context = new GetterAndSetterContext();
|
||||||
|
|
||||||
public GenerateGettersAndSettersRefactoring(IFile file, ISelection selection, ICElement element) {
|
public GenerateGettersAndSettersRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) {
|
||||||
super(file, selection, element);
|
super(file, selection, element, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,5 +197,11 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
||||||
|
|
||||||
public Region getRegion() {
|
public Region getRegion() {
|
||||||
return region;
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RefactoringDescriptor getRefactoringDescriptor() {
|
||||||
|
// TODO egraf add Descriptor
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -19,6 +19,7 @@ import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class GenerateGettersAndSettersRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public GenerateGettersAndSettersRefactoringRunner(IFile file, ISelection selection, ICElement elem, IShellProvider shellProvider) {
|
public GenerateGettersAndSettersRefactoringRunner(IFile file, ISelection selection, ICElement elem, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, elem, shellProvider);
|
super(file, selection, elem, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof ITextEditor) {
|
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);
|
GenerateGettersAndSettersRefactoringWizard wizard = new GenerateGettersAndSettersRefactoringWizard(refactoring);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -12,6 +12,8 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.SubMonitor;
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
import org.eclipse.text.edits.TextEditGroup;
|
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.dom.rewrite.ASTRewrite;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
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.core.pdom.dom.PDOMName;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
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.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.DeclarationFinder;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.DeclarationFinder;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.DeclarationFinderDO;
|
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 class HideMethodRefactoring extends CRefactoring {
|
||||||
|
|
||||||
|
public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring"; //$NON-NLS-1$
|
||||||
|
|
||||||
private IASTName methodToHide;
|
private IASTName methodToHide;
|
||||||
private IASTDeclaration methodToHideDecl;
|
private IASTDeclaration methodToHideDecl;
|
||||||
private DeclarationFinderDO declData;
|
private DeclarationFinderDO declData;
|
||||||
|
|
||||||
public HideMethodRefactoring(IFile file, ISelection selection, ICElement element) {
|
public HideMethodRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) {
|
||||||
super(file, selection, element);
|
super(file, selection, element, project);
|
||||||
name = Messages.HideMethodRefactoring_HIDE_METHOD;
|
name = Messages.HideMethodRefactoring_HIDE_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||||
super.checkInitialConditions(sm.newChild(6));
|
try {
|
||||||
|
lockIndex();
|
||||||
if(initStatus.hasFatalError()){
|
try {
|
||||||
return initStatus;
|
super.checkInitialConditions(sm.newChild(6));
|
||||||
}
|
|
||||||
|
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
|
||||||
|
|
||||||
IASTName name;
|
|
||||||
ArrayList<IASTName> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
if(initStatus.hasFatalError()){
|
||||||
sm.worked(1);
|
return initStatus;
|
||||||
if(methodToHideDecl instanceof IASTFunctionDefinition) {
|
}
|
||||||
IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator();
|
|
||||||
if(CPPVisitor.findInnermostDeclarator(declarator).getName().getRawSignature().equals(name.getRawSignature())) {
|
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||||
if (!(declarator instanceof IASTFunctionDeclarator)) {
|
|
||||||
|
IASTName name;
|
||||||
|
ArrayList<IASTName> 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);
|
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
}
|
if(!(methodToHideDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier)) {
|
||||||
}else if (methodToHideDecl instanceof IASTSimpleDeclaration) {
|
methodToHideDecl = NodeHelper.findFunctionDefinitionInAncestors(methodToHide);
|
||||||
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(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||||
if(classNode == null) {
|
sm.worked(1);
|
||||||
initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound);
|
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;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,41 +187,54 @@ public class HideMethodRefactoring extends CRefactoring {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
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) {
|
for(IIndexName pdomref : declData.allNamesPDom) {
|
||||||
declData.filename = pdomref.getFileLocation().getFileName();
|
declData.filename = pdomref.getFileLocation().getFileName();
|
||||||
|
|
||||||
if(pdomref instanceof PDOMName) {
|
if(pdomref instanceof PDOMName) {
|
||||||
PDOMName pdomName = (PDOMName)pdomref;
|
PDOMName pdomName = (PDOMName)pdomref;
|
||||||
if(pdomName.isDeclaration()) {
|
if(pdomName.isDeclaration()) {
|
||||||
continue;
|
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)) {
|
return finalConditions;
|
||||||
finalConditions.addWarning(Messages.HideMethodRefactoring_HasExternalReferences);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
unlockIndex();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
return finalConditions;
|
return finalConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTFunctionDeclarator findEnclosingFunction(IASTNode node) throws CoreException {
|
private IASTFunctionDeclarator findEnclosingFunction(IASTNode node) throws CoreException {
|
||||||
|
@ -245,12 +275,36 @@ public class HideMethodRefactoring extends CRefactoring {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
|
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
|
||||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(declData.transUnit);
|
try {
|
||||||
TextEditGroup editGroup = new TextEditGroup(Messages.HideMethodRefactoring_FILE_CHANGE_TEXT+ methodToHide.getRawSignature());
|
lockIndex();
|
||||||
|
try {
|
||||||
ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) methodToHideDecl.getParent();
|
ASTRewrite rewriter = collector.rewriterForTranslationUnit(declData.transUnit);
|
||||||
AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_private, methodToHideDecl, false, collector);
|
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<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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -12,13 +12,12 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class HideMethodRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public HideMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) {
|
public HideMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, element, shellProvider);
|
super(file, selection, element, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
CRefactoring refactoring= new HideMethodRefactoring(file, selection, celement);
|
CRefactoring refactoring= new HideMethodRefactoring(file, selection, celement, project);
|
||||||
HideMethodRefactoringWizard wizard = new HideMethodRefactoringWizard(refactoring);
|
HideMethodRefactoringWizard wizard = new HideMethodRefactoringWizard(refactoring);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
refactoring.lockIndex();
|
operator.run(shellProvider.getShell(), refactoring.getName());
|
||||||
try {
|
|
||||||
operator.run(shellProvider.getShell(), refactoring.getName());
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
refactoring.unlockIndex();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (CoreException e) {
|
}
|
||||||
CUIPlugin.log(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.SubMonitor;
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
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.ast.cpp.ICPPASTTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||||
|
@ -66,8 +68,8 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
||||||
private CPPASTFunctionDeclarator createdMethodDeclarator;
|
private CPPASTFunctionDeclarator createdMethodDeclarator;
|
||||||
private ImplementMethodData data;
|
private ImplementMethodData data;
|
||||||
|
|
||||||
public ImplementMethodRefactoring(IFile file, ISelection selection, ICElement element) {
|
public ImplementMethodRefactoring(IFile file, ISelection selection, ICElement element, ICProject project) {
|
||||||
super(file, selection, element);
|
super(file, selection, element, project);
|
||||||
data = new ImplementMethodData();
|
data = new ImplementMethodData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,4 +248,10 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
||||||
public ImplementMethodData getRefactoringData() {
|
public ImplementMethodData getRefactoringData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RefactoringDescriptor getRefactoringDescriptor() {
|
||||||
|
// TODO egraf add Descriptor
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -18,6 +18,7 @@ import org.eclipse.jface.window.IShellProvider;
|
||||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
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 class ImplementMethodRefactoringRunner extends RefactoringRunner {
|
||||||
|
|
||||||
public ImplementMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) {
|
public ImplementMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) {
|
||||||
super(file, selection, element, shellProvider);
|
super(file, selection, element, shellProvider, cProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(file, selection, celement);
|
ImplementMethodRefactoring refactoring = new ImplementMethodRefactoring(file, selection, celement, project);
|
||||||
ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring);
|
ImplementMethodRefactoringWizard wizard = new ImplementMethodRefactoringWizard(refactoring);
|
||||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ExtractConstantAction extends RefactoringAction {
|
||||||
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
||||||
IResource res= wc.getResource();
|
IResource res= wc.getResource();
|
||||||
if (res instanceof IFile) {
|
if (res instanceof IFile) {
|
||||||
new ExtractConstantRefactoringRunner((IFile) res, selection, shellProvider).run();
|
new ExtractConstantRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ExtractFunctionAction extends RefactoringAction {
|
||||||
IResource res = wc.getResource();
|
IResource res = wc.getResource();
|
||||||
if (res instanceof IFile) {
|
if (res instanceof IFile) {
|
||||||
final ISelection selection = fEditor.getSelectionProvider().getSelection();
|
final ISelection selection = fEditor.getSelectionProvider().getSelection();
|
||||||
new ExtractFunctionRefactoringRunner((IFile) res, selection, fEditor.getSite()).run();
|
new ExtractFunctionRefactoringRunner((IFile) res, selection, fEditor.getSite(), wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ExtractLocalVariableAction extends RefactoringAction {
|
||||||
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
||||||
IResource res= wc.getResource();
|
IResource res= wc.getResource();
|
||||||
if (res instanceof IFile) {
|
if (res instanceof IFile) {
|
||||||
new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider).run();
|
new ExtractLocalVariableRefactoringRunner((IFile) res, selection, shellProvider, wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,14 +45,14 @@ public class GettersAndSettersAction extends RefactoringAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IShellProvider shellProvider, ICElement elem) {
|
public void run(IShellProvider shellProvider, ICElement elem) {
|
||||||
new GenerateGettersAndSettersRefactoringRunner(null, null, elem, shellProvider).run();
|
new GenerateGettersAndSettersRefactoringRunner(null, null, elem, shellProvider, elem.getCProject()).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s) {
|
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s) {
|
||||||
IResource res= wc.getResource();
|
IResource res= wc.getResource();
|
||||||
if (res instanceof IFile) {
|
if (res instanceof IFile) {
|
||||||
new GenerateGettersAndSettersRefactoringRunner((IFile) res, s, null, shellProvider).run();
|
new GenerateGettersAndSettersRefactoringRunner((IFile) res, s, null, shellProvider, wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class HideMethodAction extends RefactoringAction {
|
||||||
@Override
|
@Override
|
||||||
public void run(IShellProvider shellProvider, ICElement elem) {
|
public void run(IShellProvider shellProvider, ICElement elem) {
|
||||||
if (elem instanceof ISourceReference) {
|
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) {
|
if (res instanceof IFile) {
|
||||||
new HideMethodRefactoringRunner((IFile) res,
|
new HideMethodRefactoringRunner((IFile) res,
|
||||||
fEditor.getSelectionProvider().getSelection(), null,
|
fEditor.getSelectionProvider().getSelection(), null,
|
||||||
fEditor.getSite().getWorkbenchWindow()).run();
|
fEditor.getSite().getWorkbenchWindow(), wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,14 +48,14 @@ public class ImplementMethodAction extends RefactoringAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IShellProvider shellProvider, ICElement elem) {
|
public void run(IShellProvider shellProvider, ICElement elem) {
|
||||||
new ImplementMethodRefactoringRunner(null, null, elem, shellProvider).run();
|
new ImplementMethodRefactoringRunner(null, null, elem, shellProvider, elem.getCProject()).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection selection) {
|
||||||
IResource res = wc.getResource();
|
IResource res = wc.getResource();
|
||||||
if (res instanceof IFile) {
|
if (res instanceof IFile) {
|
||||||
new ImplementMethodRefactoringRunner((IFile) res, selection, null, shellProvider).run();
|
new ImplementMethodRefactoringRunner((IFile) res, selection, null, shellProvider, wc.getCProject()).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue