Executing inline refactoring programmatically [message #945997] |
Mon, 15 October 2012 21:10 |
Sungmin Cho Messages: 9 Registered: October 2012 |
Junior Member |
|
|
Using Refactor -> Inline menu, one can transform this code
public class SimpleTest {
public int hello(int x, int y)
{
return (x + y)
}
public void caller()
{
int z = hello(10, 20);
}
}
into this code:
public class SimpleTest {
public void caller()
{
int z = (10 + 20);
}
}
How can I do it using JDT/LTK api?
This is my code trying to execute inlining. However, I got org.eclipse.core.runtime.CoreException: The refactoring script argument 'input' is missing
in the refactoring script. error, and I guess I need to fill in arguments to make it known that hello is the function to be inlined. Or, I might need to use different API.
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("Hello");
project.open(null /* IProgressMonitor */);
IJavaProject javaProject = JavaCore.create(project);
IType itype = javaProject.findType("SimpleTest");
org.eclipse.jdt.core.ICompilationUnit icu = itype.getCompilationUnit();
String projectName = icu.getResource().getProject().getName();
String description = "Inline method programmatically";
String comments = "";
Map arguments = new HashMap();
//arguments.put("", ""); <-- ???
int flags = 0;
InlineMethodDescriptor descriptor = new InlineMethodDescriptor(
projectName, description, comments, arguments, flags);
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();
}
How can I make the code working?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03195 seconds