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

Trees.getElement should work not only for declaration trees, but also for use-trees

XMLWordPrintable

    • b91
    • Verified

      It would be useful to javac Plugins and AnnoationProcessors if Trees.getElement would respond with a Element/Symbol also for non-declarations, similarly to current DocTrees.getElement(TreePath, ReferenceTree) does. For example, consider this snippet:
      StringBuilder sb = new StringBuilder();
      sb.append("");

      Consider a plugin that wants to find out which method is actually invoked by "sb.append". Right now, the information is stored in the javac's trees, there is no easy way to read it out without touching javac internals. Probably the easiest way right now is to take the Trees.getTypeMirror for "sb.append" and Trees.getTypeMirror for "sb", and iterate the site's methods looking for one that would match the ExecutableType, which is quite complex.

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: