New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8272234: Pass originating elements from Filer to JavaFileManager #5076
Conversation
…mprovements to the test.
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
@lahodaj This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@lahodaj This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
/open |
@lahodaj @HostUserDetails{id=51319204, username='lahodaj', fullName='null'} this pull request is now open |
I guess this one needs a CSR right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
* given package-oriented location. | ||
* | ||
* <p>The provided {@code originatingFiles} represent files that | ||
* where in, an unspecified way, used to create the content of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling: first word should probably be were
, not where
.
* @throws IllegalStateException {@link #close} has been called | ||
* and this file manager cannot be reopened | ||
* @since 18 | ||
* @see Filer#createSourceFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 yes, cross-linking to Filer
is a good idea.
* name</a> in the specified package in the given location. | ||
* | ||
* <p>The provided {@code originatingFiles} represent files that | ||
* where in, an unspecified way, used to create the content of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling: were
JavaFileObject[] originatingFiles = Arrays.asList(originatingElements) | ||
.stream() | ||
.filter(el -> el instanceof Symbol) | ||
.map(el -> (Symbol) el) | ||
.map(sym -> switch (sym.kind) { | ||
case PCK -> { | ||
if (((PackageSymbol) sym).package_info == null) { | ||
yield null; | ||
} | ||
yield ((PackageSymbol) sym).package_info.classfile; | ||
} | ||
case MDL -> { | ||
ModuleSymbol msym = (ModuleSymbol) sym; | ||
yield msym.module_info.classfile != null ? msym.module_info.classfile | ||
: msym.module_info.sourcefile; | ||
} | ||
default -> sym.outermostClass().classfile; | ||
}) | ||
.filter(fo -> fo != null) | ||
.toArray(s -> new JavaFileObject[s]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged; it would be preferable if this mapping could be done in the standardized API.
@jddarcy has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
A CSR is needed and I'd happily advance a Proposed request to Provisional in its current form. |
I made some minor edits to the CSR and added myself as reviewer |
@lahodaj This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
default JavaFileObject getJavaFileForOutputForOriginatingFiles(Location location, | ||
String className, | ||
Kind kind, | ||
FileObject... originatingFiles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps explicitly state that null originatingFile or empty originatingFiles are no-ops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - how about the following?
7c11f10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec update looks fine.
* given package-oriented location. | ||
* | ||
* <p>The provided {@code originatingFiles} represent files that | ||
* were in, an unspecified way, used to create the content of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misplaced comma. should be were, in an unspecified way,
* @param location a package-oriented location | ||
* @param className the name of a class | ||
* @param kind the kind of file, must be one of {@link | ||
* JavaFileObject.Kind#SOURCE SOURCE} or {@link | ||
* JavaFileObject.Kind#CLASS CLASS} | ||
* @param originatingFiles the files which are contributing to this newly created file; | ||
* {@code null} is equivalent to empty {@code originatingFiles}, | ||
* meaning no known originating files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor/white-space) inconsistent indentation of @param
tags
JavaFileObject[] originatingFiles = Arrays.asList(originatingElements) | ||
.stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not start with Stream.of(originatingElements)
?
* questions. | ||
*/ | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be /*
not /**
. This is not a documentation comment for javadoc.
} | ||
List<String> options = List.of("-sourcepath", src.toString(), | ||
"-processor", "TestOriginatingElements$P", | ||
"-processorpath", System.getProperty("test.classes"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be enough. but note there is also test.class.path
.... one is just the output directory, the other is the full path.
ModuleElement mdl = processingEnv.getElementUtils().getModuleElement("m"); | ||
ModuleElement java_base = processingEnv.getElementUtils().getModuleElement("java.base"); | ||
PackageElement pack = processingEnv.getElementUtils().getPackageElement("p"); | ||
PackageElement lib1Pack = processingEnv.getElementUtils().getPackageElement("lib1"); | ||
PackageElement lib2Pack = processingEnv.getElementUtils().getPackageElement("lib2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strongly suggest using a local variable for processingEnv.getElementUtils()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recent commits all look good.
/integrate |
Going to push as commit 8907003.
Your commit was automatically rebased without conflicts. |
This is a first prototype of a patch that propagates originating elements from
Filer
(createSourceFile
/createClassFile
/createResource
) to the corresponding methods inJavaFileManager
. As file managers generally don't know aboutElement
s, theElement
s are first converted to their correspondingFileObject
s (if any). As the currently existing methods only take oneFileObject
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.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5076/head:pull/5076
$ git checkout pull/5076
Update a local copy of the PR:
$ git checkout pull/5076
$ git pull https://git.openjdk.java.net/jdk pull/5076/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5076
View PR using the GUI difftool:
$ git pr show -t 5076
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5076.diff