Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8235590

Extend javax.lang.model to cover binding variables

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API

      Description

      Summary

      The javax.lang.model.element.ElementKind models various local variables, but, with the recent addition of binding variables (for pattern matching), a new ElementKind was not added. The proposal here is to add a new ElementKind for binding variables.

      Problem

      Various types of variables local to methods have their own enum constant in ElementKind, but binding variables don't.

      Solution

      A new enum constant, BINDING_VARIABLE, is added into the ElementKind.

      Specification

      diff --git a/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java b/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
      --- a/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
      +++ b/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
      @@ -137,7 +137,24 @@
            */
           @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
                                        essentialAPI=false)
      -    RECORD_COMPONENT;
      +    RECORD_COMPONENT,
      +
      +    /**
      +     * {@preview Associated with pattern matching for {@code
      +     * instanceof}, a preview feature of the Java language.
      +     *
      +     *           This enum constant is associated with <i>pattern
      +     *           matching for {@code instanceof}</i>, a preview
      +     *           feature of the Java language. Preview features
      +     *           may be removed in a future release, or upgraded to permanent
      +     *           features of the Java language.}
      +     *
      +     * A binding variable in a pattern .
      +     * @since 14
      +     */
      +    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF,
      +                                 essentialAPI=false)
      +    BINDING_VARIABLE;
      
           /**
            * Returns {@code true} if this is a kind of class:
      diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
      --- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
      +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
      @@ -136,4 +136,20 @@
           public R visitTypeAsRecord(TypeElement e, P p) {
               return defaultAction(e, p);
           }
      +
      +    /**
      +     * Visits a {@code BINDING_VARIABLE} variable element.
      +     *
      +     * @implSpec This implementation calls {@code defaultAction}.
      +     *
      +     * @param e {@inheritDoc}
      +     * @param p {@inheritDoc}
      +     * @return  the result of {@code defaultAction}
      +     *
      +     * @since 14
      +     */
      +    @Override
      +    public R visitVariableAsBindingVariable(VariableElement e, P p) {
      +        return defaultAction(e, p);
      +    }
       }
      diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
      --- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
      +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
      @@ -360,6 +363,21 @@
           }
      
           /**
      +     * Visits a {@code BINDING_VARIABLE} variable element.
      +     *
      +     * @implSpec This implementation calls {@code visitUnknown}.
      +     *
      +     * @param e the element to visit
      +     * @param p a visitor-specified parameter
      +     * @return  the result of {@code visitUnknown}
      +     *
      +     * @since 14
      +     */
      +    public R visitVariableAsBindingVariable(VariableElement e, P p) {
      +        return visitUnknown(e, p);
      +    }
      +
      +    /**
            * {@inheritDoc}
            *
            * @implSpec This implementation dispatches to the visit method

      A specdiff is also attached, and also available at the following location for convenience: http://cr.openjdk.java.net/~jlahoda/8235541/specdiff.00/overview-summary.html

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              darcy Joe Darcy
              Reviewed By:
              Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: