Skip to content

Support record classes in annotation processor #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xeals opened this issue Nov 15, 2021 · 2 comments
Closed

Support record classes in annotation processor #52

xeals opened this issue Nov 15, 2021 · 2 comments
Assignees
Milestone

Comments

@xeals
Copy link

xeals commented Nov 15, 2021

Record classes are unmodifiable data class introduced in Java 16 and included in the recent LTS version Java 17. Since records are a new syntax for Java, they generate an ElementKind.RECORD AST element instead of ElementKind.CLASS and are not supported by the current visitor.

Javadoc for a record is the same as a regular class, except it may include @param fields referring to record components:

/**
 * Example class.
 *
 * @param a first component input
 * @param b second input
 */
public class Foo(boolean a, String b) {

  /** Alternate constructor */
  public Foo(boolean a) {
    this(a, null);
  }
}

General thoughts:

  • As best as I can tell, the compiler doesn't attach any docs to the generated fields or methods, or to the primary constructor
  • There's no way to directly comment the record components

Depending on how an implementation might balance representation vs. intent:

  • The class docs could be re-applied to the primary constructor, which can be determined by the GENERATED or RECORD flags set on the method (which I think is specified, but I can't find the exact mention in the JVM spec)
  • @param tags from the primary constructor could be applied to the fields and/or methods
@dnault dnault added this to the 0.14.0 milestone Jan 1, 2022
@dnault dnault self-assigned this Jan 1, 2022
@dnault dnault modified the milestones: 0.14.0, 0.13.0 Jan 2, 2022
@dnault
Copy link
Owner

dnault commented Jan 2, 2022

The 0.13.0 release will add basic support for records. Record class docs will be retained, as well as docs for secondary constructors and other methods and fields defined in the record.

There will also be a new method ClassJavadoc.getRecordComponents() that returns any @param tags from the class docs.

I filed #60 for attaching docs to the canonical constructor and generated component accessors.

dnault added a commit that referenced this issue Jan 2, 2022
@see on classes appears under other #59

* Retain javadoc for record classes.
* Add ClassJavadoc.getRecordComponents() which returns any "param" tags in the class doc.

* ClassJavadoc.getSeeAlso() now returns the "see" tags (previously they were lumped in with getOther())
@dnault dnault closed this as completed Jan 2, 2022
@dnault
Copy link
Owner

dnault commented Jan 2, 2022

Version 0.13.0 with basic support for records is now live on Maven Central.

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

No branches or pull requests

2 participants