Skip to content

No new line break for some at-sign@ in Javadoc comment #1249

Description

@cindy-peng

We have a string as:

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* <p> Sample code:
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* try (EchoServiceClient echoServiceClient =
*     EchoServiceClient.create()) {
*   EchoResponse response =
*       echoServiceClient.chat();
* }
* }</pre>
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
* @InternalApi This method is internal used only. Please do not use directly.
*/

After running java-format on the above string, the Javadoc comment gets reformatted as:

// AUTO-GENERATED DOCUMENTATION AND METHOD.
  /**
   * Sample code:
   *
   * <pre>{@code
   * // This snippet has been automatically generated and should be regarded as a code template only.
   * try (EchoServiceClient echoServiceClient =
   *     EchoServiceClient.create()) {
   *   EchoResponse response =
   *       echoServiceClient.chat();
   * }
   * }</pre>
   *
   * @param request The request object containing all of the parameters for the API call.
   * @throws com.google.api.gax.rpc.ApiException if the remote call fails @InternalApi This method
   *     is internal used only. Please do not use directly.
   */

Notice the line break before @InternalApi was removed and a line break was added after @InternalApi This method. This makes the method comments hard to read.
Could you please help investigate?
Thank you!

Activity

  1. tbroyer commented on Apr 16, 2025

    @tbroyer
    Contributor

    Your custom @InternalApi tag is treated like an unescaped annotation by Google Java Format. If you can make it start with a lowercase, it would consider it as a tag:

    // We ensure elsewhere that we match this only at the beginning of a line.
    // Only match tags that start with a lowercase letter, to avoid false matches on unescaped
    // annotations inside code blocks.
    // Match "@param <T>" specially in case the <T> is a <P> or other HTML tag we treat specially.
    private static final Pattern FOOTER_TAG_PATTERN = compile("^@(param\\s+<\\w+>|[a-z]\\w*)");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions