I'm just starting out developing eclipse plugins so forgive me if this is an easy question, but I am developing a plugin in which the first step consists of analysing the source code of a Java application and Extract new Methods.
My plugin determines the sequence of statements to be extracted. I want to use ExtractMethodAction (http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fui%2Factions%2Fpackage-summary.html).
Note that, my plugin recover a sequence of statements (http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FStatement.html) and not an ITextSelection which is the parameter of the method run of the class ExtractMethodAction. Moreover, the constructor of ExtractMethodAction has as a parameter JavaEditor and I do not know how to create a JavaEditor for an ICompilationUnit.
This is a part of the method execute of my plugin:
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkspace workspace= ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject [] projects = root.getProjects();
for(IProject project: projects){
IJavaProject javaProject = JavaCore.create(project);
try {
IPackageFragment [] packages =javaProject.getPackageFragments();
for (IPackageFragment mypackage: packages){
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE){
ICompilationUnit[] units = mypackage.getCompilationUnits();
for (ICompilationUnit unit: units){
Parser myparser = new Parser();
CompilationUnit cu= myparser.parse(unit);
...
}
}
}
and this is how I tried to use ExtractMethodAction:
JavaEditor edit;
ExtractMethodAction act= new ExtractMethodAction(edit);
ITextSelection select;
act.run(select);
Note that I did not know how to initialise the JavaEditor and the ITextSelection .
Can you help me please to use ExtractMethodAction if possible or tell me if it would be better to devellope my own code. Thank you very much.