Refactor -> Rename programmatically [message #1811031] |
Sat, 24 August 2019 10:06  |
Eclipse User |
|
|
|
Hello,
I am trying to do a rename refactoring for type declarations programmatically. I am currently trying to do so with the following method:
public static void renameType(IType type, String newName) {
final RefactoringContribution contribution = RefactoringCore
.getRefactoringContribution(IJavaRefactorings.RENAME_TYPE);
final RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) contribution.createDescriptor();
descriptor.setProject(type.getResource().getProject().getName());
descriptor.setJavaElement(type);
descriptor.setNewName(newName);
final RefactoringStatus status = new RefactoringStatus();
try {
final Refactoring refactoring = descriptor.createRefactoring(status);
final IProgressMonitor monitor = new NullProgressMonitor();
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);
final Change change = refactoring.createChange(monitor);
change.perform(monitor);
} catch (final Exception e) {
e.printStackTrace();
}
}
I then call it simply like this:
IType javaTypeToRename = ...
renameType(javaTypetoRename, "ChangedTypeName");
The renaming of the type declaration including the .java-file name works fine. But references to this type like fields in other classes etc. do not get renamed accordingly.
Does anyone maybe have an idea on how to fix this behavior to not break the project by not renaming the references?
Thanks a lot :)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05043 seconds