Skip to content

Commit

Permalink
Avoid unnecessary calls to findOverriddenMethod eclipse-jdt#1922
Browse files Browse the repository at this point in the history
This speeds up the quick outline.

Fixes eclipse-jdt#1922
  • Loading branch information
fedejeanne committed Jan 10, 2025
1 parent 2213f68 commit 9df2422
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility)
return null;
}

Set<String> visited = new HashSet<>();

IType type= overriding.getDeclaringType();
IType superClass= fHierarchy.getSuperclass(type);
if (superClass != null) {
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding);
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding, visited);
if (res != null) {
if (!testVisibility || JavaModelUtil.isVisibleInHierarchy(res, type.getPackageFragment())) {
return res;
}
}
}
for (IType intf : fHierarchy.getSuperInterfaces(type)) {
IMethod res= findOverriddenMethodInHierarchy(intf, overriding);
IMethod res= findOverriddenMethodInHierarchy(intf, overriding, visited);
if (res != null) {
return res; // methods from interfaces are always public and therefore visible
}
Expand All @@ -160,23 +162,29 @@ public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility)
* With generics it is possible that 2 methods in the same type are overidden at the same time. In that case, the first overridden method found is returned.
* @param type The type to find methods in
* @param overriding The overriding method
* @param visited The types that were visited already
* @return The first overridden method or <code>null</code> if no method is overridden
* @throws JavaModelException if a problem occurs
*/
public IMethod findOverriddenMethodInHierarchy(IType type, IMethod overriding) throws JavaModelException {
public IMethod findOverriddenMethodInHierarchy(IType type, IMethod overriding, Set<String> visited) throws JavaModelException {

if (!visited.add(type.getElementName())) {
return null;
}

IMethod method= findOverriddenMethodInType(type, overriding);
if (method != null) {
return method;
}
IType superClass= fHierarchy.getSuperclass(type);
if (superClass != null) {
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding);
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding, visited);
if (res != null) {
return res;
}
}
for (IType superInterface : fHierarchy.getSuperInterfaces(type)) {
IMethod res= findOverriddenMethodInHierarchy(superInterface, overriding);
IMethod res= findOverriddenMethodInHierarchy(superInterface, overriding, visited);
if (res != null) {
return res;
}
Expand Down

0 comments on commit 9df2422

Please sign in to comment.