Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-09-19 08:30:33 +0000
committerSarika Sinha2019-09-19 09:48:37 +0000
commita3466b0f64e8842e5ed6a3a28165da341fb76cc0 (patch)
treeadc5e09ee603628bfbb88a247a105743b26d47fc /org.eclipse.jdt.tests.latestBREE/src
parentc842004634d661ef8d9d485e77e9c84af231e888 (diff)
downloadeclipse.jdt.core-a3466b0f64e8842e5ed6a3a28165da341fb76cc0.tar.gz
eclipse.jdt.core-a3466b0f64e8842e5ed6a3a28165da341fb76cc0.tar.xz
eclipse.jdt.core-a3466b0f64e8842e5ed6a3a28165da341fb76cc0.zip
Merge remote-tracking branch 'origin/BETA_JAVA13'I20190919-1800I20190919-0850
# Conflicts: # org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF # org.eclipse.jdt.compiler.apt/pom.xml # org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF # org.eclipse.jdt.core.tests.compiler/pom.xml # org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF # org.eclipse.jdt.core.tests.model/pom.xml # org.eclipse.jdt.core/META-INF/MANIFEST.MF # org.eclipse.jdt.core/pom.xml Change-Id: I2562d3b2833b1b63e3b8cfc46eb533bffcae6bd9
Diffstat (limited to 'org.eclipse.jdt.tests.latestBREE/src')
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java34
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java879
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java1603
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/tests/latestbree/Activator.java22
4 files changed, 2538 insertions, 0 deletions
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
new file mode 100644
index 0000000000..cdf4712cb7
--- /dev/null
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java
@@ -0,0 +1,34 @@
+package org.eclipse.jdt.core.tests.compiler.regression.latest;
+
+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;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public class TestAll extends junit.framework.TestCase {
+
+public TestAll(String testName) {
+ super(testName);
+}
+public static Test suite() {
+
+ // 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) {
+ ArrayList tests_13 = (ArrayList)standardTests.clone();
+ TestCase.resetForgottenFilters(tests_13);
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13), tests_13));
+ }
+ return all;
+}
+}
diff --git a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java
new file mode 100644
index 0000000000..d4f5032082
--- /dev/null
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java
@@ -0,0 +1,879 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression.latest;
+
+import java.util.Map;
+
+import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+@SuppressWarnings("preview")
+public class TextBlockTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_NAMES = new String[] { "test007" };
+ }
+
+ public static Class<?> testClass() {
+ return TextBlockTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_13);
+ }
+ public TextBlockTest(String testName){
+ super(testName);
+ }
+ protected Map<String, String> getCompilerOptions() {
+ return getCompilerOptions(true);
+ }
+ // Enables the tests to run individually
+ protected Map<String, String> getCompilerOptions(boolean previewFlag) {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, previewFlag ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return defaultOptions;
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, Map<String, String> customOptions) {
+ super.runConformTest(testFiles, "", null, true, new String[] {"--enable-preview"}, customOptions, null);
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
+ super.runConformTest(testFiles, expectedOutput, null, true, new String[] {"--enable-preview"}, customOptions, null);
+ }
+ public void test001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\"\"\";\n" +
+ " ^^\n" +
+ "Syntax error on token \"\"\"\", invalid AssignmentOperator\n" +
+ "----------\n");
+ }
+ public void test002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\" \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\" \"\"\";\n" +
+ " ^^^\n" +
+ "Syntax error on token \"\" \"\", invalid AssignmentOperator\n" +
+ "----------\n");
+ }
+ public void test003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "\";\n" +
+ " ^^^^^\n" +
+ "Text block is not properly closed with the delimiter\n" +
+ "----------\n");
+ }
+ /*
+ * negative - unescaped '\' in a text block
+ */
+ public void test004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\def" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\def\"\"\";\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" +
+ "----------\n");
+ }
+ /* empty text block */
+ public void test005() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - escaped '\'
+ */
+ public void test006() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\\\def\"" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "abc\\def\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Positive - Multi line text block with varying indentation
+ * and \n
+ */
+ public void test007() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\n" +
+ " \n" +
+ " line 3\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "line 1\n" + // test framework trims the leading whitespace
+ " line 2\n" +
+ "\n" +
+ "line 3",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Positive - Multi line text block with varying indentation
+ * and \n and \r
+ */
+ public void test008() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\r" +
+ " \r" +
+ " line 3\n\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "line 1\n" +
+ " line 2\n" +
+ "\n" +
+ "line 3", // the trailing whitespace is trimmed by the test framework
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using unescaped '"' in text block
+ */
+ public void test009() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc-def\"" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc-def\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using escaped '"' in text block
+ */
+ public void test010() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc-def\\\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc-def\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using escaped escaped \ and escaped " in text block
+ */
+ public void test011() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc\\\"\"\"def\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc\"\"\"def\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using Unicode in text block
+ * and compare with an equal String literal
+ */
+ public void test012() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\\u0ba4\\u0bae\\u0bbf\\u0bb4\"\"\";\n" +
+ " public static String str = \"\\u0ba4\\u0bae\\u0bbf\\u0bb4\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(str.equals(textb));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "true",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - bigger piece of code as text block
+ */
+ public void test013() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "static String code = \"\"\"\n" +
+ " public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ " }\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(code);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - concatenation of string with text block
+ */
+ public void test014() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String code = \"public void print(Object o) {\\n\" +\n" +
+ " \"\"\"\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ " }\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(code);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - freely using quotes
+ */
+ public void test015() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String story = \"\"\"\n" +
+ " \"When I use a word,\" Humpty Dumpty said,\n" +
+ " in rather a scornful tone, \"it means just what I\n" +
+ " choose it to mean - neither more nor less.\"\n" +
+ " \"The question is,\" said Alice, \"whether you\n" +
+ " can make words mean so many different things.\"\n" +
+ " \"The question is,\" said Humpty Dumpty,\n" +
+ " \"which is to be master - that's all.\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(story);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"When I use a word,\" Humpty Dumpty said,\n" +
+ "in rather a scornful tone, \"it means just what I\n" +
+ "choose it to mean - neither more nor less.\"\n" +
+ "\"The question is,\" said Alice, \"whether you\n" +
+ "can make words mean so many different things.\"\n" +
+ "\"The question is,\" said Humpty Dumpty,\n" +
+ "\"which is to be master - that's all.\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation
+ */
+ public void test016() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\r" +
+ " <body>\\r" +
+ " <p>Hello, world</p>\\r" +
+ " </body>\\r" +
+ " </html>\\r" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation with empty lines
+ */
+ public void test016a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\r\\n" +
+ " <body>\\r\\n" +
+ " <p>Hello, world</p>\\r\\n" +
+ " </body>\\r\\n" +
+ " </html>\\r\\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation with empty lines
+ * output compared with String API
+ */
+ @SuppressWarnings("removal")
+ public void test016b() {
+ String text = " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>";
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ text + "\\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ text.stripIndent().translateEscapes(),
+ null,
+ new String[] {"--enable-preview"});
+
+ }
+ /*
+ * positive - html code with indentation with \r as terminator
+ */
+ public void test016c() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\r" +
+ " <body>\\r" +
+ " <p>Hello, world</p>\\r" +
+ " </body>\\r" +
+ " </html>\\r" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation and trailing whitespace
+ */
+ public void test017() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html> \\r" +
+ " <body> \\r" +
+ " <p>Hello, world</p> \\r" +
+ " </body> \\r" +
+ " </html> \\r" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using octal escape char for trailing whitespace
+ */
+ public void test018() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\040\\040\\r" +
+ " <body>\\040\\040\\r" +
+ " <p>Hello, world</p>\\040\\040\\040\\r" +
+ " </body>\\040\\040\\r" +
+ " </html>\\040\\040\\r" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html> \n" +
+ " <body> \n" +
+ " <p>Hello, world</p> \n" +
+ " </body> \n" +
+ "</html> ",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using text block as a method argument
+ */
+ public void test019() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"\"\"\n" +
+ " <html>\\n" +
+ " <body>\\n" +
+ " <p>Hello, world</p>\\n" +
+ " </body>\\n" +
+ " </html>\\n" +
+ " \"\"\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using variable assigned with text block as a method argument
+ */
+ public void test020() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - assigning strings and text blocks interchangeably.
+ */
+ public void test021() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " String s = html;\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - escaped '\', compare with String::translateEscapes
+ */
+ @SuppressWarnings("removal")
+ public void test022() {
+ String text = "abc\\\\def\"";
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ text +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ text.translateEscapes(),
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - escaped """, compare output with
+ * String::translateEscapes
+ * String::stripIndent
+ */
+ @SuppressWarnings("removal")
+ public void test023() {
+ String text = "abc\\\"\"\"def\" ";
+ System.out.println(text.translateEscapes().stripIndent());
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ text +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ text.translateEscapes().stripIndent(),
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void test024() {
+ runConformTest(
+ new String[] {
+ "Main.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " runConformTest(\n" +
+ " new String[] {\n" +
+ " \"XYZ.java\",\n" +
+ " \"\"\"\n" +
+ " public class XYZ {\n" +
+ " public static String textb = \\\"\"\"\n" +
+ " abc\\\\\\\"\"\"def\" \n" +
+ " \\\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ " } \n" +
+ " \"\"\"\n" +
+ " }, \n" +
+ " \"\",\n" +
+ " null,\n" +
+ " new String[] {\"--enable-preview\"});\n" +
+ " }\n" +
+ " private static void runConformTest(String[] strings, String text, Object object, String[] strings2) {\n" +
+ " System.out.println(strings[1]);\n" +
+ " }\n" +
+ "}"
+ },
+ "public class XYZ {\n" +
+ " public static String textb = \"\"\"\n" +
+ " abc\\\"\"\"def\"\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void test025() {
+ runNegativeTest(
+ new String[] {
+ """
+ X.java""",
+ """
+ public class X {
+ public static String textb = \"""
+ abc\\def\""";
+ public static void main(String[] args) {
+ System.out.println(textb);
+ }
+ }
+ """
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ " abc\\def\"\"\";\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" +
+ "----------\n",
+ null,
+ true,
+ getCompilerOptions());
+ }
+ @SuppressWarnings("removal")
+ public void test026() {
+ String text = "abc\\\\def";
+ runConformTest(
+ new String[] {
+ """
+ X.java""",
+ """
+ public class X {
+ public static String textb = \"""
+ abc\\\\def\""";
+ public static void main(String[] args) {
+ System.out.println(textb);
+ }
+ }
+ """
+ },
+ text.translateEscapes(),
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void test027() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main (String[] args) {\n" +
+ " String xyz = \n" +
+ " \"\"\"\n" +
+ " public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " int arg1 = 0;\n" +
+ " pointer: foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break p;}\\n\"\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ " }\\n\"\"\"; \n" +
+ " System.out.println(xyz);\n" +
+ " }\n" +
+ "}"
+ },
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " int arg1 = 0;\n" +
+ " pointer: foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break p;}\n" +
+ "\"\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ " }",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // An empty text block
+ public void test028() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main (String[] args) {\n" +
+ " String xyz = \n" +
+ " \"\"\"\n" +
+ " \\n\"\"\"; \n" +
+ " System.out.println(xyz);\n" +
+ " }\n" +
+ "}"
+ },
+ "",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // An empty text block
+ public void test029() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "public class Cls2 {\n" +
+ " public static String str = \"\"\"\n" +
+ " Hello Guru \n" +
+ " \n" +
+ " \"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.println(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "Hello Guru", // output comparison tool strips off all trailing whitespace
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug550356() {
+ Map<String, String> options = getCompilerOptions(false);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " ^^^^^^^\n" +
+ "Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+}
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 0000000000..82237b0ffe
--- /dev/null
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java
@@ -0,0 +1,1603 @@
+/*******************************************************************************
+ * 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);
+ }
+ public void testBug545783() 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/bugs/C.java",
+ """
+ package bugs;
+ public class C {
+ int foo(String str) {
+ return switch (str) {
+ case "x", "y" -> {
+ yield 0;
+ }
+ default -> {
+ i: for (int i = 0; i < 10; i++) {
+ if (str.) {
+ yield i;
+ }
+ }
+ yield -1;
+ }
+ };
+ }
+ }
+ """);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "if (str.";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "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.Object;, ()Ljava.lang.Object;, clone, 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" +
+ "length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, 60}\n" +
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}\n" +
+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 90}",
+ requestor.getResults());
+ COMPLETION_PROJECT.setOption(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+}
diff --git a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/tests/latestbree/Activator.java b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/tests/latestbree/Activator.java
new file mode 100644
index 0000000000..30cd86bce6
--- /dev/null
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/tests/latestbree/Activator.java
@@ -0,0 +1,22 @@
+package org.eclipse.jdt.tests.latestbree;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}

Back to the top