limit refectoring to one document? Follow
Is it possible to limit refactoring changes to one document (or a set of documents)?
Here is the code to my plugin.
Please sign in to leave a comment.
it is not possible to change the scope of a refactoring as it would produce red code otherwise. If changes are in text occurrences you may set option to search in text occurences to false: com.intellij.refactoring.JavaRefactoringSettings, but please don't forget to restore the setting after your refactoring passes. BTW in your code e.g. you don't search for conflicts. The more correct usage is just to invoke run() on the refactoring instance.
I modified my code as you see below but when I run the plugin, it continues to make changes in the comments and in the text. Any suggestions about how to remedy this?
public void actionPerformed(AnActionEvent e)
final PsiJavaFile psiFile = (PsiJavaFile) e.getData(LangDataKeys.PSI_FILE);
Editor editor = e.getData(PlatformDataKeys.EDITOR);
if (psiFile == null || editor == null)
JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_CLASS = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_PACKAGE = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FIELD = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_VARIABLE = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_CLASS = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_PACKAGE = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_FIELD = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD = false;
JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_VARIABLE = false;
RefactoringSettings.getInstance().SAFE_DELETE_SEARCH_IN_NON_JAVA = false;
RefactoringSettings.getInstance().SAFE_DELETE_SEARCH_IN_COMMENTS = false;
Please try to debug from com.intellij.refactoring.rename.RenameProcessor#findUsages. You'll be able to see if the options are set and would be able to find the processor which returns usages in strings/comments
Thanks for your reply Anna.
Sorry, I am not able to see how to use your suggestion in my code. Can you provide an example of what you are describing?
You need to check that you have attached sources to IDEA JDK and set a breakpoint at the start of findUsages method. Or just step into refactoring.run() method inside your code.