From 7fc344dc96008f277dacf5518b28447f3a598cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Mon, 15 Nov 2021 15:53:43 +0000 Subject: [PATCH] 8277028: Use service type documentation as fallback for @provides Reviewed-by: prappo --- .../formats/html/ModuleWriterImpl.java | 10 +++--- .../testModules/TestModuleServices.java | 33 +++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java index 878e1bd4920..e4dd2efd10d 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java @@ -763,12 +763,14 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW Content desc = new ContentBuilder(); if (display(providesTrees)) { description = providesTrees.get(srv); - desc.add((description != null && !description.isEmpty()) - ? HtmlTree.DIV(HtmlStyle.block, description) - : Entity.NO_BREAK_SPACE); + if (description != null && !description.isEmpty()) { + desc.add(HtmlTree.DIV(HtmlStyle.block, description)); + } else { + addSummaryComment(srv, desc); + } } else { desc.add(Entity.NO_BREAK_SPACE); - } + } // Only display the implementation details in the "all" mode. if (moduleMode == ModuleMode.ALL && !implSet.isEmpty()) { desc.add(new HtmlTree(TagName.BR)); diff --git a/test/langtools/jdk/javadoc/doclet/testModules/TestModuleServices.java b/test/langtools/jdk/javadoc/doclet/testModules/TestModuleServices.java index a371a466945..ed965ee937d 100644 --- a/test/langtools/jdk/javadoc/doclet/testModules/TestModuleServices.java +++ b/test/langtools/jdk/javadoc/doclet/testModules/TestModuleServices.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 8178067 8192007 8182765 8184205 + * @bug 8178067 8192007 8182765 8184205 8277028 * @summary tests the module's services, such as provides and uses * @modules jdk.javadoc/jdk.javadoc.internal.api * jdk.javadoc/jdk.javadoc.internal.tool @@ -93,6 +93,26 @@ public class TestModuleServices extends JavadocTester { public void testMethod2() {} }"""); mb.write(src); + mb = new ModuleBuilder(tb, "moduleServiceProviderNoDescription") + .comment(""" + This is another module that provides an implementation of a service. + @provides pkgService.Service""") + .requires("moduleService") + .provides("pkgService.Service", "pkgServiceProviderNoDesc.ServiceProviderNoDescription") + .classes("/**A Package that has a service provider.*/ package pkgServiceProviderNoDesc;") + .classes(""" + package pkgServiceProviderNoDesc; + public class ServiceProviderNoDescription implements pkgService.Service { + /** + * {@inheritDoc} + */ + public void testMethod1() {} + /** + * This is an internal implementation so the documentation will not be seen. + */ + public void testMethod2() {} + }"""); + mb.write(src); mb = new ModuleBuilder(tb, "moduleServiceUser") .comment(""" This module uses a service defined in another module. @@ -128,7 +148,8 @@ public class TestModuleServices extends JavadocTester { "-quiet", "-noindex", "--module-source-path", src.toString(), - "--module", "moduleService,moduleServiceProvider,moduleServiceUser,moduleServiceUserNoDescription", + "--module", "moduleService,moduleServiceProvider,moduleServiceProviderNoDescription", + "--module", "moduleServiceUser,moduleServiceUserNoDescription", "pkgService", "moduleServiceProvider/pkgServiceProvider", "moduleServiceUser/pkgServiceUser", "moduleServiceUserNoDescription/pkgServiceUserNoDescription"); checkExit(Exit.OK); @@ -139,6 +160,12 @@ public class TestModuleServices extends JavadocTester { ml" title="interface in pkgService">Service
Provides a service whose name is ServiceProvider.
"""); + checkOutput("moduleServiceProviderNoDescription/module-summary.html", true, + """ + +
+
A service Interface for service providers.
"""); checkOutput("moduleServiceUser/module-summary.html", true, """