javaintellij-idea

How can modal dialogs for renamings be suppressed in live plugins of IntelliJ IDEA Ultimate 2025.2 RC?


I want to rename fields of Java 21 classes by a live plugin in IntelliJ IDEA Ultimate 2025.2 RC and Live Plugins 0.97 beta but when a class has got a constructor, it always opens a modal dialog to ask if the constructor parameters should be renamed as well. This is my live plugin:

// depends-on-plugin com.intellij.java

import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiField
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.AllClassesSearch
import com.intellij.openapi.module.ModuleManager

import com.intellij.refactoring.rename.RenameProcessor
import com.intellij.refactoring.ui.RefactoringDialog

Project proj = project
def targetModule = ModuleManager.getInstance(proj)
        .findModuleByName("my-module")

def scope = GlobalSearchScope.moduleScope(targetModule)

def classesQuery = AllClassesSearch.search(scope, proj)
def classesToEdit = classesQuery.findAll { it }

WriteCommandAction.runWriteCommandAction(project) {
    classesToEdit.each { PsiClass cls ->
        if (cls.isInterface() || cls.isRecord()) return
        int seq = 1
        cls.fields.each { PsiField f ->
            if (f.hasModifierProperty("static")) return
            def newName = "f" + String.format("%02d", seq++)
            def rp = new RenameProcessor(project, f, newName, true, true)
            rp.setPreviewUsages(false)
            rp.doRun()
        }
    }
}

How can I suppress those dialogs?

I have tried out proposals by ChatGPT but they don't work. Here some of them:

Removing constructors temporarily for these renamings is no option. Neither bash shell scripts which replace by sed.

EDIT: rp.setPreviewUsages(false) only works with rp.doRun() but not with rp.run(). I have corrected that.


Solution

  • TL,DR; It has become impossible. Avoid to cause any circumstances where IntelliJ IDEA wants to ask for more refactoring in a modal dialog.