Skip to content
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

Closed
wants to merge 28 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Aug 10, 2021

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 Elements, the Elements are first converted to their corresponding FileObjects (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.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issues

  • JDK-8272234: Pass originating elements from Filer to JavaFileManager
  • JDK-8275508: Pass originating elements from Filer to JavaFileManager (CSR) ⚠️ Issue is not open.

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

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 10, 2021

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 10, 2021
@openjdk
Copy link

openjdk bot commented Aug 10, 2021

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Aug 10, 2021
@mlbridge
Copy link

mlbridge bot commented Aug 10, 2021

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 7, 2021

@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!

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 6, 2021

@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 pull request command.

@bridgekeeper bridgekeeper bot closed this Oct 6, 2021
@lahodaj
Copy link
Contributor Author

lahodaj commented Oct 6, 2021

/open

@openjdk openjdk bot reopened this Oct 6, 2021
@openjdk
Copy link

openjdk bot commented Oct 6, 2021

@lahodaj @HostUserDetails{id=51319204, username='lahodaj', fullName='null'} this pull request is now open

@vicente-romero-oracle
Copy link
Contributor

I guess this one needs a CSR right?

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons left a 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
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons Oct 15, 2021

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: were

Comment on lines 530 to 549
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]);
Copy link
Contributor

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.

Copy link
Member

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.

@openjdk
Copy link

openjdk bot commented Oct 19, 2021

@jddarcy has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@lahodaj please create a CSR request for issue JDK-8272234. This pull request cannot be integrated until the CSR request is approved.

@jddarcy
Copy link
Member

jddarcy commented Oct 19, 2021

I guess this one needs a CSR right?

A CSR is needed and I'd happily advance a Proposed request to Provisional in its current form.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 19, 2021
@vicente-romero-oracle
Copy link
Contributor

I made some minor edits to the CSR and added myself as reviewer

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 16, 2021

@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!

@openjdk
Copy link

openjdk bot commented Nov 22, 2021

⚠️ @lahodaj This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

default JavaFileObject getJavaFileForOutputForOriginatingFiles(Location location,
String className,
Kind kind,
FileObject... originatingFiles)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Contributor

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,

Comment on lines 358 to 365
* @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
Copy link
Contributor

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

Comment on lines 530 to 531
JavaFileObject[] originatingFiles = Arrays.asList(originatingElements)
.stream()
Copy link
Contributor

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.
*/

/**
Copy link
Contributor

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"),
Copy link
Contributor

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.

Comment on lines 225 to 229
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");
Copy link
Contributor

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()

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons left a 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.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Dec 1, 2021
@lahodaj
Copy link
Contributor Author

lahodaj commented Dec 3, 2021

/integrate

@openjdk
Copy link

openjdk bot commented Dec 3, 2021

Going to push as commit 8907003.
Since your change was applied there have been 101 commits pushed to the master branch:

  • 0fbd271: 8278115: gc/stress/gclocker/TestGCLockerWithSerial.java has duplicate -Xmx
  • bef5c7a: 8278116: runtime/modules/LoadUnloadModuleStress.java has duplicate -Xmx
  • 473ecec: 8278174: runtime/cds/appcds/LambdaWithJavaAgent.java fails with release VMs
  • 19ce33d: 8258512: serviceability/sa/TestJmapCore.java timed out on macOS 10.13.6
  • c93552c: 8277069: [REDO] JDK-8276743 Make openjdk build Zip Archive generation "reproducible"
  • b8ac0d2: 8276681: Additional malformed Javadoc inline tags in JDK source
  • b310f30: 8277396: [TESTBUG] In DefaultButtonModelCrashTest.java, frame is accessed from main thread
  • 15345e3: 8276661: (fs) UserDefinedFileAttributeView no longer works with long path (win)
  • 652b5f8: 8276674: Malformed Javadoc inline tags in JDK source
  • e0f1fc7: 8277358: Accelerate CRC32-C
  • ... and 91 more: https://git.openjdk.java.net/jdk/compare/040b2c52d3e82048630fbd45a7db48a5e65204b7...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Dec 3, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 3, 2021
@openjdk
Copy link

openjdk bot commented Dec 3, 2021

@lahodaj Pushed as commit 8907003.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants