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

DocTrees should provide getType(DocTreePath) method

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 15
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      binary
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      a new method is added
    • Interface Kind:
      Java API

      Description

      Summary

      A new method is added to com.sun.source.util.DocTrees to obtain the TypeMirror representing the type referred to by a node represented by a DocTreePath.

      Problem

      The DocTrees API currently provides a getElement(DocTreePath) method that returns the Element referred to by a DocTree node. However, parameterized generic types such as java.util.List<String> cannot be represented as Elements, so converting the return value to a type returns the raw type.

      Solution

      Provide a new method to the DocTrees class that returns the TypeMirror instance representing the type referred to by a DocTreePath, or null if the DocTreePath does not refer to a type. If the referred type is a parameterized type the type arguments are represented in the returned TypeMirror instance.

      Specification

      The following method is added to the DocTrees class:

      /**
       * Returns the language model type referred to by the leaf node of the given
       * {@link DocTreePath}, or {@code null} if unknown. This method usually
       * returns the same value as {@code getElement(path).asType()} for a
       * {@code path} argument for which {@link #getElement(DocTreePath)} returns
       * a non-null value, but may return a type that includes additional
       * information, such as a parameterized generic type instead of a raw type.
       *
       * @param path the path for the tree node
       * @return the referenced type, or null
       *
       * @since 15
       */
      public abstract TypeMirror getType(DocTreePath path);

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              hannesw Hannes Wallnoefer
              Reviewed By:
              Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: