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

Provide access to JavaFileObject(s) for an Element

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • None
    • tools
    • None

      It is not currently easy to determine the JavaFileObject for the source file for class file (if any) from which an element may have been read. This information is known to javac but is not available on any public API. While it is possible to guess the location, it would be better to expose the information known to javac, without the client having to break into javac internals.

      There is currently no significant intersection between the java.tools API (JSR 199) and the Language Model API (JSR 269.) With that in mind, a reasonable place to make the information available would be on com.sun.source.util.JavacTask. It could be a method of the form
          JavaFileObject getFileObject(Element)
      such that the method returns the JavaFileObject for the module-info.* file for a ModuleElement (if any), the package-info.* for a PackageElement (if any), the source or class file for a type element. For other kinds of elements, it could return null, or throw ILA, or return the result for the enclosing type element. (TBD)

            darcy Joe Darcy
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: