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);
- csr of
-
JDK-8237826 DocTrees should provide getType(DocTreePath) method
-
- Resolved
-