From 3f28f21029323516f1ef7fd658ee16c1fe744850 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Wed, 10 Apr 2024 17:41:34 +0200 Subject: [PATCH] Resolve @inheritTag to most direct parent declaring a doc --- .../jdt/internal/core/DOMCodeSelector.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DOMCodeSelector.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DOMCodeSelector.java index 74a40c5b472..b72a3aa61f6 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DOMCodeSelector.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DOMCodeSelector.java @@ -164,15 +164,18 @@ public IJavaElement[] codeSelect(int offset, int length) throws JavaModelExcepti if (typeBinding.getSuperclass() != null) { types.add(typeBinding.getSuperclass()); } - var overridenMethods = types.stream().flatMap(type -> Arrays.stream(type.getDeclaredMethods())) - .filter(m -> methodBinding.overrides(m)) // should resolve to the 1st parent method which has doc - .map(IMethodBinding::getJavaElement) - .filter(Objects::nonNull) - .distinct() - .findFirst() - .map(element -> new IJavaElement[] { element }); - if (overridenMethods.isPresent()) { - return overridenMethods.get(); + while (!types.isEmpty()) { + ITypeBinding type = types.remove(0); + for (IMethodBinding m : Arrays.stream(type.getDeclaredMethods()).filter(methodBinding::overrides).toList()) { + if (m.getJavaElement() instanceof IMethod methodElement && methodElement.getJavadocRange() != null) { + return new IJavaElement[] { methodElement }; + } else { + types.addAll(Arrays.asList(type.getInterfaces())); + if (type.getSuperclass() != null) { + types.add(type.getSuperclass()); + } + } + } } } IJavaElement element = methodBinding.getJavaElement();