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)
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)
- duplicates
-
JDK-8224922 Access JavaFileObject from Element(s)
- Resolved
- relates to
-
JDK-8224233 provide link to JavaFileObject from Element
- Closed