How to rename a class? Permanently deleted user Created July 31, 2007 11:45 How to rename / move a Java class? Does the PsiClass contain a method for renaming?For example, the VirtualFile class contains the rename, move methods.
Find the name element, create a new name element, replace. Be sure to do the same for any constructors on the class, and any references to the class.
Alternatively, you could fire a "rename" refactoring by constructing a RenameRefactoringHandler. That's probably your safest bet.
In general PSI classes don't have much direct support for mutating them in their APIs.
--Dave Griffith
see PsiNamedElement.setName(). For classes it also renames file if needed.
Wow, how did I miss that?
--Dave Griffith
I can change class name but how to move the class to another package? Remove from the current package and add to another?
Hey, that's the whole refactoring! You want the references to the class to updated too, don't you? To invoke move programmatically see RefactoringActionHandlerFactory.createMoveHandler()