RFR: 8272234: Pass originating elements from Filer to JavaFileManager [v2]

Jonathan Gibbons jjg at openjdk.java.net
Fri Oct 15 22:10:52 UTC 2021


On Fri, 15 Oct 2021 11:56:14 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> This is a first prototype of a patch that propagates originating elements from `Filer` (`createSourceFile`/`createClassFile`/`createResource`) to the corresponding methods in `JavaFileManager`. As file managers generally don't know about `Element`s, the `Element`s are first converted to their corresponding `FileObject`s (if any). As the currently existing methods only take one `FileObject` as a sibling of the newly created file, a new set of methods is proposed that take multiple originating files.
>> 
>> Any feedback on this prototype would be welcome.
>
> Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 16 commits:
> 
>  - Javadoc improvements.
>  - Merge branch 'master' into ap-keep-originating-elements
>  - Cleanup.
>  - Improving testing
>  - Updating @since
>  - Merge branch 'master' into ap-keep-originating-elements
>  - Another attempt to fix the test.
>  - More attempts to fix the test.
>  - Attempting to fix test.
>  - Adding @since
>  - ... and 6 more: https://git.openjdk.java.net/jdk/compare/4cb7124c...9396bbb4

Nice solution overall to an awkward problem, as regards naming.
Yes, the new name is awkward and long, but there does not seem to be a satisfactory alternative using overloading, and accepting that, there is a reasonable correspondence between the terms "originating elements" in `Filer` and "originating files" here.

src/java.compiler/share/classes/javax/tools/JavaFileManager.java line 348:

> 346:      *
> 347:      * <p>The provided {@code originatingFiles} represent files that
> 348:      * where in, an unspecified way, used to create the content of

spelling: first work should probably be `were`, not `where`.

src/java.compiler/share/classes/javax/tools/JavaFileManager.java line 374:

> 372:      * and this file manager cannot be reopened
> 373:      * @since 18
> 374:      * @see Filer#createSourceFile

�� yes, cross-linking to `Filer` is a good idea.

src/java.compiler/share/classes/javax/tools/JavaFileManager.java line 482:

> 480:      *
> 481:      * <p>The provided {@code originatingFiles} represent files that
> 482:      * where in, an unspecified way, used to create the content of

spelling: `were`

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java line 549:

> 547:                 })
> 548:                 .filter(fo -> fo != null)
> 549:                 .toArray(s -> new JavaFileObject[s]);

@jddarcy this is an example of why it would be good to have an API method in the Language Model world to get the "source" from which an `Element` was obtained, where "source" means either a .class or a .java file ... in other words, the `Symbol.classfile` field accessed in this code.

-------------

Marked as reviewed by jjg (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5076


More information about the compiler-dev mailing list