protected void performRenameInner(PsiElement element, String newName) {
   final RenamePsiElementProcessor elementProcessor =
       RenamePsiElementProcessor.forElement(element);
   final RenameProcessor renameProcessor =
       new RenameProcessor(
           myProject,
           element,
           newName,
           elementProcessor.isToSearchInComments(element),
           elementProcessor.isToSearchForTextOccurrences(element)) {
         @Override
         public void doRun() {
           try {
             super.doRun();
           } finally {
             restoreCaretOffsetAfterRename();
           }
         }
       };
   for (AutomaticRenamerFactory factory :
       Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
     if (factory.getOptionName() != null && factory.isApplicable(element)) {
       renameProcessor.addRenamerFactory(factory);
     }
   }
   renameProcessor.run();
 }
Exemplo n.º 2
0
  @NotNull
  public UsageInfo[] findUsages() {
    myRenamers.clear();
    ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();

    List<PsiElement> elements = new ArrayList<PsiElement>(myAllRenames.keySet());
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < elements.size(); i++) {
      PsiElement element = elements.get(i);
      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;
  }