Skip to content

Commit b121a6e

Browse files
mickaelistriadatho7561
authored andcommitted
[Search] prefer returning actual member method (instead of similar one)
1 parent 940cb9b commit b121a6e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717
import java.util.Map;
1818
import java.util.Objects;
19+
import java.util.Optional;
1920
import java.util.Set;
2021
import java.util.stream.Collectors;
2122
import java.util.stream.Stream;
@@ -284,7 +285,7 @@ private IMethod getJavaElementForMethodDeclaration(IType currentType, MethodDecl
284285

285286
IMethod result = currentType.getMethod(getName(), Stream.of(getParameterTypes()).map(SignatureUtils::getSignature).toArray(String[]::new));
286287
if (result.exists()) {
287-
return result;
288+
return declaredMethod(result).orElse(result);
288289
}
289290
List<SingleVariableDeclaration> p = methodDeclaration.parameters();
290291
String[] params = p.stream() //
@@ -299,18 +300,19 @@ private IMethod getJavaElementForMethodDeclaration(IType currentType, MethodDecl
299300
if (result.exists()) {
300301
return result;
301302
}
303+
return declaredMethod(result).orElse(null);
304+
}
302305

306+
private Optional<IMethod> declaredMethod(IMethod method) {
303307
IMethod[] methods = null;
304308
try {
305-
methods = currentType.getMethods();
309+
methods = method.getDeclaringType().getMethods();
306310
} catch (JavaModelException e) {
307311
// declaring type doesn't exist
308-
return null;
312+
return Optional.empty();
309313
}
310-
IMethod[] candidates = Member.findMethods(result, methods);
311-
if (candidates == null || candidates.length == 0)
312-
return null;
313-
return candidates[0];
314+
IMethod[] candidates = Member.findMethods(method, methods);
315+
return candidates == null || candidates.length == 0 ? Optional.empty() : Optional.of(candidates[0]);
314316
}
315317

316318
private IMethod resolved(IMethod from) {

0 commit comments

Comments
 (0)