有没有任何可以以编程方式调用的eclipse重构API? [英] Is there any eclipse refactoring API that I can call programmatically?
问题描述
I需要一些想法,如何实现以下:一个程序,调用所有的eclipse重构,重命名和移动一个循环,重构整个项目一次!
我不想通过扩展重构类来引入新的重构类型。我只想以编程方式调用它们。
再次感谢Paul Webster,Leif Frenzer,Mohsen Vakilian和Arno为他们伟大的文章和帮助!
下面的答案是伟大的,但我回答了更广泛的观点 然后:
<$重新构建状态= new RefactoringStatus();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject [] projects = root.getProjects();
IType primary = unit.findPrimaryType(); b
$ b
IMethod [] methods = primary.getMethods();
int i = 1;
for(IMethod method:methods){
if(method.isConstructor()){
continue;
}
makeChangetoMethods(status,method,changedMethodVersion_+ i);
++ i;
}
}
之后: em>
IProgressMonitor monitor = new NullProgressMonitor();
status = new RefactoringStatus();
重构重构= performMethodsRefactoring(status,methodToRename,newName);
然后:
更改change = refactoring.createChange(monitor);
change.perform(monitor);
找到下面设置描述符
:
String id = IJavaRefactorings.RENAME_METHOD;
RefactoringContribution contrib = RefactoringCore.getRefactoringContribution(id);
RenameJavaElementDescriptor desc = contrib.createDescriptor();
desc.setUpdateReferences(true);
desc.setJavaElement(methodToRename);
desc.setNewName(newName);
desc.createRefactoring(status);
I need to refactor code in a wide term. I know that from inside the Eclipse IDE I can refactor my classes. But is there any API that I can use in a java project so that I can refactor projects dynamically through code?
I need some idea on how to achieve the following: a program that calls all the eclipse refactorings for renaming and moving in a loop to refactoring the entire project in one shot!
I don't want to introduce new refactoring types by extending the refactoring classes. I just want to call them programmatically.
Thanks again to Paul Webster, Leif Frenzer, Mohsen Vakilian, and Arno for their great articles and help!
The answer below is great, but I answered with a wider perspective for the people who need a more bulky and tasty crunch of this wonderful cake
:
RefactoringStatus status = new RefactoringStatus();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject[] projects = root.getProjects();
then:
for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
IType primary = unit.findPrimaryType();
IMethod[] methods = primary.getMethods();
int i = 1;
for (IMethod method : methods) {
if (method.isConstructor()) {
continue;
}
makeChangetoMethods(status, method,"changedMethodVersion_" + i);
++i;
}
}
After that:
IProgressMonitor monitor = new NullProgressMonitor();
status = new RefactoringStatus();
Refactoring refactoring = performMethodsRefactoring(status, methodToRename, newName);
then:
Change change = refactoring.createChange(monitor);
change.perform(monitor);
find below the code for setting the descriptor
:
String id = IJavaRefactorings.RENAME_METHOD;
RefactoringContribution contrib = RefactoringCore.getRefactoringContribution(id);
RenameJavaElementDescriptor desc = contrib.createDescriptor();
desc.setUpdateReferences(true);
desc.setJavaElement(methodToRename);
desc.setNewName(newName);
desc.createRefactoring(status);
这篇关于有没有任何可以以编程方式调用的eclipse重构API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!