/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * User: anna
 * Date: 12-Jan-2010
 */
package com.intellij.refactoring.rename.naming;

import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;

public class AutomaticOverloadsRenamer extends AutomaticRenamer {
  public AutomaticOverloadsRenamer(PsiMethod method, String newName) {
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass != null) {
      final PsiMethod[] overloads = containingClass.findMethodsByName(method.getName(), false);
      for (PsiMethod overload : overloads) {
        if (overload != method && overload.findDeepestSuperMethods().length == 0) {
          myElements.add(overload);
          suggestAllNames(overload.getName(), newName);
        }
      }
    }
  }

  public String getDialogTitle() {
    return "Rename Overloads";
  }

  public String getDialogDescription() {
    return "Rename overloads to:";
  }

  @Override
  public String entityName() {
    return "Overload";
  }

  @Override
  public boolean isSelectedByDefault() {
    return true;
  }
}
@@ -21,9 +21,9 @@
 -201
-4
+6
  Jet
@@ -754,16 +754,58 @@
 iMethod;
+%0Aimport org.jetbrains.annotations.NotNull;
 %0A%0Apublic
@@ -864,16 +864,17 @@
 namer %7B%0A
+%0A
   public
@@ -900,16 +900,25 @@
 Renamer(
+@NotNull 
 PsiMetho
@@ -954,116 +954,12 @@
    f
-inal PsiClass containingClass = method.getContainingClass();%0A    if (containingClass != null) %7B%0A      final 
+or (
 PsiM
@@ -967,10 +967,8 @@
 thod
-%5B%5D
  ove
@@ -976,119 +976,35 @@
 load
-s = containingClass.findMethodsByName(method.getName(), false);%0A      for (PsiMethod overload : overloads
+ : getOverloads(method)
 ) %7B%0A
-  
     
@@ -1089,18 +1089,16 @@
         
-  
 myElemen
@@ -1115,18 +1115,16 @@
 rload);%0A
-  
         
@@ -1173,18 +1173,8 @@
 e);%0A
-        %7D%0A
     
@@ -1460,24 +1460,24 @@
 Default() %7B%0A
-
     return t
@@ -1484,10 +1484,286 @@
 rue;%0A  %7D
+%0A%0A  @NotNull%0A  protected PsiMethod%5B%5D getOverloads(@NotNull PsiMethod method) %7B%0A    PsiClass containingClass = method.getContainingClass();%0A    if (containingClass == null) return PsiMethod.EMPTY_ARRAY;%0A    return containingClass.findMethodsByName(method.getName(), false);%0A  %7D
 %0A%7D

make automatic overload renamer extensible