diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java index 9004aa45dd..f8441471cb 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java @@ -22,7 +22,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; @@ -233,17 +232,15 @@ private void collectCodeLenses(ITypeRoot typeRoot, IJavaElement[] elements, Coll } } String implementationsPreference = preferenceManager.getPreferences().getImplementationsCodeLens(); - if (("all".equals(implementationsPreference) || "types".equals(implementationsPreference)) && element instanceof IType type) { - if (type.isInterface() || Flags.isAbstract(type.getFlags())) { - CodeLens lens = getCodeLens(IMPLEMENTATION_TYPE, element, typeRoot); - if (lens != null) { - lenses.add(lens); - } + if (("all".equals(implementationsPreference) || "types".equals(implementationsPreference)) && element instanceof IType) { + CodeLens lens = getCodeLens(IMPLEMENTATION_TYPE, element, typeRoot); + if (lens != null) { + lenses.add(lens); } } if (("all".equals(implementationsPreference) || "methods".equals(implementationsPreference)) && element instanceof IMethod methodElement) { - if ((methodElement.getParent() instanceof IType parentType && parentType.isInterface()) || Flags.isAbstract(methodElement.getFlags())) { + if (methodElement.getParent() instanceof IType) { CodeLens lens = getCodeLens(IMPLEMENTATION_TYPE, element, typeRoot); if (lens != null) { lenses.add(lens); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java index 9efa99a91f..73d6a6252a 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java @@ -236,6 +236,28 @@ public void testEnableImplementationsCodeLensSymbols() throws Exception { assertEquals(type, "implementations"); } + @Test + public void testEnableImplementationsCodeLensSymbolsForBaseTypes() throws Exception { + Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_KEY, "all")); + Mockito.reset(preferenceManager); + when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses); + handler = new CodeLensHandler(preferenceManager); + + String payload = createCodeLensSymbolsRequest("src/java/Foo.java"); + CodeLensParams codeLensParams = getParams(payload); + String uri = codeLensParams.getTextDocument().getUri(); + assertFalse(uri.isEmpty()); + + //when + List result = handler.getCodeLensSymbols(uri, monitor); + + //then + assertEquals(6, result.size()); + @SuppressWarnings("unchecked") + long implementations = result.stream().filter(cl -> "implementations".equals(((List) cl.getData()).get(2))).count(); + assertEquals(3, implementations); + } + @Test public void testDisableImplementationsCodeLensSymbols() throws Exception { Preferences noImplementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_KEY, "types"));