RFR: 8057543: Replace javac's Filter with Predicate (and lambdas)

Guoxiong Li gli at openjdk.java.net
Thu Apr 22 13:43:22 UTC 2021


On Mon, 19 Apr 2021 10:41:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Hi all,
>> 
>> This patch replaces javac's `Filter` with `Predicate` and sets `Filter` as `Deprecated`.
>> Two existing tests failed and I fixed it.
>> Currently, all the tests in `test/langtools` passed locally by using the following command.
>> 
>> 
>> make test CONF=linux-x86_64-server-release JOBS=4 TEST=test/langtools/
>> 
>> 
>> Thank you for taking the time to review.
>> 
>> Best Regards.
>
> @edvbld Can you please help?

@mcimadamore  Thank you for your reply about these issues.

For [JDK-8057542](https://bugs.openjdk.java.net/browse/JDK-8057542) `FreeTypeListener`, I search the words `new FreeTypeListener` at the [PATCH](https://github.com/openjdk/jdk/commit/c4e8276376676bda9aa4cb00b6d071fb70c21b85). I can get 6 places which are like the following code.


-                inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() {
-                    @Override
-                    public void typesInferred(InferenceContext inferenceContext) {
-                        checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts));
-                    }
-                });
+                inferenceContext.addFreeTypeListener(ts,
+                        solvedContext -> checkAccessibleTypes(pos, env, solvedContext, solvedContext.asInstTypes(ts)));


For [JDK-8057545](https://bugs.openjdk.java.net/browse/JDK-8057545) `Factory`,  I search the words `new Context.Factory` at the [PATCH](https://github.com/openjdk/jdk/commit/c4e8276376676bda9aa4cb00b6d071fb70c21b85). I can get 14 places which are like the following code.


-        context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
-            @Override
-            public JavaFileManager make(Context c) {
-                return new JavacFileManager(c, true, null);
-            }
-        });
+        context.put(JavaFileManager.class,
+                (Factory<JavaFileManager>)c -> new JavacFileManager(c, true, null));


For [JDK-8057546](https://bugs.openjdk.java.net/browse/JDK-8057546) `LintLogger`,  I search the words `new DeferredLintHandler.LintLogger` at the [PATCH](https://github.com/openjdk/jdk/commit/c4e8276376676bda9aa4cb00b6d071fb70c21b85). I can get 4 places which are like the following code.


-            deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
-                @Override
-                public void report() {
-                    warnDeprecated(pos, s);
-                }
-            });
+            deferredLintHandler.report(() -> warnDeprecated(pos, s));


For [JDK-8057547](https://bugs.openjdk.java.net/browse/JDK-8057547) `TreeBuilder`,  I search the words `new TreeBuilder` at the [PATCH](https://github.com/openjdk/jdk/commit/c4e8276376676bda9aa4cb00b6d071fb70c21b85). I can get 7 places which are like the following code.


-            return abstractRval(s.selected, new TreeBuilder() {
-                    public JCExpression build(final JCExpression selected) {
-                        return builder.build(make.Select(selected, s.sym));
-                    }
-                });
+            return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));


On the other hand, I search `new FreeTypeListener`, `new Context.Factory`, `new DeferredLintHandler.LintLogger` and `new TreeBuilder` at current JDK main line code base. I can't get any result. So I think these four issues are solved by this  [PATCH](https://github.com/openjdk/jdk/commit/c4e8276376676bda9aa4cb00b6d071fb70c21b85) or other patches.

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

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


More information about the compiler-dev mailing list