RFR: JDK-8312418: Add Elements.getEnumConstantBody [v2]

Joe Darcy darcy at openjdk.org
Wed Aug 23 21:05:23 UTC 2023

On Wed, 23 Aug 2023 09:14:40 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Trivial implementation to get feedback on the proposed API.
> Joe Darcy has updated the pull request incrementally with one additional commit since the last revision:
>   Update printing processor.

A few explanatory notes on the changes in the printing processor. Consider an enum like

public enum BodyEnum {
    GOLGI(true) {
        public boolean isOrganelle() {return true;}

    HEAVENLY(true) {
        public boolean isCelestial() {return true;}

    private BodyEnum(boolean predicate) {
        this.predicate = predicate;

    private boolean predicate;
    public static int field = 42;
    public void method() {return;}

which uses enum constants with bodies. If this enum class is printed from a class file, but not source code, the output is like:

public enum BodyEnum permits BodyEnum$1, BodyEnum$2 {


  private boolean predicate;
  public static int field;

  public static BodyEnum[] values();

  public static BodyEnum valueOf(java.lang.String arg0);

  private BodyEnum(boolean arg0);

  public void method();

This does reflect how javac currently lowers an enum to a class file, but the permits information is not really helpful and is better to be elided, as the extra check now does.

If one goes out of the way to explicitly request printing of the anonymous class used for an enum contanst, the output is similar to:

$ jdk-21/bin/javac -Xprint 'BodyEnum$1'
new BodyEnum(java.lang.String arg0,
  int arg1,
  boolean arg2) {

  public boolean isOrganelle();

While this is reasonable for a general anonymous class, it isn't helpful for an enum body and I think it is best to just have no output in this case.

Generally we haven't tested the exact printing processor output and I think it is best if we continue that policy here.


PR Comment: https://git.openjdk.org/jdk/pull/14939#issuecomment-1690634306

More information about the compiler-dev mailing list