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

Add getOutermostTypeElement to javax.lang.model utility class

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Adding new default method to an interface.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Add a getOutermostTypeElement convenience method to javax.lang.model.util.Elements.

      Problem

      The javax.lang.model API does not have a convenient way to access the outermost class or interface that may contain an element.

      Solution

      Add the method in question to the convenience interface intended to host such methods. A functional default implementation is included as part of the interface update.

      Specification

      /**
       * {@return the outermost type element an element is contained in
       * if such a containing element exists; otherwise returns {@code
       * null}}
       *
       * {@linkplain ModuleElement Modules} and {@linkplain
       * PackageElement packages} do <em>not</em> have a containing type
       * element and therefore {@code null} is returned for those kinds
       * of elements.
       *
       * A {@link NestingKind#TOP_LEVEL top-level} class or
       * interface is its own outermost type element.
       *
       * @implSpec
       * The default implementation of this method first checks the kind
       * of the argument. For elements of kind {@code PACKAGE}, {@code
       * MODULE}, and {@code OTHER}, {@code null} is returned. For
       * elements of other kinds, the element is examined to see if it
       * is a top-level class or interface. If so, that element is
       * returned; otherwise, the {@linkplain
       * Element#getEnclosingElement enclosing element} chain is
       * followed until a top-level class or interface is found. The
       * element for the eventual top-level class or interface is
       * returned.
       *
       * @param e the element being examined
       * @see Element#getEnclosingElement
       * @since 18
       */
      default TypeElement getOutermostTypeElement(Element e)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              ksrini Kumar Srinivasan
              Reviewed By:
              Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: