mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] make automatic overload renamer extensible
This commit is contained in:
+15
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -22,17 +22,15 @@ package com.intellij.refactoring.rename.naming;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
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 AutomaticOverloadsRenamer(@NotNull PsiMethod method, String newName) {
|
||||
for (PsiMethod overload : getOverloads(method)) {
|
||||
if (overload != method && overload.findDeepestSuperMethods().length == 0) {
|
||||
myElements.add(overload);
|
||||
suggestAllNames(overload.getName(), newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,4 +52,11 @@ public class AutomaticOverloadsRenamer extends AutomaticRenamer {
|
||||
public boolean isSelectedByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiMethod[] getOverloads(@NotNull PsiMethod method) {
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) return PsiMethod.EMPTY_ARRAY;
|
||||
return containingClass.findMethodsByName(method.getName(), false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user