栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

我可以通过编程调用任何Eclipse重构API吗?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

我可以通过编程调用任何Eclipse重构API吗?

下面的答案很好,但是对于那些需要更庞大,更美味的东西的人们,我给出了更广阔的视野

cake

    RefactoringStatus status = new RefactoringStatus();    IWorkspace workspace = ResourcesPlugin.getWorkspace();    IWorkspaceRoot root = workspace.getRoot();    IProject[] projects = root.getProjects();

然后:

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

之后:

IProgressMonitor monitor = new NullProgressMonitor();status = new RefactoringStatus();Refactoring refactoring = performMethodsRefactoring(status, methodToRename, newName);

然后:

Change change = refactoring.createChange(monitor);change.perform(monitor);

在下面找到用于设置的代码

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495624.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号