RFR: 8240658: Code completion not working for lambdas in method invocations that require type inference
Advanced Static Source Code Analysis
github.com+46417962+jlahoda-jackpot at openjdk.java.net
Mon Sep 7 15:30:29 UTC 2020
On Mon, 7 Sep 2020 11:28:45 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> When a method invocation requires type inference, and the user is in the process of typing of a (block) lambda that is
> a parameter to the method invocation, javac may not, in some cases, perform the type inference, which then may lead to
> non working code completion in JShell (and possibly other tools). For example (in JShell):
> Arrays.stream(new Integer[]{1}).forEach(v -> { System.err.println(v.
>
> and press <tab> - this leads to no proposals currently, as the type of "v" is not inferred.
>
> The idea of the proposed patch is to improve the recovery in cases significant for cases where the text is being typed,
> and allow type inference in these cases. The type of "v" is then inferred, and the code completion works.
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 24:
> 22: */
> 23:
> 24: package test;
Jackpot:
warning: Incorrect Package
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 24:
> 22: */
> 23:
> 24: package test;
Jackpot:
warning: Incorrect Package
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 30:
> 28: private static void test() {
> 29: Test.of(1).convert(c1 -> {Object o = c1/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 30: Test.of(1).consume(c2 -> {Object o = c2/*getTypeMirror:DECLARED:java.lang.Integer*/; return null;});
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 34:
> 32: convert(0, c4 -> {Object o = c4/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 33: consume(0, c5 -> {Object o = c5/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 34: convertVarArgs(0, c6 -> {Object o = c6/*getTypeMirror:DECLARED:java.lang.Integer*/;}, 1, 2, 3, 4);
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 29:
> 27:
> 28: private static void test() {
> 29: Test.of(1).convert(c1 -> {Object o = c1/*getTypeMirror:DECLARED:java.lang.Integer*/;});
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 35:
> 33: consume(0, c5 -> {Object o = c5/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 34: convertVarArgs(0, c6 -> {Object o = c6/*getTypeMirror:DECLARED:java.lang.Integer*/;}, 1, 2, 3, 4);
> 35: consumeVarArgs(0, c7 -> {Object o = c7/*getTypeMirror:DECLARED:java.lang.Integer*/;}, 1, 2, 3, 4);
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 33:
> 31: Test.of(1).consumeWithParam(c3 -> {Object o = c3/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 32: convert(0, c4 -> {Object o = c4/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 33: consume(0, c5 -> {Object o = c5/*getTypeMirror:DECLARED:java.lang.Integer*/;});
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 32:
> 30: Test.of(1).consume(c2 -> {Object o = c2/*getTypeMirror:DECLARED:java.lang.Integer*/; return null;});
> 31: Test.of(1).consumeWithParam(c3 -> {Object o = c3/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 32: convert(0, c4 -> {Object o = c4/*getTypeMirror:DECLARED:java.lang.Integer*/;});
Jackpot:
warning: Variable o is never read
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 28:
> 26: public class TestGetTypeMirrorReferenceData {
> 27:
> 28: private static void test() {
Jackpot:
warning: test is never used
test/langtools/tools/javac/api/TestGetTypeMirrorReferenceData.java line 31:
> 29: Test.of(1).convert(c1 -> {Object o = c1/*getTypeMirror:DECLARED:java.lang.Integer*/;});
> 30: Test.of(1).consume(c2 -> {Object o = c2/*getTypeMirror:DECLARED:java.lang.Integer*/; return null;});
> 31: Test.of(1).consumeWithParam(c3 -> {Object o = c3/*getTypeMirror:DECLARED:java.lang.Integer*/;});
Jackpot:
warning: Variable o is never read
-------------
PR: https://git.openjdk.java.net/jdk/pull/50
More information about the compiler-dev
mailing list