In an IntelliJ plugin, I want to call custom processing when renaming method argument parameters and implement a rename processor that replaces the same text as the rename target in SQL files.
I have prepared the following class and added it to the plugin.xml
file. However, even though it returns true
in the canProcessElement
method, neither renameElement
nor substituteElementToRename
is being called, and it seems like the custom processing is not being reached.
class DaoRenameParameterProcessor : RenamePsiElementProcessor() {
override fun canProcessElement(element: PsiElement): Boolean {
if (element is PsiParameter || element is PsiIdentifier) {
val parentMethod = PsiTreeUtil.getParentOfType(element, PsiMethod::class.java) ?: return false
val psiDaoMethod = PsiDaoMethod(parentMethod.project, parentMethod)
return !(psiDaoMethod.isUseSqlFileMethod() && psiDaoMethod.sqlFile == null)
}
return false
}
override fun isInplaceRenameSupported(): Boolean = true
override fun substituteElementToRename(
element: PsiElement,
editor: Editor?,
): PsiElement? {
println("substituteElementToRename: ${element.text}")
return element
}
override fun renameElement(
element: PsiElement,
newName: String,
usages: Array<out UsageInfo?>,
listener: RefactoringElementListener?,
) {
println("DaoRenameParameterProcessor: renameElement")
super.renameElement(element, newName, usages, listener)
}
}
plugin.xml
<renamePsiElementProcessor implementation="org.domaframework.doma.intellij.refactoring.dao.DaoRenameParameterProcessor" order="first" />
For a method argument like the following, the rename processing is called on “lists”:
/**
* test
* @param listList itemList
* @return
*/
int deleteWithSqlFile(List<List<Berry>> listList, String order, String literal);
The canProcessElement
method receives the element PsiParameter:listList
.
After the process, “listList” is renamed correctly, along with its name in the JavaDoc, likely due to the standard processing.
Is there a proper parent class or implementation method that should be used for this processor class?
Thank you.