RFR: JDK-8320200: Use Elements predicates for record constructors to improve print output

Joe Darcy darcy at openjdk.org
Tue Dec 12 02:52:42 UTC 2023


On Tue, 12 Dec 2023 02:47:18 GMT, Joe Darcy <darcy at openjdk.org> wrote:

> Please review this small increase for source fidelity by customizing the printing processor output for record compact constructors.

For a simple record like:


public record ComplexRecord(double real, double imaginary) {
    /**
     * Document the ctor.
     */
   ComplexRecord {
        this.real = real;
        this.imaginary = imaginary;
    }
}


the current printing processor output is


public record ComplexRecord(double real, double imaginary) {
  private final double real;
  private final double imaginary;

  /**
   * Document the ctor.
   */
  ComplexRecord(double real,
    double imaginary);

  public final java.lang.String toString();

  public final int hashCode();

  public final boolean equals(java.lang.Object o);

  public double real();

  public double imaginary();
}


and after this change it will be


public record ComplexRecord(double real, double imaginary) {
  private final double real;
  private final double imaginary;

  /**
   * Document the ctor.
   */
  ComplexRecord {} /* compact constructor */ ;

  public final java.lang.String toString();

  public final int hashCode();

  public final boolean equals(java.lang.Object o);

  public double real();

  public double imaginary();
}


All langtools regression tests pass with this change.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/17073#issuecomment-1851217614


More information about the compiler-dev mailing list