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

DocTrees should provide getType(DocTreePath) method

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 15
    • tools
    • None
    • binary
    • minimal
    • a new method is added
    • Java API

      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);

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

              Created:
              Updated:
              Resolved: