Skip to content

Commit 9df2422

Browse files
committed
Avoid unnecessary calls to findOverriddenMethod eclipse-jdt#1922
This speeds up the quick outline. Fixes eclipse-jdt#1922
1 parent 2213f68 commit 9df2422

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,20 @@ public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility)
136136
return null;
137137
}
138138

139+
Set<String> visited = new HashSet<>();
140+
139141
IType type= overriding.getDeclaringType();
140142
IType superClass= fHierarchy.getSuperclass(type);
141143
if (superClass != null) {
142-
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding);
144+
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding, visited);
143145
if (res != null) {
144146
if (!testVisibility || JavaModelUtil.isVisibleInHierarchy(res, type.getPackageFragment())) {
145147
return res;
146148
}
147149
}
148150
}
149151
for (IType intf : fHierarchy.getSuperInterfaces(type)) {
150-
IMethod res= findOverriddenMethodInHierarchy(intf, overriding);
152+
IMethod res= findOverriddenMethodInHierarchy(intf, overriding, visited);
151153
if (res != null) {
152154
return res; // methods from interfaces are always public and therefore visible
153155
}
@@ -160,23 +162,29 @@ public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility)
160162
* 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.
161163
* @param type The type to find methods in
162164
* @param overriding The overriding method
165+
* @param visited The types that were visited already
163166
* @return The first overridden method or <code>null</code> if no method is overridden
164167
* @throws JavaModelException if a problem occurs
165168
*/
166-
public IMethod findOverriddenMethodInHierarchy(IType type, IMethod overriding) throws JavaModelException {
169+
public IMethod findOverriddenMethodInHierarchy(IType type, IMethod overriding, Set<String> visited) throws JavaModelException {
170+
171+
if (!visited.add(type.getElementName())) {
172+
return null;
173+
}
174+
167175
IMethod method= findOverriddenMethodInType(type, overriding);
168176
if (method != null) {
169177
return method;
170178
}
171179
IType superClass= fHierarchy.getSuperclass(type);
172180
if (superClass != null) {
173-
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding);
181+
IMethod res= findOverriddenMethodInHierarchy(superClass, overriding, visited);
174182
if (res != null) {
175183
return res;
176184
}
177185
}
178186
for (IType superInterface : fHierarchy.getSuperInterfaces(type)) {
179-
IMethod res= findOverriddenMethodInHierarchy(superInterface, overriding);
187+
IMethod res= findOverriddenMethodInHierarchy(superInterface, overriding, visited);
180188
if (res != null) {
181189
return res;
182190
}

0 commit comments

Comments
 (0)