limit refectoring to one document?

Is it possible to limit refactoring changes to one document (or a set of documents)?

When I run my plugin on a java file, it goes in and modifies other source files (such as javascript files for my project) which happen to have matching variable names in them.

Here is the code to my plugin.
https://github.com/jedierikb/p5Minimizer/blob/master/org/mediamods/p5minimizer/P5Mini.java

Much thanks
Erik

0
5 comments

Hi,

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.

0
Avatar
Permanently deleted user

Thanks Anna.

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)
     { e.getPresentation().setEnabled(false);
     return;
     }


        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;


     doMinify(psiFile);
 }

0

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

0
Avatar
Permanently deleted user

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?

0

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.

0

Please sign in to leave a comment.