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

DocTreeScanner does not dive into AttributeTree.getValue() and LiteralTree.getBody()

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      Custom subclasses that do not override visitAttribute or visitLiteral may visit DocTrees, children of the AttributeNode or LiteralNode, which were not visited before, and which were silently ignored. This may require adjustments to these subclasses. Such adjustments should work on older JDKs as well.
      Show
      Custom subclasses that do not override visitAttribute or visitLiteral may visit DocTrees, children of the AttributeNode or LiteralNode, which were not visited before, and which were silently ignored. This may require adjustments to these subclasses. Such adjustments should work on older JDKs as well.
    • Interface Kind:
      Java API

      Description

      Summary

      com.sun.source.util.DocTreeScanner#visitAttribute will scan over com.sun.source.doctree.AttributeNode#getValue(), and com.sun.source.util.DocTreeScanner#visitLiteral will scan over com.sun.source.doctree.LiteralNode#getBody().

      Problem

      The visit methods in tree scanners in com.sun.source.util (TreeScanner and DocTreeScanner) are generally expected to scan over all the subnodes of the given node. That is, however, not the case of com.sun.source.util.DocTreeScanner#visitAttribute and com.sun.source.util.DocTreeScanner#visitLiteral, which are not scanning through the children of the corresponding AttributeNode and LiteralNode.

      Solution

      Fix the DocTreeScanner to scan over the children of AttributeNode and LiteralNode.

      Specification

      The specific change is as follows:

      diff --git a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
      --- a/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
      +++ b/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java
      @@ -122,19 +122,19 @@
       /* ***************************************************************************
        * Visitor methods
        ****************************************************************************/
      
           /**
      -     * {@inheritDoc} This implementation returns {@code null}.
      +     * {@inheritDoc} This implementation scans the children in left to right order.
            *
            * @param node  {@inheritDoc}
            * @param p  {@inheritDoc}
            * @return the result of scanning
            */
           @Override
           public R visitAttribute(AttributeTree node, P p) {
      -        return null;
      +        return scan(node.getValue(), p);
           }
      
           /**
            * {@inheritDoc} This implementation scans the children in left to right order.
            *
      @@ -309,19 +309,19 @@
               r = scanAndReduce(node.getLabel(), p, r);
               return r;
           }
      
           /**
      -     * {@inheritDoc} This implementation returns {@code null}.
      +     * {@inheritDoc} This implementation scans the children in left to right order.
            *
            * @param node  {@inheritDoc}
            * @param p  {@inheritDoc}
            * @return the result of scanning
            */
           @Override
           public R visitLiteral(LiteralTree node, P p) {
      -        return null;
      +        return scan(node.getBody(), p);
           }
      
           /**
            * {@inheritDoc} This implementation scans the children in left to right order.
            *
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlahoda Jan Lahoda
                Reporter:
                jlahoda Jan Lahoda
                Reviewed By:
                Jonathan Gibbons, Vicente Arturo Romero Zaldivar
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: