-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8265899: Use pattern matching for instanceof at module jdk.compiler(part 1) #3673
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
Conversation
👋 Welcome back gli! A progress list of the required criteria for merging this PR into |
/label remove javadoc |
@lgxbslgx |
Webrevs
|
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.
Very nice cleanup - left few comments
JavacScope s = (JavacScope) other; | ||
return (env.equals(s.env) | ||
&& isStarImportScope() == s.isStarImportScope()); | ||
if (other instanceof JavacScope javacScope) { |
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.
Can this be:
return other instanceof JavacScope javacScope &&
env.equals(javacScope.env) &&
isStarImportScope() == javacScope.isStarImportScope();
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.
Fixed
result = new ArrayList<>(((Collection<?>)paths).size()); | ||
else | ||
if (paths != null) { | ||
result = new ArrayList<>(paths.size()); |
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 seems odd in the original code - I'd rather have somebody versed in the API double check this - @jonathan-gibbons ? Anyway - this doesn't seem to be related with using pattern matching, so perhaps it's preferrable to just move it out of this PR.
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.
I think that removing the unnecessary instanceof
expressions is also the goal of this cleanup. So I want to keep it.
In this case, my logical analysis is shown below.
- Please see the code below. The parameter type of the method
getJavaFileObjectsFromPaths
isCollection<? extends Path>
, so we don't need to usepaths instanceof Collection<?>
. We only need to judge whetherpaths
isnull
. So I usepaths != null
instead.
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
Collection<? extends Path> paths)
- Because the
paths
may benull
, I move the following code from top scope toif (paths != null)
branch scope to avoid the NPE.
for (Path p: paths)
result.add(PathFileObject.forSimplePath(this,
fsInfo.getCanonicalFile(p), p));
In my opinion, these two steps are reasonable for removing the instanceof
expression.
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.
OK
@@ -329,18 +329,17 @@ private void validateTypeNotIn(TypeMirror t, Set<TypeKind> invalidKinds) { | |||
|| elem.getModifiers().contains(Modifier.PRIVATE)) | |||
return Collections.emptySet(); | |||
|
|||
if (!(elem instanceof MethodSymbol)) | |||
if (!(elem instanceof MethodSymbol methodSymbol)) |
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.
These two look odd - your cleanup is fine, but it seems in the first cast, we want to wrap with IllegalArgumentException instead of failing with ClassCastException. In the second cast (for class symbol) it seems we're ok with just CCE. I'm fine with leaving this as per your cleanup - just noting the inconsistency.
@@ -2178,7 +2178,7 @@ protected JCInstanceOf(JCExpression expr, JCTree pattern) { | |||
|
|||
@Override @DefinedBy(Api.COMPILER_TREE) | |||
public JCPattern getPattern() { | |||
return pattern instanceof JCPattern ? (JCPattern) pattern : null; | |||
return pattern instanceof JCPattern jcPattern ? jcPattern : null; |
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.
Using patterns to implement patterns support :-)
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.
Looks good
result = new ArrayList<>(((Collection<?>)paths).size()); | ||
else | ||
if (paths != null) { | ||
result = new ArrayList<>(paths.size()); |
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.
OK
@lgxbslgx This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 25 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mcimadamore) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@mcimadamore Thank you for your review. May I ask your help to sponsor this patch? |
/sponsor |
@mcimadamore @lgxbslgx Since your change was applied there have been 29 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 41daa88. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi all,
This series of patches update the code of the module jdk.compiler by using the pattern matching for instanceof.
This patch would revise the following packages:
Thank you for taking the time to review.
--
Best Regards,
Guoxiong.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3673/head:pull/3673
$ git checkout pull/3673
Update a local copy of the PR:
$ git checkout pull/3673
$ git pull https://git.openjdk.java.net/jdk pull/3673/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3673
View PR using the GUI difftool:
$ git pr show -t 3673
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3673.diff