mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 03:35:37 +02:00
Hide Method (work in progress) by Emanuel Graf, bug 226533.
This commit is contained in:
parent
ca61147d16
commit
d353a33638
24 changed files with 1432 additions and 69 deletions
|
@ -0,0 +1,845 @@
|
|||
//!HideMethodChangeToDefaultVisibility
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
//$void method2();$//
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
private:
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodSimple
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@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_*/
|
||||
|
||||
//!HideMethodLineComment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//Kommentar
|
||||
//$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;
|
||||
//Kommentar
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBlockComment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
/*Kommentar*/
|
||||
//$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;
|
||||
/*Kommentar*/
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodLineCommentBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//$void method2();$////Kommentar
|
||||
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(); //Kommentar
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBlockCommentBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//$void method2();$///*Kommentar*/
|
||||
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(); /*Kommentar*/
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodLineCommentWithSpace
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
|
||||
//Kommentar
|
||||
//$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;
|
||||
//Kommentar
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBlockCommentWithSpace
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
|
||||
/*Kommentar*/
|
||||
//$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;
|
||||
/*Kommentar*/
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodLineCommentWithSpaceBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//$void method2();$////Kommentar
|
||||
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(); //Kommentar
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBlockCommentWithSpaceBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//$void method2();$///*Kommentar*/
|
||||
|
||||
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(); /*Kommentar*/
|
||||
};
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBigBlockComment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
/*
|
||||
* Kommentar
|
||||
*/
|
||||
//$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;
|
||||
/*
|
||||
* Kommentar
|
||||
*/
|
||||
void method2();
|
||||
};
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBigBlockCommentBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//$void method2();$// /*
|
||||
* Kommentar
|
||||
*/
|
||||
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(); /*
|
||||
* Kommentar
|
||||
*/
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBigBlockCommentBeforeAndBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
/*
|
||||
* Davor
|
||||
*/
|
||||
//$void method2();$// /*
|
||||
* Kommentar
|
||||
*/
|
||||
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;
|
||||
/*
|
||||
* Davor
|
||||
*/
|
||||
void method2(); /*
|
||||
* Kommentar
|
||||
*/
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodMixedCommentBeforeAndAfter
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
/*123*/
|
||||
//$void method2();$////TEST
|
||||
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;
|
||||
/*123*/
|
||||
void method2(); //TEST
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodBlockCommentBeforeAndBehind
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
/*123*/
|
||||
//$void method2();$///*TEST*/
|
||||
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;
|
||||
/*123*/
|
||||
void method2(); /*TEST*/
|
||||
};
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodNoChange
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
private:
|
||||
//$void method2();$//
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
private:
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethod2MethodsDifferentLine
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
//$void method1();$//
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
void method2();
|
||||
private:
|
||||
void method1();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethod2MethodsSameLine
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
//$void method1();$//void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
void method2();
|
||||
private:
|
||||
void method1();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethod2MethodsDifferentLineWithComment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
//Kommentar
|
||||
//$void method1();$//
|
||||
void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
void method2();
|
||||
private:
|
||||
//Kommentar
|
||||
void method1();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethod2MethodsSameLineWithComment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
//Kommentar
|
||||
//$void method1();$//void method2();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
void method2();
|
||||
private:
|
||||
//Kommentar
|
||||
void method1();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//!HideMethodSimple ImplementationFile
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@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_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
void A:://$method2$//()
|
||||
{
|
||||
}
|
||||
|
||||
//!HideMethodSimple ImplementationFile with Comments BUG #60
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class A{
|
||||
public:
|
||||
A();
|
||||
//TEST 1
|
||||
void method2(); //TEST 2
|
||||
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;
|
||||
//TEST 1
|
||||
void method2(); //TEST 2
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
void A:://$method2$//()
|
||||
{
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ public class RefactoringTestSuite extends TestSuite {
|
|||
suite.addTest(RenameRegressionTests.suite());
|
||||
suite.addTest(ExtractFunctionTestSuite.suite());
|
||||
suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTests", "resources/refactoring/ExtractConstant.rts"));
|
||||
suite.addTest(RefactoringTester.suite("HideMethodRefactoringTests", "resources/refactoring/HideMethod.rts"));
|
||||
suite.addTest(UtilTestSuite.suite());
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.hidemethod;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*/
|
||||
public class HideMethodRefactoringTest extends RefactoringTest {
|
||||
|
||||
public HideMethodRefactoringTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
|
||||
IFile refFile = project.getFile(fileWithSelection);
|
||||
|
||||
HideMethodRefactoring refactoring = new HideMethodRefactoring(refFile,selection, null);
|
||||
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||
assertConditionsOk(checkInitialConditions);
|
||||
|
||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||
assertConditionsOk(finalConditions);
|
||||
createChange.perform(NULL_PROGRESS_MONITOR);
|
||||
|
||||
compareFiles(fileMap);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureRefactoring(Properties refactoringProperties) {
|
||||
}
|
||||
}
|
|
@ -7,10 +7,10 @@ Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
|
|||
Bundle-Vendor: %providerName
|
||||
Bundle-Localization: plugin
|
||||
Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
||||
org.eclipse.cdt.internal.corext.codemanipulation,
|
||||
org.eclipse.cdt.internal.corext.codemanipulation;x-internal:=true,
|
||||
org.eclipse.cdt.internal.corext.template.c;x-internal:=true,
|
||||
org.eclipse.cdt.internal.corext.util;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui,
|
||||
org.eclipse.cdt.internal.ui;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.actions;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.browser.opentype;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.buildconsole;x-internal:=true,
|
||||
|
@ -25,13 +25,14 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.internal.ui.filters;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.includebrowser;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.indexview;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.navigator,
|
||||
org.eclipse.cdt.internal.ui.navigator;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.preferences;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.preferences.formatter,
|
||||
org.eclipse.cdt.internal.ui.preferences.formatter;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.refactoring;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.dialogs,
|
||||
org.eclipse.cdt.internal.ui.refactoring.dialogs;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.refactoring.extractconstant;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.extractfunction,
|
||||
org.eclipse.cdt.internal.ui.refactoring.extractfunction;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.hidemethod;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.rename;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.utils;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.search;x-internal:=true,
|
||||
|
|
|
@ -137,6 +137,7 @@ ActionDefinition.showMacroExplorer.description= Opens a quick view for macro exp
|
|||
category.refactoring.description= C/C++ Refactorings
|
||||
category.refactoring.name = Refactor - C++
|
||||
refactoringExtractConstant.label = Extract Constant...
|
||||
refactoringHideMethod.label = Hide Memeber Function...
|
||||
|
||||
|
||||
ActionDefinition.renameElement.name= Rename - Refactoring
|
||||
|
@ -154,6 +155,7 @@ Refactoring.menu.label= Refac&tor
|
|||
Refactoring.renameAction.label=Re&name...
|
||||
Refactoring.extractConstant.label=Extr&act Constant...
|
||||
Refactoring.extractFunction.label=Extract &Function... (work in progress)
|
||||
Refactoring.hideMethod.label=Hide Member Function... (work in progress)
|
||||
|
||||
CEditor.name=C/C++ Editor
|
||||
|
||||
|
|
|
@ -1150,6 +1150,13 @@
|
|||
id="org.eclipse.cdt.ui.actions.Rename"
|
||||
retarget="true">
|
||||
</action>
|
||||
<action
|
||||
definitionId="org.eclipse.cdt.ui.refactor.hide.method"
|
||||
label="%Refactoring.hideMethod.label"
|
||||
menubarPath="org.eclipse.jdt.ui.refactoring.menu/codingGroup"
|
||||
id="org.eclipse.cdt.ui.actions.HideMethod"
|
||||
retarget="true">
|
||||
</action>
|
||||
<action
|
||||
definitionId="org.eclipse.cdt.ui.refactor.extract.function"
|
||||
label="%Refactoring.extractFunction.label"
|
||||
|
@ -1967,6 +1974,10 @@
|
|||
categoryId="org.eclipse.cdt.ui.category.refactoring"
|
||||
id="org.eclipse.cdt.ui.refactoring.command.ExtractConstant"
|
||||
name="%refactoringExtractConstant.label"/>
|
||||
<command
|
||||
categoryId="org.eclipse.cdt.ui.category.refactoring"
|
||||
id="org.eclipse.cdt.ui.refactor.hide.method"
|
||||
name="%refactoringHideMethod.label"/>
|
||||
<command
|
||||
name="%ActionDefinition.renameElement.name"
|
||||
description="%ActionDefinition.renameElement.description"
|
||||
|
|
|
@ -104,6 +104,12 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
*/
|
||||
public static final String EXTRACT_FUNCTION = "org.eclipse.cdt.ui.refactor.extract.function"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> hide method action
|
||||
* (value <code>"org.eclipse.cdt.ui.refactor.hide.method"</code>).
|
||||
*/
|
||||
public static final String HIDE_METHOD= "org.eclipse.cdt.ui.refactor.hide.method"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> undo action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.undo.action"</code>).
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -20,6 +21,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
|
@ -48,8 +50,12 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
||||
|
@ -65,25 +71,41 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
|
|||
public abstract class CRefactoring extends Refactoring {
|
||||
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
public static final String NEWLINE = "\n"; // mstodo //$NON-NLS-1$
|
||||
public static final String NEWLINE = "\n"; //$NON-NLS-1$
|
||||
|
||||
protected String name = Messages.HSRRefactoring_name;
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected Region region;
|
||||
protected RefactoringStatus initStatus;
|
||||
protected IASTTranslationUnit unit;
|
||||
private IIndex fIndex;
|
||||
|
||||
public CRefactoring(IFile file, ISelection selection) {
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
this.initStatus=new RefactoringStatus();
|
||||
public CRefactoring(IFile file, ISelection selection, ICElement element) {
|
||||
if (element instanceof ISourceReference) {
|
||||
ISourceReference sourceRef= (ISourceReference) element;
|
||||
ITranslationUnit tu= sourceRef.getTranslationUnit();
|
||||
IResource res= tu.getResource();
|
||||
if (res instanceof IFile)
|
||||
this.file= (IFile) res;
|
||||
|
||||
try {
|
||||
final ISourceRange sourceRange = sourceRef.getSourceRange();
|
||||
this.region = new Region(sourceRange.getIdStartPos(), sourceRange.getIdLength());
|
||||
} catch (CModelException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.file = file;
|
||||
this.region = getRegion(selection);
|
||||
}
|
||||
|
||||
if(selection == null){
|
||||
initStatus.addError(Messages.HSRRefactoring_SelectionNotValid);
|
||||
this.initStatus=new RefactoringStatus();
|
||||
if (this.file == null || region == null) {
|
||||
initStatus.addFatalError(Messages.HSRRefactoring_SelectionNotValid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ProblemFinder extends ASTVisitor{
|
||||
|
||||
private boolean problemFound = false;
|
||||
|
@ -248,10 +270,14 @@ public abstract class CRefactoring extends Refactoring {
|
|||
return name;
|
||||
}
|
||||
|
||||
protected ITextSelection getTextSelection() {
|
||||
return (ITextSelection) selection;
|
||||
private Region getRegion(ISelection selection) {
|
||||
if (selection instanceof ITextSelection) {
|
||||
final ITextSelection txtSelection= (ITextSelection) selection;
|
||||
return new Region(txtSelection.getOffset(), txtSelection.getLength());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private boolean loadTranslationUnit(RefactoringStatus status,
|
||||
IProgressMonitor mon) {
|
||||
SubMonitor subMonitor = SubMonitor.convert(mon, 10);
|
||||
|
@ -325,7 +351,7 @@ public abstract class CRefactoring extends Refactoring {
|
|||
return selection;
|
||||
}
|
||||
|
||||
protected boolean isExpressionWhollyInSelection(ITextSelection textSelection, IASTNode expression) {
|
||||
protected boolean isExpressionWhollyInSelection(Region textSelection, IASTNode expression) {
|
||||
ExpressionPosition exprPos = createExpressionPosition(expression);
|
||||
|
||||
int selStart = textSelection.getOffset();
|
||||
|
@ -334,7 +360,7 @@ public abstract class CRefactoring extends Refactoring {
|
|||
return exprPos.start >= selStart && exprPos.end <= selEnd;
|
||||
}
|
||||
|
||||
public static boolean isSelectionOnExpression(ITextSelection textSelection, IASTNode expression) {
|
||||
public static boolean isSelectionOnExpression(Region textSelection, IASTNode expression) {
|
||||
ExpressionPosition exprPos = createExpressionPosition(expression);
|
||||
int selStart = textSelection.getOffset();
|
||||
int selEnd = textSelection.getLength() + selStart;
|
||||
|
@ -348,14 +374,14 @@ public abstract class CRefactoring extends Refactoring {
|
|||
return locFile.equals(tmpFile);
|
||||
}
|
||||
|
||||
protected boolean isInSameFileSelection(ITextSelection textSelection, IASTNode node) {
|
||||
protected boolean isInSameFileSelection(Region textSelection, IASTNode node) {
|
||||
if( isInSameFile(node) ) {
|
||||
return isSelectionOnExpression(textSelection, node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isSelectedFile(ITextSelection textSelection, IASTNode node) {
|
||||
protected boolean isSelectedFile(Region textSelection, IASTNode node) {
|
||||
if( isInSameFile(node) ) {
|
||||
return isExpressionWhollyInSelection(textSelection, node);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
/**
|
||||
* Base class for all refactoring runners.
|
||||
*
|
||||
|
@ -25,14 +27,16 @@ public abstract class RefactoringRunner {
|
|||
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected ICElement celement;
|
||||
protected IShellProvider shellProvider;
|
||||
|
||||
public RefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) {
|
||||
public RefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) {
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
this.celement= element;
|
||||
this.shellProvider= shellProvider;
|
||||
}
|
||||
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
@ -80,14 +80,14 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
private final NameNVisibilityInformation info;
|
||||
|
||||
public ExtractConstantRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info){
|
||||
super(file,selection);
|
||||
super(file,selection, null);
|
||||
this.info = info;
|
||||
name = Messages.ExtractConstantRefactoring_ExtractConst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||
SubMonitor sm = SubMonitor.convert(pm, 9);
|
||||
super.checkInitialConditions(sm.newChild(6));
|
||||
|
||||
Collection<IASTLiteralExpression> literalExpressionVector = findAllLiterals();
|
||||
|
@ -95,16 +95,11 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
||||
return initStatus;
|
||||
}
|
||||
|
||||
sm.worked(1);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
ITextSelection textSelection = getTextSelection();
|
||||
sm.worked(1);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
boolean oneMarked = isOneMarked(literalExpressionVector, textSelection);
|
||||
boolean oneMarked = region != null && isOneMarked(literalExpressionVector, region);
|
||||
if(!oneMarked){
|
||||
//No or more than one marked
|
||||
if(target == null){
|
||||
|
@ -132,7 +127,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
String nameString = literal.toString();
|
||||
switch (literal.getKind()) {
|
||||
case IASTLiteralExpression.lk_char_constant:
|
||||
case ICPPASTLiteralExpression.lk_string_literal:
|
||||
case IASTLiteralExpression.lk_string_literal:
|
||||
int beginIndex = 1;
|
||||
if(nameString.startsWith("L")) { //$NON-NLS-1$
|
||||
beginIndex = 2;
|
||||
|
@ -220,7 +215,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isOneMarked(Collection<IASTLiteralExpression> literalExpressionVector, ITextSelection textSelection) {
|
||||
private boolean isOneMarked(Collection<IASTLiteralExpression> literalExpressionVector, Region textSelection) {
|
||||
boolean oneMarked = false;
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
boolean isInSameFileSelection = isInSameFileSelection(textSelection, expression);
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
|||
public class ExtractConstantRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) {
|
||||
super(file, selection, shellProvider);
|
||||
super(file, selection, null, shellProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
@ -123,7 +122,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
public ExtractFunctionRefactoring(IFile file, ISelection selection,
|
||||
ExtractFunctionInformation info) {
|
||||
super(file, selection);
|
||||
super(file, selection, null);
|
||||
this.info = info;
|
||||
name = Messages.ExtractFunctionRefactoring_ExtractFunction;
|
||||
names = new HashMap<String, Integer>();
|
||||
|
@ -902,39 +901,31 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
private NodeContainer findExtractableNodes() {
|
||||
final NodeContainer container = new NodeContainer();
|
||||
if (selection instanceof ITextSelection) {
|
||||
final ITextSelection textSelection = (ITextSelection) selection;
|
||||
unit.accept(new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
unit.accept(new CPPASTVisitor() {
|
||||
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitExpressions = true;
|
||||
@Override
|
||||
public int visit(IASTStatement stmt) {
|
||||
if (!(stmt instanceof IASTCompoundStatement)
|
||||
&& isSelectedFile(region, stmt)) {
|
||||
container.add(stmt);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
return super.visit(stmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement stmt) {
|
||||
if (!(stmt instanceof IASTCompoundStatement)
|
||||
&& isSelectedFile(textSelection, stmt)) {
|
||||
container.add(stmt);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
return super.visit(stmt);
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (isSelectedFile(region, expression)) {
|
||||
container.add(expression);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (isSelectedFile(textSelection, expression)) {
|
||||
container.add(expression);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
return super.visit(expression);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return super.visit(expression);
|
||||
}
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
|||
public class ExtractFunctionRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public ExtractFunctionRefactoringRunner(IFile file, ISelection selection, IShellProvider shellProvider) {
|
||||
super(file, selection, shellProvider);
|
||||
super(file, selection, null, shellProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class HideMethodRefactoring extends CRefactoring {
|
||||
|
||||
private IASTName methodToMove;
|
||||
private IASTSimpleDeclaration fieldToMoveDecl;
|
||||
|
||||
public HideMethodRefactoring(IFile file, ISelection selection, ICElement element) {
|
||||
super(file, selection, element);
|
||||
name = Messages.HideMethodRefactoring_HIDE_METHOD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||
super.checkInitialConditions(sm.newChild(6));
|
||||
|
||||
if(initStatus.hasFatalError()){
|
||||
return initStatus;
|
||||
}
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
IASTName name;
|
||||
Vector<IASTName> names = findAllMarkedNames();
|
||||
if(names.size() > 1) {
|
||||
name = names.lastElement();
|
||||
} else if (names.size() < 1) {
|
||||
initStatus.addFatalError(Messages.HideMethodRefactoring_NoNameSelected);
|
||||
return initStatus;
|
||||
}else {
|
||||
name = names.get(0);
|
||||
}
|
||||
sm.worked(1);
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
this.methodToMove = getDeclaration(name);
|
||||
|
||||
if(this.methodToMove == null) {
|
||||
initStatus.addFatalError(Messages.HideMethodRefactoring_NoMethodNameSeleceted);
|
||||
return initStatus;
|
||||
}
|
||||
sm.worked(1);
|
||||
fieldToMoveDecl = findSimpleDeclaration(this.methodToMove);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
sm.worked(1);
|
||||
for(IASTDeclarator declarator : fieldToMoveDecl.getDeclarators()) {
|
||||
if(declarator.getName().getRawSignature().equals(name.getRawSignature())) {
|
||||
if (!(declarator instanceof IASTFunctionDeclarator)) {
|
||||
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
|
||||
return initStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
sm.done();
|
||||
return initStatus;
|
||||
}
|
||||
|
||||
private Vector<IASTName> findAllMarkedNames() {
|
||||
final Vector<IASTName> namesVector = new Vector<IASTName>();
|
||||
|
||||
unit.accept(new CPPASTVisitor(){
|
||||
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
if( isInSameFileSelection(region, name) ) {
|
||||
if (!(name instanceof ICPPASTQualifiedName)) {
|
||||
namesVector.add(name);
|
||||
}
|
||||
}
|
||||
return super.visit(name);
|
||||
}
|
||||
|
||||
});
|
||||
return namesVector;
|
||||
}
|
||||
|
||||
protected IASTSimpleDeclaration findSimpleDeclaration(IASTNode fieldToFoundDecl) {
|
||||
while(fieldToFoundDecl != null){
|
||||
if (fieldToFoundDecl instanceof IASTSimpleDeclaration) {
|
||||
return (IASTSimpleDeclaration) fieldToFoundDecl;
|
||||
}
|
||||
fieldToFoundDecl = fieldToFoundDecl.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IASTName getDeclaration(IASTName name) {
|
||||
DeclarationFinder df = new DeclarationFinder(name);
|
||||
unit.accept(df);
|
||||
return df.getDeclaration();
|
||||
}
|
||||
|
||||
private class DeclarationFinder extends CPPASTVisitor{
|
||||
|
||||
IASTName astName;
|
||||
IASTName declaration = null;
|
||||
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
public DeclarationFinder(IASTName name) {
|
||||
this.astName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if(declarator instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator funcDec = (ICPPASTFunctionDeclarator)declarator;
|
||||
if(funcDec.getName().getRawSignature().equals(astName.getRawSignature())){
|
||||
declaration = funcDec.getName();
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public IASTName getDeclaration() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
return super.checkFinalConditions(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
|
||||
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||
TextEditGroup editGroup = new TextEditGroup(Messages.HideMethodRefactoring_FILE_CHANGE_TEXT+ methodToMove.getRawSignature());
|
||||
|
||||
// egtodo
|
||||
// IASTNode parent = fieldToMoveDecl.getParent();
|
||||
|
||||
ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) fieldToMoveDecl.getParent();
|
||||
AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_private, fieldToMoveDecl, false, collector);
|
||||
|
||||
rewriter.remove(fieldToMoveDecl, editGroup);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class HideMethodRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public HideMethodRefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider) {
|
||||
super(file, selection, element, shellProvider);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
CRefactoring refactoring= new HideMethodRefactoring(file, selection, celement);
|
||||
HideMethodRefactoringWizard wizard = new HideMethodRefactoringWizard(refactoring);
|
||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||
|
||||
try {
|
||||
refactoring.lockIndex();
|
||||
try {
|
||||
operator.run(shellProvider.getShell(), refactoring.getName());
|
||||
}
|
||||
finally {
|
||||
refactoring.unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class HideMethodRefactoringWizard extends RefactoringWizard {
|
||||
|
||||
public HideMethodRefactoringWizard(Refactoring refactoring) {
|
||||
super(refactoring, WIZARD_BASED_USER_INTERFACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addUserInputPages() {
|
||||
//No spezial User Wizard to add
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public final class Messages extends NLS {
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.hsrrefactoring.hidemethod.messages";//$NON-NLS-1$
|
||||
|
||||
private Messages() {
|
||||
// Do not instantiate
|
||||
}
|
||||
|
||||
public static String HideMethodRefactoring_HIDE_METHOD;
|
||||
public static String HideMethodRefactoring_NoNameSelected;
|
||||
public static String HideMethodRefactoring_NoMethodNameSeleceted;
|
||||
public static String HideMethodRefactoring_CanOnlyHideMethods;
|
||||
public static String HideMethodRefactoring_FILE_CHANGE_TEXT;
|
||||
public static String HideMethodRefactoring_BAD_TYPE;
|
||||
public static String HideMethodRefactoring_NO_SELECTION;
|
||||
public static String HideMethodRefactoring_BAD_DIALECT;
|
||||
public static String HideMethodRefactoring_NO_FILE;
|
||||
public static String HideMethodRefactoring_NO_PROPER_SELECTION;
|
||||
public static String HideMethodRefactoring_EDITOR_NOT_SAVE;
|
||||
public static String HideMethodRefactoring_NO_NODES;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
# Rapperswil, University of applied sciences and others
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# Institute for Software - initial API and implementation
|
||||
###############################################################################
|
||||
HideMethodRefactoring_HIDE_METHOD=Hide Method
|
||||
HideMethodRefactoring_NoNameSelected=No names selected.
|
||||
HideMethodRefactoring_NoMethodNameSeleceted=No method name selected.
|
||||
HideMethodRefactoring_CanOnlyHideMethods=Hide Method can only hide Methods.
|
||||
HideMethodRefactoring_FILE_CHANGE_TEXT=Hide
|
||||
HideMethodRefactoring_BAD_TYPE=Bad selection-type
|
||||
HideMethodRefactoring_NO_SELECTION=No Selection available.
|
||||
|
||||
HideMethodRefactoring_BAD_DIALECT=Not Supported Dialect
|
||||
HideMethodRefactoring_NO_FILE=There is no file marked.
|
||||
HideMethodRefactoring_NO_PROPER_SELECTION=No proper Selection\!
|
||||
HideMethodRefactoring_EDITOR_NOT_SAVE=Editor is not saved
|
||||
HideMethodRefactoring_NO_NODES=No nodes found.
|
||||
|
|
@ -247,6 +247,12 @@ public class CdtActionConstants {
|
|||
* (value <code>"org.eclipse.cdt.ui.actions.ExtractConstant"</code>).
|
||||
*/
|
||||
public static final String EXTRACT_CONSTANT= "org.eclipse.cdt.ui.actions.ExtractConstant"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Refactor menu: name of standard Hide Method global action
|
||||
* (value <code>"org.eclipse.cdt.ui.actions.HideMethod"</code>).
|
||||
*/
|
||||
public static final String HIDE_METHOD= "org.eclipse.cdt.ui.actions.HideMethod"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Refactor menu: name of standard Introduce Parameter global action
|
||||
|
|
|
@ -114,6 +114,7 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
|||
private CRenameAction fRenameAction;
|
||||
private RefactoringAction fExtractConstantAction;
|
||||
private RefactoringAction fExtractFunctionAction;
|
||||
private RefactoringAction fHideMethodAction;
|
||||
private IWorkbenchSite fSite;
|
||||
private List<RefactoringAction> fAllActions= new ArrayList<RefactoringAction>();
|
||||
|
||||
|
@ -154,6 +155,10 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
|||
fExtractFunctionAction.setActionDefinitionId(ICEditorActionDefinitionIds.EXTRACT_FUNCTION);
|
||||
fAllActions.add(fExtractFunctionAction);
|
||||
}
|
||||
|
||||
fHideMethodAction = new HideMethodAction();
|
||||
fHideMethodAction.setActionDefinitionId(ICEditorActionDefinitionIds.HIDE_METHOD);
|
||||
fAllActions.add(fHideMethodAction);
|
||||
}
|
||||
|
||||
public void setWorkbenchSite(IWorkbenchSite site) {
|
||||
|
@ -190,6 +195,7 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
|||
setActionHandler(actionBar, CdtActionConstants.RENAME, fRenameAction);
|
||||
setActionHandler(actionBar, CdtActionConstants.EXTRACT_CONSTANT, fExtractConstantAction);
|
||||
setActionHandler(actionBar, CdtActionConstants.EXTRACT_METHOD, fExtractFunctionAction);
|
||||
setActionHandler(actionBar, CdtActionConstants.HIDE_METHOD, fHideMethodAction);
|
||||
}
|
||||
|
||||
private void setActionHandler(IActionBars actionBar, String id, RefactoringAction action) {
|
||||
|
@ -219,6 +225,8 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
|||
refactorSubmenu.add(new Separator(GROUP_CODING));
|
||||
addAction(refactorSubmenu, fExtractConstantAction);
|
||||
addAction(refactorSubmenu, fExtractFunctionAction);
|
||||
addAction(refactorSubmenu, fHideMethodAction);
|
||||
|
||||
refactorSubmenu.add(new Separator(GROUP_REORG2));
|
||||
refactorSubmenu.add(new Separator(GROUP_TYPE));
|
||||
refactorSubmenu.add(new Separator(GROUP_TYPE2));
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.refactoring.actions;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IMethodDeclaration;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoringRunner;
|
||||
|
||||
/**
|
||||
* Launches a HideMethod refacoring
|
||||
* @author Guido Zgraggen IFS
|
||||
*/
|
||||
public class HideMethodAction extends RefactoringAction {
|
||||
|
||||
public HideMethodAction() {
|
||||
super(Messages.HideMethodAction_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IShellProvider shellProvider, ICElement elem) {
|
||||
if (elem instanceof ISourceReference) {
|
||||
new HideMethodRefactoringRunner(null, null, elem, shellProvider).run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s) {
|
||||
IResource res= wc.getResource();
|
||||
if (res instanceof IFile) {
|
||||
new HideMethodRefactoringRunner((IFile) res,
|
||||
fEditor.getSelectionProvider().getSelection(), null,
|
||||
fEditor.getSite().getWorkbenchWindow()).run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSelection(ICElement elem) {
|
||||
super.updateSelection(elem);
|
||||
if (elem instanceof IMethodDeclaration == false
|
||||
|| elem instanceof ISourceReference == false
|
||||
|| ((ISourceReference) elem).getTranslationUnit().getResource() instanceof IFile == false) {
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ public class Messages extends NLS {
|
|||
public static String CRenameAction_label;
|
||||
public static String ExtractConstantAction_label;
|
||||
public static String ExtractFunctionAction_label;
|
||||
public static String HideMethodAction_label;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
|
|
|
@ -78,6 +78,7 @@ public abstract class RefactoringAction extends Action {
|
|||
|
||||
public void updateSelection(ICElement elem) {
|
||||
fElement= elem;
|
||||
setEnabled(elem != null);
|
||||
}
|
||||
|
||||
public abstract void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s);
|
||||
|
|
|
@ -11,4 +11,5 @@
|
|||
CRefactoringActionGroup_menu=Refactor
|
||||
CRenameAction_label=Rename...
|
||||
ExtractConstantAction_label=Extract Constant...
|
||||
HideMethodAction_label=Hide Member Function... (work in progress)
|
||||
ExtractFunctionAction_label=Extract Function... (work in progress)
|
||||
|
|
Loading…
Add table
Reference in a new issue