Search in sources :

Example 6 with AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory in project intellij-community by JetBrains.

the class RenameDialog method createCheckboxes.

protected void createCheckboxes(JPanel panel, GridBagConstraints gbConstraints) {
    gbConstraints.insets = JBUI.insetsBottom(4);
    gbConstraints.gridwidth = 1;
    gbConstraints.gridx = 0;
    gbConstraints.weighty = 0;
    gbConstraints.weightx = 1;
    gbConstraints.fill = GridBagConstraints.BOTH;
    myCbSearchInComments = new NonFocusableCheckBox();
    myCbSearchInComments.setText(RefactoringBundle.getSearchInCommentsAndStringsText());
    myCbSearchInComments.setSelected(true);
    panel.add(myCbSearchInComments, gbConstraints);
    gbConstraints.insets = JBUI.insetsBottom(4);
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.gridx = 1;
    gbConstraints.weightx = 1;
    gbConstraints.fill = GridBagConstraints.BOTH;
    myCbSearchTextOccurrences = new NonFocusableCheckBox();
    myCbSearchTextOccurrences.setText(RefactoringBundle.getSearchForTextOccurrencesText());
    myCbSearchTextOccurrences.setSelected(true);
    panel.add(myCbSearchTextOccurrences, gbConstraints);
    if (!TextOccurrencesUtil.isSearchTextOccurencesEnabled(myPsiElement)) {
        myCbSearchTextOccurrences.setEnabled(false);
        myCbSearchTextOccurrences.setSelected(false);
        myCbSearchTextOccurrences.setVisible(false);
    }
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        if (factory.isApplicable(myPsiElement) && factory.getOptionName() != null) {
            gbConstraints.insets = JBUI.insetsBottom(4);
            gbConstraints.gridwidth = myAutoRenamerFactories.size() % 2 == 0 ? 1 : GridBagConstraints.REMAINDER;
            gbConstraints.gridx = myAutoRenamerFactories.size() % 2;
            gbConstraints.weightx = 1;
            gbConstraints.fill = GridBagConstraints.BOTH;
            JCheckBox checkBox = new NonFocusableCheckBox();
            checkBox.setText(factory.getOptionName());
            checkBox.setSelected(factory.isEnabled());
            panel.add(checkBox, gbConstraints);
            myAutoRenamerFactories.put(factory, checkBox);
        }
    }
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox)

Example 7 with AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory in project intellij-community by JetBrains.

the class RenameProcessor method findUsages.

@Override
@NotNull
public UsageInfo[] findUsages() {
    myRenamers.clear();
    ArrayList<UsageInfo> result = new ArrayList<>();
    List<PsiElement> elements = new ArrayList<>(myAllRenames.keySet());
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < elements.size(); i++) {
        PsiElement element = elements.get(i);
        if (element == null) {
            LOG.error("primary: " + myPrimaryElement + "; renamers: " + myRenamers);
            continue;
        }
        final String newName = myAllRenames.get(element);
        final UsageInfo[] usages = RenameUtil.findUsages(element, newName, mySearchInComments, mySearchTextOccurrences, myAllRenames);
        final List<UsageInfo> usagesList = Arrays.asList(usages);
        result.addAll(usagesList);
        for (AutomaticRenamerFactory factory : myRenamerFactories) {
            if (factory.isApplicable(element)) {
                myRenamers.add(factory.createRenamer(element, newName, usagesList));
            }
        }
        for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
            if (factory.getOptionName() == null && factory.isApplicable(element)) {
                myRenamers.add(factory.createRenamer(element, newName, usagesList));
            }
        }
    }
    UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
    usageInfos = UsageViewUtil.removeDuplicatedUsages(usageInfos);
    return usageInfos;
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) UsageInfo(com.intellij.usageView.UsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) RelatedUsageInfo(com.intellij.refactoring.util.RelatedUsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory in project intellij-community by JetBrains.

the class AbstractJavaFXRenameTest method doRenameWithAutomaticRenamers.

protected void doRenameWithAutomaticRenamers(PsiElement elementAtCaret, String newName) {
    final RenameProcessor processor = new RenameProcessor(getProject(), elementAtCaret, newName, false, false);
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        processor.addRenamerFactory(factory);
    }
    processor.run();
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor)

Aggregations

AutomaticRenamerFactory (com.intellij.refactoring.rename.naming.AutomaticRenamerFactory)8 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)5 PsiClass (com.intellij.psi.PsiClass)2 UsageInfo (com.intellij.usageView.UsageInfo)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceBundleRenamerFactory (com.intellij.lang.properties.refactoring.rename.ResourceBundleRenamerFactory)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 RefactoringEventData (com.intellij.refactoring.listeners.RefactoringEventData)1 AutomaticRenamer (com.intellij.refactoring.rename.naming.AutomaticRenamer)1 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)1 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)1 RelatedUsageInfo (com.intellij.refactoring.util.RelatedUsageInfo)1 NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)1 MultiMap (com.intellij.util.containers.MultiMap)1 ArrayList (java.util.ArrayList)1