RFR: 8265899: Use pattern matching for instanceof at module jdk.compiler(part 1)
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Mon Apr 26 13:48:26 UTC 2021
On Sun, 25 Apr 2021 09:20:32 GMT, Guoxiong Li <gli at openjdk.org> wrote:
> 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:
>
> com.sun.tools.javac.api
> com.sun.tools.javac.file
> com.sun.tools.javac.main
> com.sun.tools.javac.model
> com.sun.tools.javac.platform
> com.sun.tools.javac.tree
> com.sun.tools.javac.util
>
>
> Thank you for taking the time to review.
>
> --
> Best Regards,
> Guoxiong.
Very nice cleanup - left few comments
src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java line 130:
> 128:
> 129: public boolean equals(Object other) {
> 130: if (other instanceof JavacScope javacScope) {
Can this be:
return other instanceof JavacScope javacScope &&
env.equals(javacScope.env) &&
isStarImportScope() == javacScope.isStarImportScope();
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java line 963:
> 961: ArrayList<PathFileObject> result;
> 962: if (paths != null) {
> 963: result = new ArrayList<>(paths.size());
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.
src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacTypes.java line 332:
> 330: return Collections.emptySet();
> 331:
> 332: if (!(elem instanceof MethodSymbol methodSymbol))
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.
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java line 2181:
> 2179: @Override @DefinedBy(Api.COMPILER_TREE)
> 2180: public JCPattern getPattern() {
> 2181: return pattern instanceof JCPattern jcPattern ? jcPattern : null;
Using patterns to implement patterns support :-)
-------------
PR: https://git.openjdk.java.net/jdk/pull/3673
More information about the compiler-dev
mailing list