【发布时间】:2012-10-05 14:37:50
【问题描述】:
当我需要内联方法时,我可以使用Refactor->Inine。
这是我尝试过的代码骨架,我使用了这篇文章中的代码 - Is there any eclipse refactoring API that I can call programmatically?。
// 1. Get ICompiationUnit for type "smcho.Hello"
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("Hello");
project.open(null /* IProgressMonitor */);
IJavaProject javaProject = JavaCore.create(project);
IType itype = javaProject.findType("smcho.Hello");
org.eclipse.jdt.core.ICompilationUnit icu = itype.getCompilationUnit();
// 2. Contribution and Description creation
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(IJavaRefactorings.INLINE_METHOD);
InlineMethodDescriptor descriptor = (InlineMethodDescriptor) contribution.createDescriptor();
descriptor.setProject(icu.getResource().getProject().getName( ));
// 3. executing the refactoring
RefactoringStatus status = new RefactoringStatus();
try {
Refactoring refactoring = descriptor.createRefactoring(status);
IProgressMonitor monitor = new NullProgressMonitor();
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);
Change change = refactoring.createChange(monitor);
change.perform(monitor);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
当我执行代码时,我得到了这个错误
org.eclipse.core.runtime.CoreException: The refactoring script argument 'input' is missing
in the refactoring script.
我认为我需要将重构的方法名称提供给 API。代码可能有什么问题?
【问题讨论】:
标签: eclipse eclipse-jdt eclipse-plugin ltk