Bug 542560 - [13][completion] Code completion Support for Switch
Expressions
Change-Id: I82f86c5c029927d976e86cf8c3614f0a97921084
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
# Conflicts:
# org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
Change-Id: I4eceb7297a7b037d406e2c90ec249279ab88dd5a
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
index b7de234..7912c9e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
@@ -500,11 +500,13 @@
" public X() {\n" +
" }\n" +
" public static void foo(Num num_) {\n" +
- " {\n" +
- " {\n" +
- " int i_j;\n" +
- " <SelectOnName:i_j>;\n" +
- " }\n" +
+ " switch (num_) {\n" +
+ " case THREE ->\n" +
+ " {\n" +
+ " int i_j;\n" +
+ " System.out.println(<SelectOnName:i_j>);\n" +
+ " break;\n" +
+ " }\n" +
" }\n" +
" }\n" +
"}\n";
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar b/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar
new file mode 100644
index 0000000..0f621d1
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip b/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip
new file mode 100644
index 0000000..bf05b46
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
index 85ad17c..07a741c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
@@ -3318,7 +3318,7 @@
}
} else if ("13".equals(compliance)) {
if (JavaCore.getClasspathVariable("JCL13_LIB") == null) {
- setupExternalJCL("jclMin12"); // No need for an explicit jclmin13, just use the same old one.
+ setupExternalJCL("jclMin13"); // No need for an explicit jclmin13, just use the same old one.
JavaCore.setClasspathVariables(
new String[] {"JCL13_LIB", "JCL13_SRC", "JCL_SRCROOT"},
new IPath[] {getExternalJCLPath("13"), getExternalJCLSourcePath("13"), getExternalJCLRootSourcePath()},
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java
deleted file mode 100644
index ea03702..0000000
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java
+++ /dev/null
@@ -1,856 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019 IBM and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- *******************************************************************************/
-package org.eclipse.jdt.core.tests.model;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
-
-import junit.framework.Test;
-
-public class CompletionTests12 extends AbstractJavaModelCompletionTests {
-
- static {
-// TESTS_NAMES = new String[]{"test018e"};
- }
-
- public CompletionTests12(String name) {
- super(name);
- }
- public void setUpSuite() throws Exception {
- if (COMPLETION_PROJECT == null) {
- COMPLETION_PROJECT = setUpJavaProject("Completion", "12");
- } else {
- setUpProjectCompliance(COMPLETION_PROJECT, "12");
- }
- super.setUpSuite();
- }
- public static Test suite() {
- return buildModelTestSuite(CompletionTests12.class);
- }
- public void test001() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUN ->\n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "SATURDAY, SUN";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test002() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUN :\n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "SATURDAY, SUN";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test003() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATU -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "SATU";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "SATURDAY[FIELD_REF]{SATURDAY, LMyDay;, LMyDay;, SATURDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test004() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUNDAY, MOND -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "MOND";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test005() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUND, MONDAY -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "SUND";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test005a() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUNDAY -> \n" +
- " System.out.println(day.toString());\n" +
- " case MON -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "case MON";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
- (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
- RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
- RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
- RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
- requestor.getResults());
- }
- public void test006() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day.toS) {\n" +
- " case \"SATURDAY\" -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "day.toS";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}",
- requestor.getResults());
- }
- public void test007() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (day.o) {\n" +
- " case 0 -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "day.o";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 60}",
- requestor.getResults());
- }
- public void test008() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (1 + day.o) {\n" +
- " case 0 -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "day.o";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 90}",
- requestor.getResults());
- }
- public void test009() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (1 + da) {\n" +
- " case 0 -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "1 + da";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
- requestor.getResults());
- }
- public void test010() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(MyDay day) {\n" +
- " switch (1 + da + 1) {\n" +
- " case 0 -> \n" +
- " System.out.println(day.toString());\n" +
- " }\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n" +
- "enum MyDay { SATURDAY, SUNDAY}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "1 + da";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
- requestor.getResults());
- }
- public void test011() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " switch (arg) {\n" +
- " case 1 -> 1;\n" +
- " default -> 0;\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "switch (arg";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
- requestor.getResults());
- }
- public void test012() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " switch (arg0) {\n" +
- " case 1 -> arg;\n" +
- " default -> 0;\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "-> arg";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
- requestor.getResults());
- }
- public void test013() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/Switch.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " switch (0 + arg) {\n" +
- " case 1 -> 1;\n" +
- " default -> 0;\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "0 + arg";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 82}",
- requestor.getResults());
- }
- public void test014() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class X {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " swi);\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "swi";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "switch[KEYWORD]{switch, null, null, switch, null, 49}",
- requestor.getResults());
- }
- public void _test015() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " switch (0 + arg0) {\n" +
- " case 1 -> {break ar;}\n" +
- " default -> 0;\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "break ar";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
- requestor.getResults());
- }
- public void test016() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " switch (0 + arg0) {\n" +
- " case 1 -> {break 1;}\n" +
- " default -> ar;\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "-> ar";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
- requestor.getResults());
- }
- public void _test017() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " int arg1 = 0;\n" +
- " foo(\n" +
- " switch (0 + arg0) {\n" +
- " case 1 -> 1;\n" +
- " default -> {break ar;}\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "break ar";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
- requestor.getResults());
- }
- public void _test017a() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class Switch {\n" +
- " public static void bar(int arg0) {\n" +
- " foo(\n" +
- " argLabel: switch (0 + arg0) {\n" +
- " case 1 -> 1;\n" +
- " default -> {break ar;}\n" +
- " }\n" +
- " });\n" +
- " public static void foo(int arg0) {\n" +
- " bar(MyDay.SUNDAY);\n" +
- " }\n" +
- "}\n");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "break ar";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}\n" +
- "argLabel[LABEL_REF]{argLabel, null, null, argLabel, null, 49}",
- requestor.getResults());
- }
- public void test018a() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 1 -> this::n_; \n" +
- " case 2 -> () -> n1(); \n" +
- " case 3 -> null; \n" +
- " case 4 -> () -> n2(); \n" +
- " default -> this::n2; }); \n" +
- " }\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "this::n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
- "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
- requestor.getResults());
- }
- public void test018b() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 2 -> () -> n_; \n" +
- " }\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "-> n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
- "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
- requestor.getResults());
- }
- public void test018c() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " default -> this::n_; }); \n" +
- " }\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "this::n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
- "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
- requestor.getResults());
- }
- public void test018d() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " default -> () -> n_; }); \n" +
- " }\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "() -> n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
- "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
- requestor.getResults());
- }
- public void test018e() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 1 -> this::n_1; \n" +
- " case 2 -> () -> n_; \n" +
- " }\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "() -> n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[LOCAL_VARIABLE_REF]{n_1, null, Ljava.lang.Object;, n_1, null, 51}\n" +
- "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
- "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
- requestor.getResults());
- }
- public void test018f() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 1 -> () -> n_1; \n" +
- " case 2 -> this::n_; \n" +
- " }\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "this::n_";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
- "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
- requestor.getResults());
- }
- public void test019() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "import org.eclipse.jdt.annotation.*;\n" +
- " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
- "public class X {\n" +
- " void testSw(int i) { \n" +
- " m(swi);\n" +
- "}\n" +
- "interface Supplier<T> {\n" +
- " T get();\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "swi";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "switch[KEYWORD]{switch, null, null, switch, null, 49}",
- requestor.getResults());
- }
- public void test020() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class X {\n" +
- " static final String MONDAY = \"MONDAY\";\n" +
- " static final String TUESDAY = \"TUESDAY\";\n" +
- " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
- " static final String THURSDAY = \"THURSDAY\";\n" +
- " static final String FRIDAY = \"FRIDAY\";\n" +
- " static final String SATURDAY = \"SATURDAY\";\n" +
- " static final String SUNDAY = \"SUNDAY\"; \n" +
- " @SuppressWarnings(\"preview\")\n" +
- " public static void main(String[] args) {\n" +
- " String day = \"MONDAY\";\n" +
- " switch (day) {\n" +
- " case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n" +
- " case TUESDAY -> System.out.println(7);\n" +
- " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
- " case WEDNESDAY -> System.out.println(9);\n" +
- " }\n" +
- " int k = switch (day) {\n" +
- " case MONDAY -> throw new NullPointerException();\n" +
- " case TUESDAY -> 1;\n" +
- " case WEDNESDAY -> {break 10;}\n" +
- " default -> {\n" +
- " int g = day.h();\n" +
- " int result = f(g);\n" +
- " break result;\n" +
- " }};\n" +
- " }\n" +
- " static int f(int k) {\n" +
- " return k*k;\n" +
- " }\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "day.h";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
- requestor.getResults());
- }
- public void test021() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy(
- "/Completion/src/X.java",
- "public class X {\n" +
- " static final String MONDAY = \"MONDAY\";\n" +
- " static final String TUESDAY = \"TUESDAY\";\n" +
- " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
- " static final String THURSDAY = \"THURSDAY\";\n" +
- " static final String FRIDAY = \"FRIDAY\";\n" +
- " static final String SATURDAY = \"SATURDAY\";\n" +
- " static final String SUNDAY = \"SUNDAY\"; \n" +
- " @SuppressWarnings(\"preview\")\n" +
- " public static void main(String[] args) {\n" +
- " String day = \"MONDAY\";\n" +
- " int k = switch (day) {\n" +
- " case MONDAY -> throw new NullPointerException();\n" +
- " case TUESDAY -> 1;\n" +
- " case WEDNESDAY -> {break 10;}\n" +
- " default -> {\n" +
- " int g = day.h();\n" +
- " int result = f(g);\n" +
- " break result;\n" +
- " }};\n" +
- " }\n" +
- " static int f(int k) {\n" +
- " return k*k;\n" +
- " }\n" +
- "}");
- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
- requestor.allowAllRequiredProposals();
- String str = this.workingCopies[0].getSource();
- String completeBehind = "day.h";
- int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
- this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults(
- "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
- requestor.getResults());
- }
-}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
index 348ad9c..992ad6f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
@@ -41,7 +41,6 @@
COMPLETION_SUITES.add(CompletionTests9.class);
COMPLETION_SUITES.add(CompletionTests10.class);
COMPLETION_SUITES.add(CompletionTests11.class);
- COMPLETION_SUITES.add(CompletionTests12.class);
COMPLETION_SUITES.add(CompletionContextTests.class);
COMPLETION_SUITES.add(CompletionContextTests_1_5.class);
COMPLETION_SUITES.add(CompletionWithMissingTypesTests.class);
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
index 38eaad8..3ae6696 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
@@ -7,6 +7,10 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -99,6 +103,7 @@
protected static final int K_AFTER_NAME_IN_PROVIDES_STATEMENT = COMPLETION_PARSER + 49;
protected static final int K_AFTER_WITH_IN_PROVIDES_STATEMENT = COMPLETION_PARSER + 50;
protected static final int K_INSIDE_OPENS_STATEMENT = COMPLETION_PARSER + 51;
+ protected static final int K_YIELD_KEYWORD = COMPLETION_PARSER + 52;
public final static char[] FAKE_TYPE_NAME = new char[]{' '};
@@ -1675,6 +1680,14 @@
}
return false;
}
+private boolean checkYieldKeyword() {
+ // Clients to ensure that we are already inside a method
+ char[] id = this.scanner.getCurrentIdentifierSource();
+ if(id.length > 0 && CharOperation.prefixEquals(id, Keywords.YIELD)) {
+ return true;
+ }
+ return false;
+}
/**
* Checks if the completion is inside a method invocation or a constructor invocation.
* Returns whether we found a completion node.
@@ -3798,6 +3811,12 @@
}
}
@Override
+protected void consumeSwitchLabeledBlock() {
+ popUntilElement(K_SWITCH_LABEL);
+ popElement(K_SWITCH_LABEL);
+ concatNodeLists();
+}
+@Override
protected void consumeToken(int token) {
if(this.isFirst) {
super.consumeToken(token);
@@ -3826,6 +3845,10 @@
break;
case TokenNameLBRACE:
popElement(K_BETWEEN_NEW_AND_LEFT_BRACKET);
+ if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_SWITCH_LABEL
+ && previous == TokenNameARROW) {
+ pushOnElementStack(K_SWITCH_EXPRESSION_DELIMITTER);
+ }
break;
case TokenNameLBRACKET:
if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_BETWEEN_NEW_AND_LEFT_BRACKET) {
@@ -3916,6 +3939,16 @@
case TokenNameIdentifier:
if (this.inReferenceExpression)
break;
+ if (this.scanner.previewEnabled && isInsideSwitch() && checkYieldKeyword()) {
+ pushOnElementStack(K_YIELD_KEYWORD);
+ // Take the short cut here.
+ // Instead of injecting the TokenNameRestrictedIdentifierYield, totally ignore it
+ // and let completion take it course. We will not be constructing the
+ // YieldStatement and thus not producing accurate completion, but completion doesn't have
+ // enough information anyway about the LHS anyway.
+ token = this.currentToken = this.getNextToken();
+ super.consumeToken(this.currentToken);
+ }
if (previous == TokenNameDOT) { // e.g. foo().[fred]()
if (this.invocationType != SUPER_RECEIVER // e.g. not super.[fred]()
&& this.invocationType != NAME_RECEIVER // e.g. not bar.[fred]()
@@ -4321,6 +4354,7 @@
pushOnElementStack(K_BETWEEN_FOR_AND_RIGHT_PAREN, this.bracketDepth);
break;
case TokenNameswitch:
+ popElement(K_LOCAL_INITIALIZER_DELIMITER);
pushOnElementStack(K_BETWEEN_SWITCH_AND_RIGHT_PAREN, this.bracketDepth);
break;
case TokenNamesynchronized:
@@ -4864,7 +4898,8 @@
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for
// loop without block. Completion while at K_CONTROL_STATEMENT_DELIMITER case needs to handled
// similar to the K_BLOCK_DELIMITER with minor differences.
- if(kind == K_BLOCK_DELIMITER || kind == K_CONTROL_STATEMENT_DELIMITER || kind == K_LAMBDA_EXPRESSION_DELIMITER) {
+ if(kind == K_BLOCK_DELIMITER || kind == K_CONTROL_STATEMENT_DELIMITER || kind == K_LAMBDA_EXPRESSION_DELIMITER
+ || kind == K_SWITCH_EXPRESSION_DELIMITTER) {
if(this.canBeExplicitConstructor == YES) {
canBeExplicitConstructorCall = true;
}
@@ -4906,6 +4941,9 @@
if(isInsideBreakable()) {
keywords[count++]= Keywords.BREAK;
}
+ if(isInsideSwitch()) {
+ keywords[count++]= Keywords.YIELD;
+ }
} else if (kind == K_BETWEEN_FOR_AND_RIGHT_PAREN) {
if (this.options.complianceLevel >= ClassFileConstants.JDK10) {
keywords[count++]= Keywords.VAR;
@@ -4920,13 +4958,16 @@
keywords[count++]= Keywords.TRUE;
keywords[count++]= Keywords.FALSE;
keywords[count++]= Keywords.NULL;
-
+ if (kind == K_YIELD_KEYWORD) {
+ keywords[count++]= Keywords.YIELD;
+ }
if(kind == K_SWITCH_LABEL) {
if(topKnownElementInfo(COMPLETION_OR_ASSIST_PARSER) != DEFAULT) {
keywords[count++]= Keywords.DEFAULT;
}
keywords[count++]= Keywords.BREAK;
keywords[count++]= Keywords.CASE;
+ keywords[count++]= Keywords.YIELD;
if (this.options.complianceLevel >= ClassFileConstants.JDK1_4) {
keywords[count++]= Keywords.ASSERT;
}
@@ -5124,9 +5165,7 @@
@Override
protected void consumePostfixExpression() {
// PostfixExpression ::= Name
- if(this.topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_INSIDE_BREAK_STATEMENT) {
- // Do nothing, just let checkLabelStatement() do the job
- } else {
+ if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) != K_YIELD_KEYWORD) {
super.consumePostfixExpression();
}
}
@@ -5231,24 +5270,11 @@
return false;
}
-protected boolean isIndirectlyInsideBlock(){
- int i = this.elementPtr;
- while(i > -1) {
- if(this.elementKindStack[i] == K_BLOCK_DELIMITER)
- return true;
- i--;
- }
- return false;
-}
-
-protected boolean isInsideBlock(){
+protected boolean isInsideSwitch(){
int i = this.elementPtr;
while(i > -1) {
switch (this.elementKindStack[i]) {
- case K_TYPE_DELIMITER : return false;
- case K_METHOD_DELIMITER : return false;
- case K_FIELD_INITIALIZER_DELIMITER : return false;
- case K_BLOCK_DELIMITER : return true;
+ case K_SWITCH_LABEL : return true;
}
i--;
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
index 9980463..fa1531d 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -104,6 +108,7 @@
protected static final int K_ENUM_CONSTANT_DELIMITER = ASSIST_PARSER + 6; // whether we are inside a field initializer
protected static final int K_LAMBDA_EXPRESSION_DELIMITER = ASSIST_PARSER + 7; // whether we are inside a lambda expression
protected static final int K_MODULE_INFO_DELIMITER = ASSIST_PARSER + 8; // whether we are inside a module info declaration
+ protected static final int K_SWITCH_EXPRESSION_DELIMITTER = ASSIST_PARSER + 9; // whether we are inside a switch expression
// selector constants
protected static final int THIS_CONSTRUCTOR = -1;
@@ -1281,11 +1286,8 @@
break;
}
}
-private boolean lastArrowAssociatedWithCase = false;
@Override
protected void consumeToken(int token) {
- if (TokenNameARROW == token)
- this.lastArrowAssociatedWithCase = this.caseFlagSet; // remember the arrow association before reset.
super.consumeToken(token);
if(this.isFirst) {
@@ -1318,9 +1320,10 @@
}
break;
case TokenNameLBRACE:
- if (this.previousToken == TokenNameARROW && !this.lastArrowAssociatedWithCase) {
+ if (this.previousToken == TokenNameARROW) {
popElement(K_LAMBDA_EXPRESSION_DELIMITER);
- pushOnElementStack(K_LAMBDA_EXPRESSION_DELIMITER, BLOCK_BODY, this.previousObjectInfo);
+ if (topKnownElementKind(ASSIST_PARSER, 1) != K_SWITCH_EXPRESSION_DELIMITTER)
+ pushOnElementStack(K_LAMBDA_EXPRESSION_DELIMITER, BLOCK_BODY, this.previousObjectInfo);
}
break;
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java
index 2fb6ab5..ba10f2c 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Jesper Steen Møller - Contributions for
@@ -22,6 +26,7 @@
char[] ASSERT = "assert".toCharArray(); //$NON-NLS-1$
char[] BREAK = "break".toCharArray(); //$NON-NLS-1$
char[] CASE = "case".toCharArray(); //$NON-NLS-1$
+ char[] YIELD = "yield".toCharArray(); //$NON-NLS-1$
char[] CATCH = "catch".toCharArray(); //$NON-NLS-1$
char[] CLASS = "class".toCharArray(); //$NON-NLS-1$
char[] CONTINUE = "continue".toCharArray(); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/YieldStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/YieldStatement.java
index 8fd2e97..0e8962b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/YieldStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/YieldStatement.java
@@ -32,8 +32,8 @@
*/
public boolean isImplicit;
-public YieldStatement(Expression exp, int sourceStart, int e) {
- super(null, sourceStart, e);
+public YieldStatement(Expression exp, int sourceStart, int sourceEnd) {
+ super(null, sourceStart, sourceEnd);
this.expression = exp;
}
@Override
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 2f9e6af..6add7a5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -9794,7 +9794,7 @@
//System.out.println(this.scanner.toStringAction(type));
switch (type) {
case TokenNameARROW:
- if (!this.caseFlagSet && this.scanner.lookBack[0] != TokenNamedefault)
+ if (!this.caseFlagSet && this.scanner.lookBack[0] != TokenNamedefault)
consumeLambdaHeader();
this.caseFlagSet = false;
break;
diff --git a/org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF b/org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF
index 8ea3f60..527baf4 100644
--- a/org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
+ org.eclipse.jdt.core.tests.model;bundle-version="[3.10.0,4.0.0)",
org.eclipse.jdt.core.tests.compiler;bundle-version="[3.10.0,4.0.0)",
javax.annotation
Bundle-RequiredExecutionEnvironment: JavaSE-13
diff --git a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java
index e8443b2..cdf4712 100644
--- a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
+import org.eclipse.jdt.core.tests.model.CompletionTests13;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
@@ -20,6 +21,7 @@
// Common test suites
ArrayList standardTests = new ArrayList();
standardTests.add(TextBlockTest.class);
+ standardTests.add(CompletionTests13.class);
TestSuite all = new TestSuite(TestAll.class.getName());
int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((possibleComplianceLevels & AbstractCompilerTest.F_13) != 0) {
diff --git a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java
new file mode 100644
index 0000000..844da06
--- /dev/null
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java
@@ -0,0 +1,1555 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+@SuppressWarnings("preview")
+public class CompletionTests13 extends AbstractJavaModelCompletionTests {
+
+ static {
+// TESTS_NAMES = new String[]{"test034"};
+ }
+
+ public CompletionTests13(String name) {
+ super(name);
+ }
+ public void setUpSuite() throws Exception {
+ if (COMPLETION_PROJECT == null) {
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "13");
+ } else {
+ setUpProjectCompliance(COMPLETION_PROJECT, "13");
+ }
+ super.setUpSuite();
+ }
+ public static Test suite() {
+ return buildModelTestSuite(CompletionTests13.class);
+ }
+ public void test001() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUN ->\n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATURDAY, SUN";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test002() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUN :\n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATURDAY, SUN";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test003() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATU -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATU";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SATURDAY[FIELD_REF]{SATURDAY, LMyDay;, LMyDay;, SATURDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test004() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY, MOND -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "MOND";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test005() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUND, MONDAY -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SUND";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test005a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY -> \n" +
+ " System.out.println(day.toString());\n" +
+ " case MON -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case MON";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test006() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ """
+ public class Switch {
+ public static void bar(MyDay day) {
+ switch (day.toS) {
+ case "SATURDAY" ->
+ System.out.println(day.toString());
+ }
+ }
+ public static void main(String[] args) {
+ bar(MyDay.SUNDAY);
+ }
+ }
+ enum MyDay { SATURDAY, SUNDAY}
+ """
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.toS";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}",
+ requestor.getResults());
+ }
+ public void test007() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day.o) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.o";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 60}",
+ requestor.getResults());
+ }
+ public void test008() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + day.o) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.o";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 90}",
+ requestor.getResults());
+ }
+ public void test009() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + da) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "1 + da";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
+ requestor.getResults());
+ }
+ public void test010() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + da + 1) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "1 + da";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
+ requestor.getResults());
+ }
+ public void test011() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (arg) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "switch (arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test012() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (arg0) {\n" +
+ " case 1 -> arg;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test013() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (0 + arg) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "0 + arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 82}",
+ requestor.getResults());
+ }
+ public void test014() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " swi);\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "swi";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "switch[KEYWORD]{switch, null, null, switch, null, 49}",
+ requestor.getResults());
+ }
+ public void test015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class Switch {
+ public static void bar(int arg0) {
+ pointer: foo(
+ switch (0 + arg0) {
+ case 1 -> {break ;}
+ default -> 0;
+ }
+ });
+ public static void foo(int arg0) {
+ bar(MyDay.SUNDAY);
+ }
+ }""");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break ";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "pointer[LABEL_REF]{pointer, null, null, pointer, null, 49}",
+ requestor.getResults());
+ }
+ public void test016() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> {break 1;}\n" +
+ " default -> ar;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test017() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class Switch {
+ public static void bar(int arg0) {
+ int arg1 = 0;
+ pointer: foo(
+ switch (0 + arg0) {
+ case 1 -> 1;
+ default -> {break p;}
+ }
+ });
+ public static void foo(int arg0) {
+ bar(MyDay.SUNDAY);
+ }
+ }""");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break p";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "pointer[LABEL_REF]{pointer, null, null, pointer, null, 49}",
+ requestor.getResults());
+ }
+ public void test017a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " argLabel: switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break ar;}\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "argLabel[LABEL_REF]{argLabel, null, null, argLabel, null, 49}",
+ requestor.getResults());
+ }
+ public void test018a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> this::n_; \n" +
+ " case 2 -> () -> n1(); \n" +
+ " case 3 -> null; \n" +
+ " case 4 -> () -> n2(); \n" +
+ " default -> this::n2; }); \n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test018b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 2 -> () -> n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " default -> this::n_; }); \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test018d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " default -> () -> n_; }); \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "() -> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> this::n_1; \n" +
+ " case 2 -> () -> n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "() -> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[LOCAL_VARIABLE_REF]{n_1, null, Ljava.lang.Object;, n_1, null, 51}\n" +
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018f() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> () -> n_1; \n" +
+ " case 2 -> this::n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test019() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ "public class X {\n" +
+ " void testSw(int i) { \n" +
+ " m(swi);\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "swi";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "switch[KEYWORD]{switch, null, null, switch, null, 49}",
+ requestor.getResults());
+ }
+ public void test020() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " static final String THURSDAY = \"THURSDAY\";\n" +
+ " static final String FRIDAY = \"FRIDAY\";\n" +
+ " static final String SATURDAY = \"SATURDAY\";\n" +
+ " static final String SUNDAY = \"SUNDAY\"; \n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = \"MONDAY\";\n" +
+ " switch (day) {\n" +
+ " case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " case WEDNESDAY -> System.out.println(9);\n" +
+ " }\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {break 10;}\n" +
+ " default -> {\n" +
+ " int g = day.h();\n" +
+ " int result = f(g);\n" +
+ " break result;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.h";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
+ requestor.getResults());
+ }
+ public void test021() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " static final String THURSDAY = \"THURSDAY\";\n" +
+ " static final String FRIDAY = \"FRIDAY\";\n" +
+ " static final String SATURDAY = \"SATURDAY\";\n" +
+ " static final String SUNDAY = \"SUNDAY\"; \n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = \"MONDAY\";\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {break 10;}\n" +
+ " default -> {\n" +
+ " int g = day.h();\n" +
+ " int result = f(g);\n" +
+ " break result;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.h";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
+ requestor.getResults());
+ }
+ /*
+ * Try completion for break keyword inside switch expression - negative
+ */
+ public void test022() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = \"MONDAY\";\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {br;}\n" +
+ " default -> {\n" +
+ " int g = day.hashCode();\n" +
+ " int result = f(g);\n" +
+ " yield result;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case WEDNESDAY -> {br";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "break[KEYWORD]{break, null, null, break, null, 49}",
+ requestor.getResults());
+ }
+ /*
+ * Try completion for yield keyword - positive
+ */
+ public void test023() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String[] args) {
+ String day = "MONDAY";
+ int k = switch (day) {
+ case "M" -> throw new NullPointerException();
+ case "T" -> 1;
+ case "W" -> {yi ;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ yield result;
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case \"W\" -> {yi";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "yield[KEYWORD]{yield, null, null, yield, null, 49}",
+ requestor.getResults());
+ }
+ /*
+ * Try completion for yield with identifier - positive
+ */
+ public void test024() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String day) {\n" +
+ " int k = switch (day) {\n" +
+ " default -> {\n" +
+ " int g = day.hashCode();\n" +
+ " int result = f(g);\n" +
+ " yield res;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield res";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "result[LOCAL_VARIABLE_REF]{result, null, I, result, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion for yield with identifier with a preceding case with yield - positive
+ */
+ public void test024a() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String day) {\n" +
+ " int k = switch (day) {\n" +
+ " case TUESDAY -> { yield 1;}\n" +
+ " default -> {\n" +
+ " int g = day.hashCode();\n" +
+ " int result = f(g);\n" +
+ " yield res;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield res";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "result[LOCAL_VARIABLE_REF]{result, null, I, result, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion for yield with identifier with a preceding case with yield - positive
+ */
+ public void test024b() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String day) {\n" +
+ " int k = switch (day) {\n" +
+ " case TUESDAY -> { yield 1;}\n" +
+ " default -> {\n" +
+ " int g = day.hashCode();\n" +
+ " int result = f(g);\n" +
+ " yield 0 + res;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield 0 + res";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "result[LOCAL_VARIABLE_REF]{result, null, I, result, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion in a switch expression case block without any assist keyword
+ */
+ public void test024c() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String day) {\n" +
+ " int k = switch (day) {\n" +
+ " case TUESDAY -> { yield 1;}\n" +
+ " default -> {\n" +
+ " int[] g = new int[0];\n" +
+ " yield g.;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield g.";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "length[FIELD_REF]{length, [I, I, length, null, 49}\n" +
+ "clone[METHOD_REF]{clone(), [I, ()[I, clone, null, 60}\n" +
+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 60}\n" +
+ "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, 60}\n" +
+ "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, 60}\n" +
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}\n" +
+ "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, 60}\n" +
+ "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, 60}\n" +
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, 60}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), 60}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), 60}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion in a switch expression case block without any assist keyword
+ */
+ public void test024d() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = args[0];\n" +
+ " int k = switch (day) {\n" +
+ " case TUESDAY -> { yield 1;}\n" +
+ " default -> {\n" +
+ " int[] g = args.;\n" +
+ " yield g;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "int[] g = args.";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "length[FIELD_REF]{length, [Ljava.lang.String;, I, length, null, 49}\n" +
+ "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, 55}\n" +
+ "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, 55}\n" +
+ "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, 55}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, 55}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), 55}\n" +
+ "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), 55}\n" +
+ "clone[METHOD_REF]{clone(), [Ljava.lang.String;, ()[Ljava.lang.String;, clone, null, 60}\n" +
+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 60}\n" +
+ "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, 60}\n" +
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}\n" +
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion for yield with value inside switch - positive
+ *
+ */
+ public void test025() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " resolve: {" +
+ " String day = \"MONDAY\";\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {yield 10;}\n" +
+ " default -> {\n" +
+ " yield day.h;\n" +
+ " }};\n" +
+ " }" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield day.h";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}",
+ requestor.getResults());
+ }
+ /*
+ * Try completion for yield keyword - inside nested block
+ */
+ public void test026() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String day) {
+ int k = switch (day) {
+ case "W" -> {yield 2;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ {
+ yie;
+ }
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yie";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "yield[KEYWORD]{yield, null, null, yield, null, 49}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion for yield - inside nested block
+ */
+ public void test027() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String day) {
+ int k = switch (day) {
+ case "W" -> {yield 2;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ {
+ yield res;
+ }
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield res";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "result[LOCAL_VARIABLE_REF]{result, null, I, result, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion for yield - inside nested block
+ */
+ public void test028() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String day) {
+ int k = switch (day) {
+ case "W" -> {yield 2;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ {
+ for(int i = 0; i < 3; i++) {
+ if (i == 0) {
+ yield day.h
+ }
+ }
+ yield 0;
+ }
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield day.h";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion of other keywords inside switch expression nested block
+ */
+ public void test029() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String day) {
+ int k = switch (day) {
+ case "W" -> {yield 2;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ {
+ for(int i = 0; i < 3; i++) {
+ if (i == 0) {
+ thr
+ }
+ }
+ yield 0;
+ }
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "thr";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "Throwable[TYPE_REF]{Throwable, java.lang, Ljava.lang.Throwable;, null, null, 42}\n" +
+ "throw[KEYWORD]{throw, null, null, throw, null, 49}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion of other keywords inside switch expression nested block
+ */
+ public void test030() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String day) {
+ int k = switch (day) {
+ case "W" -> {yield 2;}
+ default -> {
+ int g = day.hashCode();
+ int result = f(g);
+ {
+ for(int i = 0; i < 3; i++) {
+ if (i == 0) {
+ throw Exc
+ }
+ }
+ yield 0;
+ }
+ }};
+ }
+ static int f(int k) {
+ return k*k;
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "throw Exc";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "Exception[TYPE_REF]{Exception, java.lang, Ljava.lang.Exception;, null, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion inside a lambda nested inside a switch expression
+ */
+ public void test031() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String[] args) {
+ String day = "";
+ int i = switch (day) {
+ default -> {
+ for (int j = 0; j < 3; j++) {
+ if (j == 0) {
+ IntPredicate pre = (_value) -> !test(_v);
+ };
+ }
+ }
+ yield 0;
+ }
+ };
+ }
+ private static boolean test(int value) {
+ return false;
+ }
+ }
+ interface IntPredicate {
+ boolean test(int value);
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "test(_v";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "_value[LOCAL_VARIABLE_REF]{_value, null, I, _value, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion inside a lambda (block) nested inside a switch expression
+ */
+ public void test032() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String[] args) {
+ String day = "";
+ int i = switch (day) {
+ default -> {
+ for (int j = 0; j < 3; j++) {
+ if (j == 0) {
+ IntPredicate pre = (_value) -> {
+ return !test(_v);
+ };
+ }
+ }
+ yield 0;
+ }
+ };
+ }
+ private static boolean test(int value) {
+ return false;
+ }
+ }
+ interface IntPredicate {
+ boolean test(int value);
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "test(_v";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "_value[LOCAL_VARIABLE_REF]{_value, null, I, _value, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion inside a switch expression nested inside a lambda expression
+ */
+ public void test033() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String[] args) {
+ IntPredicate pre = (_value) -> !test(
+ switch (_value) {
+ default -> {
+ yield _v;
+ }
+ }
+ );
+ }
+ private static boolean test(int value) {
+ return false;
+ }
+ }
+ interface IntPredicate {
+ boolean test(int value);
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield _v";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "_value[LOCAL_VARIABLE_REF]{_value, null, I, _value, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ /*
+ * Try completion inside a switch expression nested inside a lambda expression
+ */
+ public void test034() throws JavaModelException {
+ String old = COMPLETION_PROJECT.getOption(CompilerOptions.OPTION_EnablePreviews, true);
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ """
+ public class X {
+ @SuppressWarnings("preview")
+ public static void main(String[] args) {
+ IntPredicate pre = (_value) -> {
+ return !test(
+ switch (_value) {
+ default -> {
+ yield _v;
+ }
+ }
+ );
+ };
+ }
+ private static boolean test(int value) {
+ return false;
+ }
+ }
+ interface IntPredicate {
+ boolean test(int value);
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "yield _v";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "_value[LOCAL_VARIABLE_REF]{_value, null, I, _value, null, 52}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+}