4

I'm trying to use Java Records instead of Lombok @Data:

/**
 * User data.
 *
 * @param id    user ID.
 * @param roles user roles.
 */
public record User(
        UUID id,
        Set<UserRoleGrantedAuthority> roles
) { /* ... */ }

But IntelliJ IDEA (2021.2.3) doesn't provide information about record fields in hover tooltips. Though it shows information about whole record class (with all its fields) when I move mouse cursor over the class name.

Am I doing something wrong, or the IDE still doesn't support it yet?

ertaquo
  • 130
  • 1
  • 1
  • 9
  • Try putting some JavaDoc on the field directly, e.g. `record User(/** The User ID */ UUID id, ...)`. – Thomas Nov 17 '21 at 06:34
  • I tried, but IDEA tells about "Dangling Javadoc comment" and doesn't show the information in the field tooltip. – ertaquo Nov 17 '21 at 06:37
  • Hmm, I can't tell about IntelliJ but it works in Eclipse, so either of the 2 is not sticking to the spec. :) – Thomas Nov 17 '21 at 06:40
  • Btw, this might be relevant (not sure which version of IntelliJ you're using): https://stackoverflow.com/questions/61445534/how-to-document-java-record-parameters – Thomas Nov 17 '21 at 06:42
  • @Thomas unless the JavaDoc spec changed, that's indeed a dangling JavaDoc comment. – jwenting Nov 17 '21 at 06:56
  • @jwenting good to know, then Eclipse is more lenient about this. – Thomas Nov 17 '21 at 07:17
  • 1
    @Thomas it might even be that Eclipse implemented it thinking it'd become part of the specs :) – jwenting Nov 17 '21 at 07:52
  • [*JEP 395: Records*](https://openjdk.java.net/jeps/395) describes the member fields list in parentheses as a “header”, not parameters. And the JEP makes no mention of how to handle Javadoc, unfortunately. [`RecordHeader`](https://docs.oracle.com/javase/specs/jls/se17/html/jls-8.html#jls-RecordHeader) is defined in the Java Language Spec. – Basil Bourque Nov 17 '21 at 08:21

0 Answers0