Initial merge with BETA_JAVA17 as of Y20210911-0800
diff --git a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF
index 69d3463..2c259f4 100644
--- a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler;singleton:=true
-Bundle-Version: 3.12.1700.qualifier
+Bundle-Version: 3.12.1750.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.compiler,
diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml
index 62b3aa6..bdf289f 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2020 Eclipse Foundation and others.
+ Copyright (c) 2012, 2021 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
- <version>3.12.1700-SNAPSHOT</version>
+ <version>3.12.1750-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
@@ -226,6 +226,36 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,15,16</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-17</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <id>JavaSE-17</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,14,17</tycho.surefire.argLine>
+ </properties>
+ </profile>
</profiles>
</project>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
index e9ca6be..e114d21 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -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
* Technical University Berlin - adapted for Object Teams
@@ -184,6 +188,7 @@
expected15ProblemLog
);
}
+// TODO: Fix this and Enable
public void test0003() {
String[] testFiles = new String[] {
"X.java",
@@ -196,12 +201,7 @@
"1. ERROR in X.java (at line 1)\n" +
" public enum X {\n" +
" ^^^^\n" +
-//{ObjectTeams: in non-deterministic choice, OT/J takes other alternative:
-/* orig:
- "Syntax error on token \"enum\", interface expected\n" +
- :giro */
"Syntax error on token \"enum\", class expected\n" +
-// SH}
"----------\n";
String expected14ProblemLog =
expected13ProblemLog;
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/PatternMatchingSelectionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/PatternMatchingSelectionTest.java
index 8cc8264..94a5232 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/PatternMatchingSelectionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/PatternMatchingSelectionTest.java
@@ -85,7 +85,7 @@
" public X() {\n" +
" }\n" +
" public @SuppressWarnings(\"preview\") void f(Object obj, boolean b) {\n" +
- " final String y_;\n" +
+ " String y_;\n" +
" {\n" +
" <SelectOnName:y_>;\n" +
" }\n" +
@@ -120,7 +120,7 @@
" public X() {\n" +
" }\n" +
" public @SuppressWarnings(\"preview\") void f(Object obj, boolean b) {\n" +
- " final String y_;\n" +
+ " String y_;\n" +
" <SelectOnName:y_>;\n" +
" }\n" +
"}\n";
@@ -142,7 +142,7 @@
+ "}";
String selection = "y_";
- String selectKey = "<SelectionOnLocalName:final String ";
+ String selectKey = "<SelectionOnLocalName:String ";
String expectedSelection = selectKey + selection + ">;";
String selectionIdentifier = "y_";
@@ -151,7 +151,7 @@
" public X() {\n" +
" }\n" +
" public @SuppressWarnings(\"preview\") void f(Object obj, boolean b) {\n" +
- " <SelectionOnLocalName:final String y_>;\n" +
+ " <SelectionOnLocalName:String y_>;\n" +
" }\n" +
"}\n";
String expectedReplacedSource = "y_";
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
index 2832012..84a0b6a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -266,7 +266,6 @@
tests_15.add(SelectionParserTest12.class);
tests_15.add(ModuleDeclarationSyntaxTest.class);
tests_15.add(JEP286ReservedWordTest.class);
- tests_15.add(PatternMatchingSelectionTest.class);
// Reset forgotten subsets tests
TestCase.TESTS_PREFIX = null;
TestCase.TESTS_NAMES = null;
@@ -275,6 +274,53 @@
TestCase.RUN_ONLY_ID = null;
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_15), tests_15));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_16) != 0) {
+ ArrayList tests_16 = (ArrayList)testClasses.clone();
+ tests_16.addAll(TEST_CLASSES_1_5);
+ tests_16.add(ParserTest1_7.class);
+ tests_16.add(LambdaExpressionSyntaxTest.class);
+ tests_16.add(ReferenceExpressionSyntaxTest.class);
+ tests_16.add(TypeAnnotationSyntaxTest.class);
+ tests_16.add(CompletionParserTest18.class);
+ tests_16.add(SelectionParserTest18.class);
+ tests_16.add(SelectionParserTest9.class);
+ tests_16.add(SelectionParserTest10.class);
+ tests_16.add(SelectionParserTest12.class);
+ tests_16.add(ModuleDeclarationSyntaxTest.class);
+ tests_16.add(JEP286ReservedWordTest.class);
+ tests_16.add(PatternMatchingSelectionTest.class);
+ // Reset forgotten subsets tests
+ TestCase.TESTS_PREFIX = null;
+ TestCase.TESTS_NAMES = null;
+ TestCase.TESTS_NUMBERS= null;
+ TestCase.TESTS_RANGE = null;
+ TestCase.RUN_ONLY_ID = null;
+
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16), tests_16));
+ }
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_17) != 0) {
+ ArrayList tests_17 = (ArrayList)testClasses.clone();
+ tests_17.addAll(TEST_CLASSES_1_5);
+ tests_17.add(ParserTest1_7.class);
+ tests_17.add(LambdaExpressionSyntaxTest.class);
+ tests_17.add(ReferenceExpressionSyntaxTest.class);
+ tests_17.add(TypeAnnotationSyntaxTest.class);
+ tests_17.add(CompletionParserTest18.class);
+ tests_17.add(SelectionParserTest18.class);
+ tests_17.add(SelectionParserTest9.class);
+ tests_17.add(SelectionParserTest10.class);
+ tests_17.add(SelectionParserTest12.class);
+ tests_17.add(ModuleDeclarationSyntaxTest.class);
+ tests_17.add(JEP286ReservedWordTest.class);
+ tests_17.add(PatternMatchingSelectionTest.class);
+ // Reset forgotten subsets tests
+ TestCase.TESTS_PREFIX = null;
+ TestCase.TESTS_NAMES = null;
+ TestCase.TESTS_NUMBERS= null;
+ TestCase.TESTS_RANGE = null;
+ TestCase.RUN_ONLY_ID = null;
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17), tests_17));
+ }
return all;
}
public static Test suite() {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index deab03b..71c673a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.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
* Technical University Berlin - adapted for Object Teams
@@ -310,6 +314,8 @@
return JavaCore.VERSION_15;
} else if(rawVersion.startsWith("16")) {
return JavaCore.VERSION_16;
+ } else if(rawVersion.startsWith("17")) {
+ return JavaCore.VERSION_17;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
@@ -493,6 +499,20 @@
return 0200;
}
}
+ if (version == JavaCore.VERSION_17) {
+ if ("17-ea".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("17".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("17.0.1".equals(rawVersion)) {
+ return 0100;
+ }
+ if ("17.0.2".equals(rawVersion)) {
+ return 0200;
+ }
+ }
throw new RuntimeException("unknown raw javac version: " + rawVersion);
}
// returns 0L if everything went fine; else the lower word contains the
@@ -1634,19 +1654,28 @@
return null;
}
- protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
+ protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map<String, String> options) {
+ if (options == null)
+ options = getCompilerOptions();
String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
if ("".equals(encoding))
encoding = null;
+ String release = null;
+ if (CompilerOptions.ENABLED.equals(options.get(CompilerOptions.OPTION_Release))) {
+ release = getCompilerOptions().get(CompilerOptions.OPTION_Compliance);
+ }
if (useDefaultClasspaths && encoding == null)
- return DefaultJavaRuntimeEnvironment.create(this.classpaths);
+ return DefaultJavaRuntimeEnvironment.create(this.classpaths, release);
// fall back to FileSystem
INameEnvironment[] classLibs = new INameEnvironment[1];
classLibs[0] = new FileSystem(this.classpaths, new String[]{}, // ignore initial file names
- encoding // default encoding
+ encoding, release
);
return classLibs;
}
+ protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
+ return getClassLibs(useDefaultClasspaths, null);
+ }
@Override
protected Map<String, String> getCompilerOptions() {
Map<String, String> defaultOptions = super.getCompilerOptions();
@@ -1728,9 +1757,12 @@
/*
* Will consider first the source units passed as arguments, then investigate the classpath: jdklib + output dir
*/
- protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) {
+ protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map<String, String> options) {
this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths;
- return new InMemoryNameEnvironment(testFiles, getClassLibs(classPaths == null));
+ return new InMemoryNameEnvironment(testFiles, getClassLibs((classPaths == null), options));
+ }
+ protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) {
+ return getNameEnvironment(testFiles, classPaths, null);
}
protected IProblemFactory getProblemFactory() {
return new DefaultProblemFactory(Locale.getDefault());
@@ -3445,7 +3477,7 @@
CompilerOptions compilerOptions = new CompilerOptions(options);
compilerOptions.performMethodsFullRecovery = performStatementsRecovery;
compilerOptions.performStatementsRecovery = performStatementsRecovery;
- INameEnvironment nameEnvironment = getNameEnvironment(dependantFiles, classLibraries);
+ INameEnvironment nameEnvironment = getNameEnvironment(dependantFiles, classLibraries, options);
Compiler batchCompiler =
new Compiler(
nameEnvironment,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
index c2761d8..ecfbe4c 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017, 2018 GK Software AG, and others.
+ * Copyright (c) 2017, 2021 GK Software AG, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -50,9 +50,9 @@
}
@Override
- protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) {
+ protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map<String, String> options) {
this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths;
- INameEnvironment[] classLibs = getClassLibs(classPaths == null);
+ INameEnvironment[] classLibs = getClassLibs(classPaths == null, options);
for (INameEnvironment nameEnvironment : classLibs) {
((FileSystem) nameEnvironment).scanForModules(createParser());
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index eaebd57..a656fa2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -106,12 +106,12 @@
return options;
}
@Override
- protected INameEnvironment getNameEnvironment(String[] testFiles, String[] classPaths) {
+ protected INameEnvironment getNameEnvironment(String[] testFiles, String[] classPaths, Map<String, String> options) {
if (this.javaClassLib != null) {
this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths;
return new InMemoryNameEnvironment(testFiles, new INameEnvironment[] {this.javaClassLib });
}
- return super.getNameEnvironment(testFiles, classPaths);
+ return super.getNameEnvironment(testFiles, classPaths, options);
}
/* (non-Javadoc)
@@ -1077,6 +1077,13 @@
// check annotation member modifiers (validity unchanged despite grammar change from JSR 335 - default methods)
// and https://bugs.eclipse.org/bugs/show_bug.cgi?id=3383968
public void test039a() {
+ String extra = this.complianceLevel < ClassFileConstants.JDK17 ? "" :
+ "----------\n" +
+ "1. WARNING in X.java (at line 2)\n" +
+ " strictfp double val() default 0.1;\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n";
+ int offset = this.complianceLevel < ClassFileConstants.JDK17 ? 0 : 1;
this.runNegativeTest(
new String[] {
"X.java",
@@ -1085,13 +1092,14 @@
" synchronized String id() default \"zero\";\n" +
"}"
},
+ extra +
"----------\n" +
- "1. ERROR in X.java (at line 2)\n" +
+ (1 + offset) + ". ERROR in X.java (at line 2)\n" +
" strictfp double val() default 0.1;\n" +
" ^^^^^\n" +
"Illegal modifier for the annotation attribute X.val; only public & abstract are permitted\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
+ (2 + offset) + ". ERROR in X.java (at line 3)\n" +
" synchronized String id() default \"zero\";\n" +
" ^^^^\n" +
"Illegal modifier for the annotation attribute X.id; only public & abstract are permitted\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 4250a24..02bbb85 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -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
* Benjamin Muskalla - Contribution for bug 239066
@@ -60,8 +64,10 @@
import org.eclipse.jdt.internal.compiler.batch.ClasspathJar;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.batch.Main;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer;
@@ -594,6 +600,14 @@
"",
true);
}
+private String getVersionOptions() {
+ StringBuilder builder = new StringBuilder();
+ String template = " -15 -15.0 use 15 compliance (-source 15 -target 15)\n";
+ for(int i = ClassFileConstants.MAJOR_VERSION_15; i <= ClassFileConstants.MAJOR_LATEST_VERSION; i++) {
+ builder.append(template.replace("15", "" + (i - ClassFileConstants.MAJOR_VERSION_0)));
+ }
+ return builder.toString();
+}
// command line - help
// amended for https://bugs.eclipse.org/bugs/show_bug.cgi?id=141512 (checking
// width)
@@ -679,11 +693,10 @@
" -12 -12.0 use 12 compliance (-source 12 -target 12)\n" +
" -13 -13.0 use 13 compliance (-source 13 -target 13)\n" +
" -14 -14.0 use 14 compliance (-source 14 -target 14)\n" +
- " -15 -15.0 use 15 compliance (-source 15 -target 15)\n" +
- " -16 -16.0 use 16 compliance (-source 16 -target 16)\n" +
- " -source <version> set source level: 1.3 to 1.9, 10 to 16\n" +
+ getVersionOptions() +
+ " -source <version> set source level: 1.3 to 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 6, 6.0, etc)\n" +
- " -target <version> set classfile target: 1.3 to 1.9, 10 to 16\n" +
+ " -target <version> set classfile target: 1.3 to 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" +
" (or 6, 6.0, etc)\n" +
" cldc1.1 can also be used to generate the StackMap\n" +
" attribute\n" +
@@ -13304,4 +13317,15 @@
true);
}
+public void testBug573153() {
+ String output = MAIN.bind("configure.source", "10");
+ String template = "source level should be in '1.1'...'1.8','9'...'15' (or '5.0'..'15.0'): 10";
+ template = template.replace("15", CompilerOptions.getLatestVersion());
+ assertEquals("configure.source is not updated", template, output);
+
+ output = MAIN.bind("configure.targetJDK", "10");
+ template = "target level should be in '1.1'...'1.8','9'...'15' (or '5.0'..'15.0') or cldc1.1: 10";
+ template = template.replace("15", CompilerOptions.getLatestVersion());
+ assertEquals("configure.source is not updated", template, output);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java
index caa176c..d60df4f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java
@@ -86,8 +86,6 @@
}
}
public void testBug570399(){
- if (!AbstractBatchCompilerTest.isJREVersionEqualTo(CompilerOptions.VERSION_16))
- return;
this.runConformTest(
new String[] {
"src/X.java",
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_15.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java
similarity index 60%
rename from org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_15.java
rename to org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java
index eb0282d..716d006 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_15.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java
@@ -1,16 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2013, 2020 GoPivotal, Inc and others
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
+ * Copyright (c) 2020, 2021 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
*
+ * 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:
- * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
- * Bug 407191 - [1.8] Binary access support for type annotations
+ * IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -18,21 +20,22 @@
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@SuppressWarnings({ "rawtypes" })
-public class ClassFileReaderTest_15 extends AbstractRegressionTest {
+public class ClassFileReaderTest_17 extends AbstractRegressionTest {
static {
}
public static Test suite() {
- return buildMinimalComplianceTestSuite(testClass(), F_15);
+ return buildMinimalComplianceTestSuite(testClass(), F_17);
}
public static Class testClass() {
- return ClassFileReaderTest_15.class;
+ return ClassFileReaderTest_17.class;
}
- public ClassFileReaderTest_15(String name) {
+ public ClassFileReaderTest_17(String name) {
super(name);
}
@@ -40,8 +43,7 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- this.complianceLevel = ClassFileConstants.JDK16;
- this.enablePreview = true;
+ this.complianceLevel = ClassFileConstants.JDK17;
}
public void testBug564227_001() throws Exception {
@@ -107,4 +109,38 @@
int modifiers = classFileReader.getModifiers();
assertTrue("sealed modifier expected", (modifiers & ExtraCompilerModifiers.AccSealed) != 0);
}
+ public void testBug545510_1() throws Exception {
+ String source =
+ "strictfp class X {\n"+
+ "}";
+
+ org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source);
+
+ int modifiers = classFileReader.getModifiers();
+ assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0);
+ }
+ public void testBug545510_2() throws Exception {
+ String source =
+ "class X {\n"+
+ " strictfp void foo() {}\n"+
+ "}";
+
+ org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source);
+ IBinaryMethod[] methods = classFileReader.getMethods();
+ IBinaryMethod method = methods[1];
+ int modifiers = method.getModifiers();
+ assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0);
+ }
+ public void testBug545510_3() throws Exception {
+ String source =
+ "strictfp class X {\n"+
+ " void foo() {}\n"+
+ "}";
+
+ org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source);
+ IBinaryMethod[] methods = classFileReader.getMethods();
+ IBinaryMethod method = methods[1];
+ int modifiers = method.getModifiers();
+ assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0);
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 0b1310a..a657031 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.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
* Benjamin Muskalla - Contribution for bug 239066
@@ -560,6 +564,7 @@
expectedProblemAttributes.put("IllegalModifierForArgument", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalModifierForClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalModifierForConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
+ expectedProblemAttributes.put("StrictfpNotRequired", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
expectedProblemAttributes.put("IllegalModifierForEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalModifierForEnumConstant", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalModifierForEnumConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
@@ -1103,6 +1108,7 @@
expectedProblemAttributes.put("UnnecessaryElse", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
expectedProblemAttributes.put("UnnecessaryInstanceof", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
expectedProblemAttributes.put("UnnecessaryNLSTag", new ProblemAttributes(CategorizedProblem.CAT_NLS));
+ expectedProblemAttributes.put("UnnecessaryNullCaseInSwitchOverNonNull", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("UnqualifiedFieldAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
expectedProblemAttributes.put("UnreachableCatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("UnresolvedVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
@@ -1376,10 +1382,22 @@
expectedProblemAttributes.put("SealedNotDirectSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedLocalDirectSuperTypeSealed", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedAnonymousClassCannotExtendSealedType", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("LocalReferencedInGuardMustBeEffectivelyFinal", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedSuperTypeInDifferentPackage", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedSuperTypeDisallowed", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SafeVarargsOnSyntheticRecordAccessor", new ProblemAttributes(true));
expectedProblemAttributes.put("DiscouragedValueBasedTypeSynchronization", new ProblemAttributes(true));
+ expectedProblemAttributes.put("SwitchPatternConstantWithPatternIncompatible", new ProblemAttributes(true));
+ expectedProblemAttributes.put("IllegalFallthroughToPattern", new ProblemAttributes(true));
+ expectedProblemAttributes.put("SwitchPatternOnlyOnePatternCaseLabelAllowed", new ProblemAttributes(true));
+ expectedProblemAttributes.put("SwitchPatternBothPatternAndDefaultCaseLabelsNotAllowed", new ProblemAttributes(true));
+ expectedProblemAttributes.put("SwitchPatternBothNullAndNonTypePatternNotAllowed", new ProblemAttributes(true));
+ expectedProblemAttributes.put("PatternDominated", new ProblemAttributes(true));
+ expectedProblemAttributes.put("IllegalTotalPatternWithDefault", new ProblemAttributes(true));
+ expectedProblemAttributes.put("EnhancedSwitchMissingDefaultCase", new ProblemAttributes(true));
+ expectedProblemAttributes.put("DuplicateTotalPattern", new ProblemAttributes(true));
+ expectedProblemAttributes.put("UnexpectedTypeinSwitchPattern", new ProblemAttributes(true));
+
StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -1706,6 +1724,7 @@
expectedProblemAttributes.put("IllegalModifierForArgument", SKIP);
expectedProblemAttributes.put("IllegalModifierForClass", SKIP);
expectedProblemAttributes.put("IllegalModifierForConstructor", SKIP);
+ expectedProblemAttributes.put("StrictfpNotRequired", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnum", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnumConstant", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnumConstructor", SKIP);
@@ -2252,6 +2271,7 @@
expectedProblemAttributes.put("UnnecessaryElse", new ProblemAttributes(JavaCore.COMPILER_PB_UNNECESSARY_ELSE));
expectedProblemAttributes.put("UnnecessaryInstanceof", new ProblemAttributes(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK));
expectedProblemAttributes.put("UnnecessaryNLSTag", new ProblemAttributes(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL));
+ expectedProblemAttributes.put("UnnecessaryNullCaseInSwitchOverNonNull", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
expectedProblemAttributes.put("UnqualifiedFieldAccess", new ProblemAttributes(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS));
expectedProblemAttributes.put("UnreachableCatch", SKIP);
expectedProblemAttributes.put("UnresolvedVariable", SKIP);
@@ -3062,8 +3082,20 @@
expectedProblemAttributes.put("SealedSuperTypeInDifferentPackage", SKIP);
expectedProblemAttributes.put("SealedSuperTypeDisallowed", SKIP);
expectedProblemAttributes.put("SealedAnonymousClassCannotExtendSealedType", SKIP);
+ expectedProblemAttributes.put("LocalReferencedInGuardMustBeEffectivelyFinal", SKIP);
expectedProblemAttributes.put("SafeVarargsOnSyntheticRecordAccessor", SKIP);
expectedProblemAttributes.put("DiscouragedValueBasedTypeSynchronization", SKIP);
+ expectedProblemAttributes.put("SwitchPatternConstantWithPatternIncompatible", SKIP);
+ expectedProblemAttributes.put("IllegalFallthroughToPattern", SKIP);
+ expectedProblemAttributes.put("SwitchPatternOnlyOnePatternCaseLabelAllowed", SKIP);
+ expectedProblemAttributes.put("SwitchPatternBothPatternAndDefaultCaseLabelsNotAllowed", SKIP);
+ expectedProblemAttributes.put("SwitchPatternBothNullAndNonTypePatternNotAllowed", SKIP);
+ expectedProblemAttributes.put("PatternDominated", SKIP);
+ expectedProblemAttributes.put("IllegalTotalPatternWithDefault", SKIP);
+ expectedProblemAttributes.put("EnhancedSwitchMissingDefaultCase", SKIP);
+ expectedProblemAttributes.put("DuplicateTotalPattern", SKIP);
+ expectedProblemAttributes.put("UnexpectedTypeinSwitchPattern", SKIP);
+
Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java
index c99c66e..ac050e9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others.
+ * Copyright (c) 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,25 +13,49 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
+import java.io.File;
import java.util.Iterator;
import java.util.Map.Entry;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
+import org.eclipse.jdt.internal.compiler.util.JRTUtil;
public class DefaultJavaRuntimeEnvironment extends FileSystem {
- private DefaultJavaRuntimeEnvironment(String[] jreClasspaths) {
- super(jreClasspaths, new String[] {} /* ignore initial file names */, null);
+ private DefaultJavaRuntimeEnvironment(String[] jreClasspaths, String release) {
+ super(jreClasspaths, new String[] {} /* ignore initial file names */, null, release);
+ }
+ private DefaultJavaRuntimeEnvironment(Classpath[] jreClasspaths) {
+ super(jreClasspaths, new String[] {} /* ignore initial file names */, false);
}
private static INameEnvironment[] defaultJreClassLibs;
public static INameEnvironment[] create(String[] jreClasspaths) {
+ return create(jreClasspaths, null);
+ }
+ public static INameEnvironment[] create(String[] jreClasspaths, String release) {
+ if (defaultJreClassLibs == null) {
+ if (release != null && !release.equals("")) {
+ defaultJreClassLibs = new INameEnvironment[1];
+ Classpath[] classpath = new Classpath[jreClasspaths.length];
+ for(int i = 0; i < classpath.length; i++) {
+ if (jreClasspaths[i].endsWith(JRTUtil.JRT_FS_JAR)) {
+ File file = new File(jreClasspaths[0]);
+ classpath[i] = FileSystem.getOlderSystemRelease(file.getParentFile().getParent(), release, null);
+
+ } else {
+ classpath[i] = FileSystem.getClasspath(jreClasspaths[i], null, null);
+ }
+ }
+ defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(classpath);
+ }
+ }
if (defaultJreClassLibs == null) {
defaultJreClassLibs = new INameEnvironment[1];
- defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(jreClasspaths);
+ defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(jreClasspaths, release);
}
return defaultJreClassLibs;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java
index a14082e..dc9e3bb 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java
@@ -52,10 +52,10 @@
}
@Override
-protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) {
+protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map<String, String> options) {
// constructs a name environment that is able to hide a type of name 'this.invisibleType':
this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths;
- return new InMemoryNameEnvironment(testFiles, getClassLibs(classPaths == null)) {
+ return new InMemoryNameEnvironment(testFiles, getClassLibs(classPaths == null, options)) {
@Override
public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
if (DeprecatedTest.this.invisibleType != null && CharOperation.equals(DeprecatedTest.this.invisibleType, compoundTypeName))
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java
index 4c8a684..fa6372d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java
@@ -2467,6 +2467,25 @@
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85397
public void test079() throws Exception {
+ String op =
+ this.complianceLevel < ClassFileConstants.JDK17 ?
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " private strictfp X() {}\n" +
+ " ^^^\n" +
+ "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" +
+ "----------\n" :
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " private strictfp X() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 3)\n" +
+ " private strictfp X() {}\n" +
+ " ^^^\n" +
+ "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" +
+ "----------\n";
this.runNegativeTest(
new String[] {
"X.java",
@@ -2475,12 +2494,7 @@
" private strictfp X() {}\n" +
"}\n"
},
- "----------\n" +
- "1. ERROR in X.java (at line 3)\n" +
- " private strictfp X() {}\n" +
- " ^^^\n" +
- "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" +
- "----------\n"
+ op
);
this.runConformTest(
new String[] {
@@ -2493,10 +2507,17 @@
""
);
- String[] expectedOutputs = new String[] {
- " private strictfp X(java.lang.String arg0, int arg1);\n",
- " public static strictfp X[] values();\n",
- " public static strictfp X valueOf(java.lang.String arg0);\n"
+ String[] expectedOutputs =
+ this.complianceLevel < ClassFileConstants.JDK17 ?
+ new String[] {
+ " private strictfp X(java.lang.String arg0, int arg1);\n",
+ " public static strictfp X[] values();\n",
+ " public static strictfp X valueOf(java.lang.String arg0);\n"
+ } :
+ new String[] {
+ " private X(java.lang.String arg0, int arg1);\n",
+ " public static X[] values();\n",
+ " public static X valueOf(java.lang.String arg0);\n"
};
ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 1769812..3154f1d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.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
* Technical University Berlin - adapted for Object Teams
@@ -5410,7 +5414,7 @@
customOptions);
}
public void test0178a() {
- if (this.complianceLevel < ClassFileConstants.JDK16)
+ if (this.complianceLevel < ClassFileConstants.JDK17)
return;
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java
new file mode 100644
index 0000000..4b17c7d
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * Copyright (c) 2021 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
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class InstanceofPrimaryPatternTest extends AbstractRegressionTest {
+
+ private static final JavacTestOptions JAVAC_OPTIONS = new JavacTestOptions("-source 17 --enable-preview -Xlint:-preview");
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] { "test005" };
+ }
+
+ public static Class<?> testClass() {
+ return InstanceofPrimaryPatternTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_17);
+ }
+ public InstanceofPrimaryPatternTest(String testName){
+ super(testName);
+ }
+ // Enables the tests to run individually
+ protected Map<String, String> getCompilerOptions(boolean preview) {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel()
+ && preview) {
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ }
+ return defaultOptions;
+ }
+
+ protected Map<String, String> getCompilerOptions() {
+ return getCompilerOptions(true);
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
+ if(!isJRE17Plus)
+ return;
+ runConformTest(testFiles, expectedOutput, customOptions, new String[] {"--enable-preview"}, JAVAC_OPTIONS);
+ }
+ protected void runNegativeTest(
+ String[] testFiles,
+ String expectedCompilerLog,
+ String javacLog,
+ String[] classLibraries,
+ boolean shouldFlushOutputDirectory,
+ Map<String, String> customOptions) {
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedCompilerLog = expectedCompilerLog;
+ runner.javacTestOptions = JAVAC_OPTIONS;
+ runner.customOptions = customOptions;
+ runner.expectedJavacOutputString = javacLog;
+ runner.runNegativeTest();
+ }
+ public void test001() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof String s) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello World!",
+ options);
+ }
+ public void test002() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof (String s)) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello World!",
+ options);
+ }
+ public void test003() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof ((String s))) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello World!",
+ options);
+ }
+ public void test004() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof ((((String s))))) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello World!",
+ options);
+ }
+ public void test005() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof (String s) && (s.length() > 0)) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello World!",
+ options);
+ }
+ public void test006() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof (String s && s.length() > 0)) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " Zork();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void test007() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof var s) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " Zork();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (obj instanceof var s) {\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void test008() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof (((var s)))) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " Zork();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (obj instanceof (((var s)))) {\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void test009() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void foo(String s) {\n" +
+ " if (s instanceof Object o) {\n" +
+ " System.out.println(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"Hello World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (s instanceof Object o) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Expression type cannot be a subtype of the Pattern type\n" +
+ "----------\n");
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
index d74edfb..3912c46 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2019 GK Software AG, IBM Corporation and others.
+ * Copyright (c) 2013, 2021 GK Software AG, IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -81,6 +81,54 @@
// default methods with various modifiers, negative cases
public void testModifiers1a() {
String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : "";
+ String op = this.complianceLevel < ClassFileConstants.JDK17 ?
+ "----------\n" +
+ "1. ERROR in I.java (at line 5)\n" +
+ " public default synchronized void foo2() { System.exit(0); }\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo2; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
+ "----------\n" +
+ "2. ERROR in I.java (at line 7)\n" +
+ " public default strictfp synchronized void foo4() {}\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo4; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
+ "----------\n" +
+ "3. ERROR in I.java (at line 8)\n" +
+ " public default strictfp synchronized @Annot void foo5() {}\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo5; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
+ "----------\n" :
+ "----------\n" +
+ "1. ERROR in I.java (at line 5)\n" +
+ " public default synchronized void foo2() { System.exit(0); }\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo2; only public, private, abstract, default, static and strictfp are permitted\n" +
+ "----------\n" +
+ "2. WARNING in I.java (at line 6)\n" +
+ " strictfp default void foo3() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" +
+ "3. WARNING in I.java (at line 7)\n" +
+ " public default strictfp synchronized void foo4() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" +
+ "4. ERROR in I.java (at line 7)\n" +
+ " public default strictfp synchronized void foo4() {}\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo4; only public, private, abstract, default, static and strictfp are permitted\n" +
+ "----------\n" +
+ "5. WARNING in I.java (at line 8)\n" +
+ " public default strictfp synchronized @Annot void foo5() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" +
+ "6. ERROR in I.java (at line 8)\n" +
+ " public default strictfp synchronized @Annot void foo5() {}\n" +
+ " ^^^^^^\n" +
+ "Illegal modifier for the interface method foo5; only public, private, abstract, default, static and strictfp are permitted\n" +
+ "----------\n";
runNegativeTest(
new String[] {
"I.java",
@@ -93,22 +141,7 @@
" public default strictfp synchronized void foo4() {}\n" +
" public default strictfp synchronized @Annot void foo5() {}\n" +
"}\n"},
- "----------\n" +
- "1. ERROR in I.java (at line 5)\n" +
- " public default synchronized void foo2() { System.exit(0); }\n" +
- " ^^^^^^\n" +
- "Illegal modifier for the interface method foo2; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
- "----------\n" +
- "2. ERROR in I.java (at line 7)\n" +
- " public default strictfp synchronized void foo4() {}\n" +
- " ^^^^^^\n" +
- "Illegal modifier for the interface method foo4; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
- "----------\n" +
- "3. ERROR in I.java (at line 8)\n" +
- " public default strictfp synchronized @Annot void foo5() {}\n" +
- " ^^^^^^\n" +
- "Illegal modifier for the interface method foo5; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
- "----------\n");
+ op);
}
// default methods with various modifiers, simple syntax error blows the parser
@@ -148,7 +181,19 @@
" ^^^^^^^\n" +
"Syntax error, insert \"MethodSpecsLong EmptyParameterMappings\" to complete InvalidCallinBinding\n" +
// SH}
- "----------\n");
+ "----------\n" +
+ (this.complianceLevel >= ClassFileConstants.JDK17 ?
+ "4. WARNING in I.java (at line 7)\n" +
+ " default public strictfp void foo4() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" +
+ "5. WARNING in I.java (at line 8)\n" +
+ " public strictfp default @Annot void foo5() {}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" +
+ "----------\n" : "")
+ );
}
// regular interface with illegal modifiers
@@ -2147,6 +2192,13 @@
// test for different error messages in modifiers.
public void test400977() {
String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : "";
+ String extra = this.complianceLevel >= ClassFileConstants.JDK17 ?
+ "----------\n" +
+ "2. WARNING in I.java (at line 3)\n" +
+ " public abstract default strictfp final void bar();}\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" : "";
+ int offset = this.complianceLevel >= ClassFileConstants.JDK17 ? 1 : 0;
runNegativeTest(
new String[] {
"I.java",
@@ -2159,18 +2211,19 @@
" default abstract void foo();\n" +
" ^^^^^\n" +
"Illegal combination of modifiers for the interface method foo; only one of abstract, default, or static permitted\n" +
+ extra +
"----------\n" +
- "2. ERROR in I.java (at line 3)\n" +
+ (2 + offset) + ". ERROR in I.java (at line 3)\n" +
" public abstract default strictfp final void bar();}\n" +
" ^^^^^\n" +
"strictfp is not permitted for abstract interface method bar\n" +
"----------\n" +
- "3. ERROR in I.java (at line 3)\n" +
+ (3 + offset) + ". ERROR in I.java (at line 3)\n" +
" public abstract default strictfp final void bar();}\n" +
" ^^^^^\n" +
"Illegal combination of modifiers for the interface method bar; only one of abstract, default, or static permitted\n" +
"----------\n" +
- "4. ERROR in I.java (at line 3)\n" +
+ (3 + offset) + ". ERROR in I.java (at line 3)\n" +
" public abstract default strictfp final void bar();}\n" +
" ^^^^^\n" +
"Illegal modifier for the interface method bar; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java
index 3bdd55d..e4ca9e6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1746,7 +1746,7 @@
* Bug 86769: [javadoc] Warn/Error for 'Missing javadoc comments' doesn't recognize private inner classes
* @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=86769"
*/
- public void testBug86769() {
+ public void _testBug86769() {
this.reportMissingJavadocComments = CompilerOptions.ERROR;
runNegativeTest(
new String[] {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java
index 24dcdf6..4241dae 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java
@@ -7,6 +7,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
*******************************************************************************/
@@ -65,12 +69,11 @@
runner.expectedOutputString = expectedOutput;
runner.vmArguments = new String[] {"--enable-preview"};
runner.customOptions = customOptions;
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("16");
runner.runConformTest();
}
@Override
protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
- runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("15"));
+ runNegativeTest(testFiles, expectedCompilerLog, null);
}
protected void runWarningTest(String[] testFiles, String expectedCompilerLog) {
runWarningTest(testFiles, expectedCompilerLog, null);
@@ -85,9 +88,6 @@
runner.testFiles = testFiles;
runner.expectedCompilerLog = expectedCompilerLog;
runner.customOptions = customOptions;
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("15") :
- JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions);
runner.runWarningTest();
}
@@ -988,6 +988,7 @@
"----------\n"
);
}
+
public void testBug568514LocalEnums_004() {
this.runNegativeTest(
new String[] {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index b66db74..e3f06ee 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.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
*******************************************************************************/
@@ -846,7 +850,7 @@
"p/X.java",
"package p;\n" +
"public class X {\n" +
- " java.lang.SecurityManager man = null;\n" +
+ " java.lang.SecurityException ex = null;\n" +
"}",
"module-info.java",
"module mod.one { \n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
index ed6c2c7..8dc580b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2019 IBM Corporation and others.
+ * Copyright (c) 2011, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -473,6 +473,13 @@
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384595, Reject illegal modifiers on lambda arguments.
public void test014() {
+ String extra = this.complianceLevel < ClassFileConstants.JDK17 ? "" :
+ "----------\n" +
+ "2. WARNING in X.java (at line 5)\n" +
+ " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
+ " ^^^^^^^^\n" +
+ "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n";
+ int offset = this.complianceLevel < ClassFileConstants.JDK17 ? 0 : 1;
this.runNegativeTest(
new String[] {
"X.java",
@@ -490,23 +497,24 @@
" I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
" ^^^^^^^^^\n" +
"Undefined cannot be resolved to a type\n" +
+ extra +
"----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
+ (2 + offset) + ". ERROR in X.java (at line 5)\n" +
" I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
" ^^^^^^\n" +
"Lambda expression\'s parameter o is expected to be of type int\n" +
"----------\n" +
- "3. ERROR in X.java (at line 5)\n" +
+ (3 + offset) + ". ERROR in X.java (at line 5)\n" +
" I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
" ^\n" +
"Illegal modifier for parameter o; only final is permitted\n" +
"----------\n" +
- "4. ERROR in X.java (at line 5)\n" +
+ (4 + offset) + ". ERROR in X.java (at line 5)\n" +
" I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
" ^\n" +
"Illegal modifier for parameter p; only final is permitted\n" +
"----------\n" +
- "5. ERROR in X.java (at line 5)\n" +
+ (5 + offset) + ". ERROR in X.java (at line 5)\n" +
" I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" +
" ^\n" +
"Void methods cannot return a value\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java
new file mode 100644
index 0000000..d37f557
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java
@@ -0,0 +1,499 @@
+/*******************************************************************************
+ * Copyright (c) 2021 GK Software SE, 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
+ *
+ * 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:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import static org.eclipse.jdt.core.tests.util.Util.createJar;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.jdt.core.tests.util.Util;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class NullAnnotationTests17 extends AbstractNullAnnotationTest {
+
+ public NullAnnotationTests17(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NAMES = new String[] { "test_totalTypePatternNonNullExpression" };
+// TESTS_NUMBERS = new int[] { 001 };
+// TESTS_RANGE = new int[] { 1, 12 };
+ }
+
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_17);
+ }
+
+ public static Class<?> testClass() {
+ return NullAnnotationTests17.class;
+ }
+
+ @Deprecated // super method is deprecated
+ @Override
+ protected void setUpAnnotationLib() throws IOException {
+ if (this.LIBS == null) {
+ String[] defaultLibs = getDefaultClassPaths();
+ int len = defaultLibs.length;
+ this.LIBS = new String[len+1];
+ System.arraycopy(defaultLibs, 0, this.LIBS, 0, len);
+ this.LIBS[len] = createAnnotation_2_2_jar(Util.getOutputDirectory() + File.separator, null);
+ }
+ }
+
+ public static String createAnnotation_2_2_jar(String dirName, String jcl17Path) throws IOException {
+ // role our own annotation library as long as o.e.j.annotation is still at BREE 1.8:
+ String jarFileName = dirName + "org.eclipse.jdt.annotation_2.2.0.jar";
+ createJar(new String[] {
+ "module-info.java",
+ "module org.eclipse.jdt.annotation {\n" +
+ " exports org.eclipse.jdt.annotation;\n" +
+ "}\n",
+
+ "org/eclipse/jdt/annotation/DefaultLocation.java",
+ "package org.eclipse.jdt.annotation;\n" +
+ "\n" +
+ "public enum DefaultLocation {\n" +
+ " \n" +
+ " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" +
+ "}\n",
+
+ "org/eclipse/jdt/annotation/NonNullByDefault.java",
+ "package org.eclipse.jdt.annotation;\n" +
+ "\n" +
+ "import java.lang.annotation.ElementType;\n" +
+ "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" +
+ "\n" +
+ "import java.lang.annotation.*;\n" +
+ " \n" +
+ "@Documented\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE })\n" +
+ "public @interface NonNullByDefault {\n" +
+ " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" +
+ "}",
+
+ "org/eclipse/jdt/annotation/NonNull.java",
+ "package org.eclipse.jdt.annotation;\n" +
+ "import static java.lang.annotation.ElementType.TYPE_USE;\n" +
+ "\n" +
+ "import java.lang.annotation.*;\n" +
+ " \n" +
+ "@Documented\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ TYPE_USE })\n" +
+ "public @interface NonNull {\n" +
+ " // marker annotation with no members\n" +
+ "}\n",
+
+ "org/eclipse/jdt/annotation/Nullable.java",
+ "package org.eclipse.jdt.annotation;\n" +
+ "\n" +
+ "import static java.lang.annotation.ElementType.TYPE_USE;\n" +
+ "\n" +
+ "import java.lang.annotation.*;\n" +
+ " \n" +
+ "@Documented\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ TYPE_USE })\n" +
+ "public @interface Nullable {\n" +
+ " // marker annotation with no members\n" +
+ "}\n"
+ },
+ null,
+ jarFileName,
+ jcl17Path != null ? new String[] { jcl17Path } : null,
+ "17");
+ return jarFileName;
+ }
+
+ // -------- helper ------------
+
+ private Runner getDefaultRunner() {
+ Runner runner = new Runner();
+ runner.classLibraries = this.LIBS;
+ Map<String,String> opts = getCompilerOptions();
+ opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17);
+ opts.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ opts.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runner.customOptions = opts;
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.javacTestOptions =
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError;
+ return runner;
+ }
+
+ // --------- tests start -----------
+
+ public void test_typePatternIsNN() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " default -> System.out.println(\"default\");\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(3);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "3";
+ runner.runConformTest();
+ }
+
+ public void test_totalTypePatternAdmitsNull() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(Number n) {\n" +
+ " try {\n" +
+ " switch (n) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " }\n" +
+ " } catch (NullPointerException npe) {\n" +
+ " // ignoring the unchecked warning, and expecting the NPE:\n" +
+ " System.out.print(npe.getMessage());\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " }\n" +
+ " void consumeNumber(@NonNull Number n) {\n" +
+ " System.out.print(n.toString());\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 7)\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " ^^\n" +
+ "Null type safety (type annotations): The expression of type \'Number\' needs unchecked conversion to conform to \'@NonNull Number\'\n" +
+ "----------\n";
+ runner.expectedOutputString = "Cannot invoke \"Object.toString()\" because \"n\" is null";
+ runner.runConformTest();
+ }
+
+ public void test_totalTypePatternNonNullExpression() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(Number n) {\n" +
+ " if (n == null) return;\n" + // this prevents the NPE -> no need to warn
+ " switch (n) {\n" +
+ " case Integer i -> System.out.print(i);\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeNumber(@NonNull Number n) {\n" +
+ " System.out.print(n.toString());\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "";
+ runner.runConformTest();
+ }
+
+ public void test_totalTypePatternNonNullExpression_swExpr() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " int foo(Number n) {\n" +
+ " if (n == null) return -1;\n" + // this prevents the NPE -> no need to warn
+ " return switch (n) {\n" +
+ " case Integer i -> i;\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " };\n" +
+ " }\n" +
+ " int consumeNumber(@NonNull Number n) {\n" +
+ " return Integer.valueOf(n.toString());\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "";
+ runner.runConformTest();
+ }
+
+ public void test_totalTypePatternPlusNullPattern() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(Number n) {\n" +
+ " switch (n) {\n" +
+ " case null -> System.out.print(\"null\");\n" + // this prevents the NPE
+ " case Integer i -> System.out.print(i);\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeNumber(@NonNull Number n) {\n" +
+ " System.out.print(n.toString());\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "null";
+ runner.runConformTest();
+ }
+
+ public void test_totalTypePatternNullableExpression() {
+ Runner runner = getDefaultRunner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(@Nullable Number n) {\n" + // @Nullable here turns "unchecked" into "null type mismatch"
+ " switch (n) {\n" +
+ " case Integer i -> System.out.print(i);\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeNumber(@NonNull Number n) {\n" +
+ " System.out.print(n.toString());\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case Number n0 -> consumeNumber(n0);\n" +
+ " ^^\n" +
+ "Null type mismatch: required \'@NonNull Number\' but the provided value is inferred as @Nullable\n" +
+ "----------\n";
+ runner.runNegativeTest();
+ }
+
+ public void test_switchOverNNValueWithNullCase() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(@NonNull Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " case null -> System.out.print(\"null\");\n" +
+ " default -> System.out.println(\"default\");\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(3);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " case null -> System.out.print(\"null\");\n" +
+ " ^^^^^^^^^\n" +
+ "Unnecessary \'null\' pattern, the switch selector expression cannot be null\n" +
+ "----------\n";
+ runner.expectedOutputString = "3";
+ runner.runConformTest();
+ }
+
+ public void test_switchNullInSameCase() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case null, Integer i -> consumeInt(i);\n" +
+ " default -> System.out.println(\"default\");\n" +
+ " }\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(3);\n" +
+ " }\n" +
+ "}\n"
+ };
+ // demonstrate that null case cannot leak into a type pattern:
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case null, Integer i -> consumeInt(i);\n" +
+ " ^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n";
+ runner.runNegativeTest();
+ }
+
+ public void test_switchOverNNValueWithNullCase_swExpr() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " int foo(@NonNull Object o) {\n" +
+ " return switch (o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " case null -> 0;\n" +
+ " default -> -1;\n" +
+ " };\n" +
+ " }\n" +
+ " int consumeInt(@NonNull Integer i) {\n" +
+ " return i;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(new X().foo(3));\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " case null -> 0;\n" +
+ " ^^^^^^^^^\n" +
+ "Unnecessary \'null\' pattern, the switch selector expression cannot be null\n" +
+ "----------\n";
+ runner.expectedOutputString = "3";
+ runner.runConformTest();
+ }
+
+ public void test_nullHostileSwitch() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(@Nullable Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " default -> System.out.println(o);\n" +
+ " };\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " switch (o) {\n" +
+ " ^\n" +
+ "Potential null pointer access: this expression has a \'@Nullable\' type\n" +
+ "----------\n";
+ runner.runNegativeTest();
+ }
+
+ public void test_defaultDoesNotApplyToNull() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void foo(@Nullable Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " default -> System.out.println(o.toString());\n" +
+ " case null -> System.out.print(\"null\");\n" +
+ " };\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo(null);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "null";
+ runner.runConformTest();
+ }
+
+ public void test_defaultDoesNotApplyToNull_field() {
+ Runner runner = getDefaultRunner();
+ runner.customOptions.put(CompilerOptions.OPTION_SyntacticNullAnalysisForFields, CompilerOptions.ENABLED);
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable Object o;\n" +
+ " void foo() {\n" +
+ " switch (this.o) {\n" +
+ " case Integer i -> consumeInt(i);\n" +
+ " default -> System.out.println(this.o.toString());\n" +
+ " case null -> System.out.print(\"null\");\n" +
+ " };\n" +
+ " }\n" +
+ " void consumeInt(@NonNull Integer i) {\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog = "";
+ runner.expectedOutputString = "null";
+ runner.runConformTest();
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java
index f02810d..34b0578 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java
@@ -144,9 +144,9 @@
Map<String,String> file2module = new HashMap<>();
@Override
- protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) {
+ protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map<String, String> options) {
this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths;
- INameEnvironment[] classLibs = getClassLibs(classPaths == null);
+ INameEnvironment[] classLibs = getClassLibs(classPaths == null, options);
for (INameEnvironment nameEnvironment : classLibs) {
((FileSystem) nameEnvironment).scanForModules(createParser());
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
index f853c26..2f13e97 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
@@ -7,6 +7,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
*******************************************************************************/
@@ -15,6 +19,7 @@
import java.io.IOException;
import java.util.Map;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.core.util.ClassFormatException;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -27,7 +32,7 @@
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "test063b" };
+// TESTS_NAMES = new String[] { "testBug575035" };
}
public static Class<?> testClass() {
@@ -42,18 +47,16 @@
// Enables the tests to run individually
protected Map<String, String> getCompilerOptions(boolean preview) {
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews,
- preview ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel()
+ && preview) {
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ }
return defaultOptions;
}
@Override
protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
- if(!isJRE15Plus)
+ if(!isJRE16Plus)
return;
runConformTest(testFiles, expectedOutput, customOptions, new String[] {"--enable-preview"}, JAVAC_OPTIONS);
}
@@ -91,7 +94,7 @@
"1. ERROR in X1.java (at line 3)\n" +
" if (obj instanceof String s) {\n" +
" ^^^^^^^^\n" +
- "The Java feature 'Pattern Matching in instanceof Expressions' is only available with source level "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +" and above\n" +
+ "The Java feature 'Pattern Matching in instanceof Expressions' is only available with source level 16 and above\n" +
"----------\n",
null,
true,
@@ -101,6 +104,8 @@
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
}
public void test000b() {
+ if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel())
+ return;
Map<String, String> options = getCompilerOptions(true);
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14);
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
@@ -119,7 +124,7 @@
"1. ERROR in X1.java (at line 0)\n" +
" public class X1 {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 14, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
+ "Preview features enabled at an invalid source release level 14, preview can be enabled only at source level 17\n" +
"----------\n",
null,
true,
@@ -3861,6 +3866,31 @@
options);
}
+ public void testBug573880() {
+ if (this.complianceLevel < ClassFileConstants.JDK17)
+ return;
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public void foo(Object o) {\n"
+ + " if (o instanceof var s) {\n"
+ + " System.out.println(s);\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (o instanceof var s) {\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n",
+ null,
+ true,
+ compilerOptions);
+ }
public void testBug574906() {
Map<String, String> options = getCompilerOptions(false);
runConformTest(
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java
index 546ce0f..f564280 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java
@@ -7,6 +7,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
*******************************************************************************/
@@ -14,7 +18,9 @@
import java.util.Map;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.impl.JavaFeature;
import junit.framework.Test;
@@ -35,23 +41,21 @@
public PreviewFeatureTest(String testName){
super(testName);
}
-
- // Enables the tests to run individually
+ @Override
protected Map<String, String> getCompilerOptions() {
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
- defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
- return defaultOptions;
+ Map<String, String> options = super.getCompilerOptions();
+ if (isJRE17Plus) {
+ options.put(CompilerOptions.OPTION_Release, CompilerOptions.ENABLED);
+ }
+ return options;
}
-
/*
* Preview API, --enable-preview=false, SuppressWarning=No
*/
public void test001() {
+ if (this.complianceLevel >= ClassFileConstants.JDK17) {
+ return;
+ }
Map<String, String> options = getCompilerOptions();
String old = options.get(CompilerOptions.OPTION_EnablePreviews);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
@@ -97,6 +101,9 @@
* Preview API, --enable-preview=false, SuppressWarning=yes
*/
public void test002() {
+ if (this.complianceLevel >= ClassFileConstants.JDK17) {
+ return;
+ }
Map<String, String> options = getCompilerOptions();
String old = options.get(CompilerOptions.OPTION_EnablePreviews);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
@@ -133,6 +140,8 @@
* Preview API, --enable-preview=true, SuppressWarning=No
*/
public void test003() {
+ if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel())
+ return;
Map<String, String> options = getCompilerOptions();
String old = options.get(CompilerOptions.OPTION_EnablePreviews);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
@@ -168,6 +177,8 @@
* Preview API, --enable-preview=true, SuppressWarning=Yes
*/
public void test004() {
+ if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel())
+ return;
Map<String, String> options = getCompilerOptions();
String old = options.get(CompilerOptions.OPTION_EnablePreviews);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
@@ -200,4 +211,20 @@
options.put(CompilerOptions.OPTION_EnablePreviews, old);
}
}
+ public void test005() {
+ if (this.complianceLevel < ClassFileConstants.JDK16)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ String old = options.get(CompilerOptions.OPTION_EnablePreviews);
+ if (this.complianceLevel == ClassFileConstants.getLatestJDKLevel())
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ try {
+ if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel())
+ assertFalse(JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(new CompilerOptions(options)));
+ else
+ assertTrue(JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(new CompilerOptions(options)));
+ } finally {
+ options.put(CompilerOptions.OPTION_EnablePreviews, old);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
index 798c52c..9cdfc11 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -7,6 +7,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
*******************************************************************************/
@@ -20,6 +24,7 @@
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.core.util.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
@@ -48,11 +53,21 @@
defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16);
defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
return defaultOptions;
}
+ // Enables the tests to run individually
+ protected Map<String, String> getCompilerOptionsWithPreview() {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ return defaultOptions;
+ }
@Override
protected void runConformTest(String[] testFiles, String expectedOutput) {
@@ -68,7 +83,7 @@
runner.expectedOutputString = expectedOutput;
runner.vmArguments = new String[] {"--enable-preview"};
runner.customOptions = customOptions;
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("16");
+ runner.javacTestOptions = JavacTestOptions.forRelease("16");
runner.runConformTest();
}
@Override
@@ -91,9 +106,9 @@
runner.testFiles = testFiles;
runner.expectedCompilerLog = expectedCompilerLog;
runner.customOptions = customOptions;
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("16") :
- JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions);
+ runner.vmArguments = new String[] {};
+ runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forRelease("16") :
+ JavacTestOptions.forRelease("16", javacAdditionalTestOptions);
runner.runWarningTest();
}
@@ -179,7 +194,7 @@
runConformTest(
new String[] {
"X.java",
- "class X {\n"+
+ "public class X {\n"+
" public static void main(String[] args){\n"+
" System.out.println(0);\n" +
" }\n"+
@@ -769,7 +784,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug550750_033() {
@@ -786,7 +801,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class X<record> {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug550750_034() {
@@ -804,12 +819,12 @@
"1. ERROR in X.java (at line 5)\n" +
" public <record> void foo(record args){}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" public <record> void foo(record args){}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug550750_035() {
@@ -827,7 +842,7 @@
"1. ERROR in X.java (at line 5)\n" +
" public void foo(record args){}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug550750_036() {
@@ -853,7 +868,7 @@
"2. ERROR in X.java (at line 4)\n" +
" I lambda = (record r) -> {};\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug550750_037() {
@@ -4720,12 +4735,12 @@
"1. ERROR in X.java (at line 1)\n" +
" class X extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 6)\n" +
" class record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_002() {
@@ -4742,7 +4757,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class X extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_003() {
@@ -4760,12 +4775,12 @@
"1. ERROR in X.java (at line 1)\n" +
" class X implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_004() {
@@ -4782,7 +4797,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class X implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_005() {
@@ -4802,12 +4817,12 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" class record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_006() {
@@ -4826,7 +4841,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_007() {
@@ -4846,12 +4861,12 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_008() {
@@ -4870,7 +4885,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_009() {
@@ -4890,12 +4905,12 @@
"1. ERROR in X.java (at line 1)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_010() {
@@ -4914,7 +4929,7 @@
"1. ERROR in X.java (at line 1)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_011() {
@@ -4934,12 +4949,12 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_012() {
@@ -4958,7 +4973,7 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_013() {
@@ -4975,12 +4990,12 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" class record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_014() {
@@ -4996,7 +5011,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_015() {
@@ -5013,12 +5028,12 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_016() {
@@ -5034,7 +5049,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_017() {
@@ -5051,12 +5066,12 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" interface record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_018() {
@@ -5072,7 +5087,7 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_019() {
@@ -5093,12 +5108,12 @@
"1. ERROR in X.java (at line 3)\n" +
" record r=new record(i,j);\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" record r=new record(i,j);\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"3. ERROR in X.java (at line 4)\n" +
" return r;\n" +
@@ -5125,17 +5140,17 @@
"1. ERROR in X.java (at line 2)\n" +
" class record {};\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" record r=new record();\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"3. ERROR in X.java (at line 4)\n" +
" record r=new record();\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"4. ERROR in X.java (at line 5)\n" +
" return r;\n" +
@@ -5254,7 +5269,7 @@
"1. ERROR in X.java (at line 5)\n" +
" static IPoint a(int i, int j) throws record{\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_024() {
@@ -5272,7 +5287,7 @@
"1. ERROR in X.java (at line 2)\n" +
" X() throws record {} \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_025() {
@@ -5287,7 +5302,7 @@
"1. ERROR in X.java (at line 2)\n" +
" int a() throws record; \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_026() {
@@ -5306,7 +5321,7 @@
"1. ERROR in X.java (at line 2)\n" +
" List<record> R = new List<record>();\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 2)\n" +
" List<record> R = new List<record>();\n" +
@@ -5316,7 +5331,7 @@
"3. ERROR in X.java (at line 2)\n" +
" List<record> R = new List<record>();\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_027() {
@@ -5344,12 +5359,12 @@
"2. ERROR in X.java (at line 4)\n" +
" public class X implements I<record>{\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" void print(record arg){\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_028() {
@@ -5369,12 +5384,12 @@
"1. ERROR in X.java (at line 1)\n" +
" class Y<record> {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 2)\n" +
" void equal(record R) {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_029() {
@@ -5394,12 +5409,12 @@
"1. ERROR in X.java (at line 1)\n" +
" class Y<record> {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 2)\n" +
" Y(record R) {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_030() {
@@ -5417,7 +5432,7 @@
"1. ERROR in X.java (at line 2)\n" +
" static record i= 0;\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_031() {
@@ -5437,7 +5452,7 @@
"1. ERROR in X.java (at line 2)\n" +
" record i=0;\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_032() {
@@ -5457,7 +5472,7 @@
"1. ERROR in X.java (at line 2)\n" +
" static int sum(record i, int param){\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_033() {
@@ -5476,7 +5491,7 @@
"1. ERROR in X.java (at line 2)\n" +
" X(record i, int param){\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_034() {
@@ -5496,7 +5511,7 @@
"1. ERROR in X.java (at line 2)\n" +
" int sum(record i, int num);\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_035() {
@@ -5535,7 +5550,7 @@
"1. ERROR in X.java (at line 2)\n" +
" int sum(record this, int i, int num) {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_037() {
@@ -5553,7 +5568,7 @@
"1. ERROR in X.java (at line 2)\n" +
" static record i;\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_038() {
@@ -5572,7 +5587,7 @@
"1. ERROR in X.java (at line 3)\n" +
" for (record i = 0; i<10; i++) {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_039() {
@@ -5592,7 +5607,7 @@
"1. ERROR in X.java (at line 4)\n" +
" for (record i: rec) {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" for (record i: rec) {\n" +
@@ -5616,7 +5631,7 @@
"1. ERROR in X.java (at line 3)\n" +
" try (record i = 0){\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_041() {
@@ -5636,7 +5651,7 @@
"1. ERROR in X.java (at line 5)\n" +
" catch (record e) {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_042() {
@@ -5659,7 +5674,7 @@
"2. ERROR in X.java (at line 1)\n" +
" record Point(record x, int i) { }\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_043() {
@@ -5683,7 +5698,7 @@
"1. ERROR in X.java (at line 5)\n" +
" <record> this(null);\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" <record> this(null);\n" +
@@ -5714,7 +5729,7 @@
"1. ERROR in X.java (at line 7)\n" +
" <record> super(null);\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" <record> super(null);\n" +
@@ -5742,7 +5757,7 @@
"1. ERROR in X.java (at line 4)\n" +
" this.<record>m1(); }\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. WARNING in X.java (at line 4)\n" +
" this.<record>m1(); }\n" +
@@ -5770,7 +5785,7 @@
"1. ERROR in X.java (at line 8)\n" +
" new <record>Y().a();\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. WARNING in X.java (at line 8)\n" +
" new <record>Y().a();\n" +
@@ -5799,7 +5814,7 @@
"1. ERROR in X.java (at line 5)\n" +
" new <record>Y() {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. WARNING in X.java (at line 5)\n" +
" new <record>Y() {\n" +
@@ -5828,7 +5843,7 @@
"1. ERROR in X.java (at line 5)\n" +
" new <record>Y() {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. WARNING in X.java (at line 5)\n" +
" new <record>Y() {\n" +
@@ -5851,12 +5866,12 @@
"1. ERROR in X.java (at line 3)\n" +
" record[] y= new record[3]; \n" +
" ^^^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 3)\n" +
" record[] y= new record[3]; \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_050() {
@@ -5875,12 +5890,12 @@
"1. ERROR in X.java (at line 4)\n" +
" record y= (record)s; \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" record y= (record)s; \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_051() {
@@ -5901,7 +5916,7 @@
"1. ERROR in X.java (at line 4)\n" +
" if (s instanceof record) { \n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
public void testBug564672_052() {
@@ -5950,7 +5965,7 @@
"2. ERROR in X.java (at line 7)\n" +
" messages.stream().map(record::new).toArray(record[]::new);\n" +
" ^^^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n");
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -5991,7 +6006,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class X extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6036,7 +6051,7 @@
"1. ERROR in X.java (at line 1)\n" +
" class X implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6085,7 +6100,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6134,7 +6149,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6183,7 +6198,7 @@
"1. ERROR in X.java (at line 1)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6232,7 +6247,7 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6280,7 +6295,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6328,7 +6343,7 @@
"1. ERROR in X.java (at line 2)\n" +
" class Y implements record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6376,7 +6391,7 @@
"1. ERROR in X.java (at line 2)\n" +
" interface Y extends record {\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -6961,7 +6976,7 @@
"2. ERROR in X.java (at line 7)\n" +
" class record {}\n" +
" ^^^^^^\n" +
- "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
+ "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
"----------\n",
null,
true,
@@ -7264,8 +7279,8 @@
);
}
public void testBug565388_001() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
this.runNegativeTest(
new String[] {
"X.java",
@@ -7284,8 +7299,8 @@
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
}
public void testBug565388_002() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
this.runNegativeTest(
new String[] {
"X.java",
@@ -7746,8 +7761,8 @@
"private final int X$1Bar.x");
}
public void testBug566063_001() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
runConformTest(
new String[] {
"X.java",
@@ -7773,8 +7788,8 @@
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
}
public void testBug566063_002() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
runNegativeTest(
new String[] {
"X.java",
@@ -7807,8 +7822,8 @@
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
}
public void testBug566063_003() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
runNegativeTest(
new String[] {
"X.java",
@@ -8029,8 +8044,8 @@
"----------\n");
}
public void testBug567731_001() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
this.runNegativeTest(
new String[] {
"X.java",
@@ -8059,8 +8074,8 @@
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
}
public void testBug567731_002() {
- Map<String, String> options = getCompilerOptions();
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ if (this.complianceLevel < ClassFileConstants.JDK17) return;
+ Map<String, String> options = getCompilerOptionsWithPreview();
this.runNegativeTest(
new String[] {
"X.java",
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java
index 31d8dea..d6ce494 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java
@@ -7,6 +7,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
*******************************************************************************/
@@ -38,7 +42,7 @@
return SealedTypesTests.class;
}
public static Test suite() {
- return buildMinimalComplianceTestSuite(testClass(), F_16);
+ return buildMinimalComplianceTestSuite(testClass(), F_17);
}
public SealedTypesTests(String testName){
super(testName);
@@ -47,10 +51,9 @@
// Enables the tests to run individually
protected Map<String, String> getCompilerOptions() {
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); // FIXME
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17);
defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
return defaultOptions;
@@ -68,12 +71,12 @@
runner.expectedOutputString = expectedOutput;
runner.vmArguments = new String[] {"--enable-preview"};
runner.customOptions = customOptions;
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("16");
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("17");
runner.runConformTest();
}
@Override
protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
- runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("16"));
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("17"));
}
protected void runWarningTest(String[] testFiles, String expectedCompilerLog) {
runWarningTest(testFiles, expectedCompilerLog, null);
@@ -1378,7 +1381,7 @@
"public final class Z extends Y{}",
},
lib1Path,
- JavaCore.VERSION_16,
+ JavaCore.VERSION_17,
true);
String[] libs = getDefaultClassPaths();
int len = libs.length;
@@ -1686,7 +1689,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1742,7 +1745,7 @@
},
"----------\n" +
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" permits p;\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1753,7 +1756,7 @@
"The method Zork() is undefined for the type X\n" +
"----------\n" +
"----------\n" +
- "1. WARNING in permits.java (at line 1)\n" +
+ "1. ERROR in permits.java (at line 1)\n" +
" public class permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1809,7 +1812,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X<permits> {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1891,7 +1894,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X extends permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1901,7 +1904,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" class permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1956,7 +1959,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X implements permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -1966,7 +1969,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" interface permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -2021,7 +2024,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" interface X extends permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -2031,7 +2034,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" interface permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -2084,16 +2087,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" permits foo() {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " permits foo() {\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 3)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2140,16 +2138,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" void foo() throws permits{\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " void foo() throws permits{\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 3)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2211,16 +2204,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X <T extends permits>{\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 1)\n" +
- " class X <T extends permits>{\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 1)\n" +
" class X <T extends permits>{\n" +
" ^\n" +
@@ -2286,16 +2274,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" private final permits p;\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " private final permits p;\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2355,16 +2338,11 @@
" ^^^^^^^^^^^^^\n" +
"This lambda expression refers to the missing type permits\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" I i = (permits p)-> {};\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "3. ERROR in X.java (at line 3)\n" +
- " I i = (permits p)-> {};\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"4. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2402,15 +2380,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public void foo(permits this) {}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public void foo(permits this) {}\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -2444,15 +2417,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public void foo(permits this) {}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public void foo(permits this) {}\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -2495,12 +2463,12 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" class permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" public void foo(permits this) {}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -2548,16 +2516,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" permits p;\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " permits p;\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2610,16 +2573,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" for (permits i = 0; i < 10; ++i) {} \n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " for (permits i = 0; i < 10; ++i) {} \n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -2666,25 +2624,15 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public static void main(permits[] args) {\n" +
" ^^^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public static void main(permits[] args) {\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
- "3. WARNING in X.java (at line 3)\n" +
+ "3. ERROR in X.java (at line 3)\n" +
" for (permits p : args) {} \n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "4. ERROR in X.java (at line 3)\n" +
- " for (permits p : args) {} \n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -2742,15 +2690,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" try (permits y = new Y()) {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " try (permits y = new Y()) {\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -2808,15 +2751,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" } catch (permits e) {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " } catch (permits e) {\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -2858,15 +2796,10 @@
" ^\n" +
"permits cannot be resolved to a type\n" +
"----------\n" +
- "2. WARNING in X.java (at line 1)\n" +
+ "2. ERROR in X.java (at line 1)\n" +
" record X(permits p) {\n" +
" ^^^^^^^\n" +
- "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 1)\n" +
- " record X(permits p) {\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
+ "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 17\n" +
"----------\n",
null,
true,
@@ -2913,16 +2846,11 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" <permits>this(t);\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " <permits>this(t);\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" <permits>this(t);\n" +
" ^^^^^^^^\n" +
@@ -2980,15 +2908,10 @@
" ^^^^^^^^^^^^^^^^^\n" +
"The parameterized constructor <permits>X(permits) of type X is not applicable for the arguments (Integer)\n" +
"----------\n" +
- "2. WARNING in X.java (at line 5)\n" +
+ "2. ERROR in X.java (at line 5)\n" +
" new <permits>X(t).foo();\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 5)\n" +
- " new <permits>X(t).foo();\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -3037,16 +2960,11 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 6)\n" +
+ "1. ERROR in X.java (at line 6)\n" +
" x.<permits>foo(0);\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 6)\n" +
- " x.<permits>foo(0);\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" x.<permits>foo(0);\n" +
" ^^^\n" +
@@ -3092,15 +3010,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" X x = new permits();\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " X x = new permits();\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -3157,7 +3070,7 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" new permits() {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3167,7 +3080,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type new permits(){}\n" +
"----------\n" +
- "3. WARNING in X.java (at line 11)\n" +
+ "3. ERROR in X.java (at line 11)\n" +
" abstract class permits {\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3208,15 +3121,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" Object[] p = new permits[10];\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " Object[] p = new permits[10];\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -3271,25 +3179,15 @@
" ^^^\n" +
"The method foo(permits) from the type X refers to the missing type permits\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" new X().foo((permits) null);\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "3. ERROR in X.java (at line 3)\n" +
- " new X().foo((permits) null);\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
- "----------\n" +
- "4. WARNING in X.java (at line 5)\n" +
+ "4. ERROR in X.java (at line 5)\n" +
" private void foo(permits o) {}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "5. ERROR in X.java (at line 5)\n" +
- " private void foo(permits o) {}\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -3327,15 +3225,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" if (o instanceof permits) {}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " if (o instanceof permits) {}\n" +
- " ^^^^^^^\n" +
- "permits cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -3395,7 +3288,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "2. WARNING in X.java (at line 8)\n" +
+ "2. ERROR in X.java (at line 8)\n" +
" class permits{}\n" +
" ^^^^^^^\n" +
"\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3419,7 +3312,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3475,7 +3368,7 @@
},
"----------\n" +
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" sealed p;\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3486,7 +3379,7 @@
"The method Zork() is undefined for the type X\n" +
"----------\n" +
"----------\n" +
- "1. WARNING in sealed.java (at line 1)\n" +
+ "1. ERROR in sealed.java (at line 1)\n" +
" public class sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3542,7 +3435,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X<sealed> {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3624,7 +3517,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X extends sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3634,7 +3527,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" class sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3689,7 +3582,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X implements sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3699,7 +3592,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" interface sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3754,7 +3647,7 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" interface X extends sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3764,7 +3657,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" interface sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -3817,16 +3710,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" sealed foo() {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " sealed foo() {\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 3)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -3873,16 +3761,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" void foo() throws sealed{\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " void foo() throws sealed{\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 3)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -3944,16 +3827,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
+ "1. ERROR in X.java (at line 1)\n" +
" class X <T extends sealed>{\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 1)\n" +
- " class X <T extends sealed>{\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 1)\n" +
" class X <T extends sealed>{\n" +
" ^\n" +
@@ -4019,16 +3897,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" private final sealed p;\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " private final sealed p;\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -4088,16 +3961,11 @@
" ^^^^^^^^^^^^\n" +
"This lambda expression refers to the missing type sealed\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" I i = (sealed p)-> {};\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "3. ERROR in X.java (at line 3)\n" +
- " I i = (sealed p)-> {};\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"4. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -4135,15 +4003,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public void foo(sealed this) {}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public void foo(sealed this) {}\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4177,15 +4040,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public void foo(sealed this) {}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public void foo(sealed this) {}\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4228,12 +4086,12 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" class sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" public void foo(sealed this) {}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -4281,16 +4139,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" sealed p;\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " sealed p;\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -4343,16 +4196,11 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" for (sealed i = 0; i < 10; ++i) {} \n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " for (sealed i = 0; i < 10; ++i) {} \n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" Zork();\n" +
" ^^^^\n" +
@@ -4399,25 +4247,15 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
+ "1. ERROR in X.java (at line 2)\n" +
" public static void main(sealed[] args) {\n" +
" ^^^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " public static void main(sealed[] args) {\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
- "3. WARNING in X.java (at line 3)\n" +
+ "3. ERROR in X.java (at line 3)\n" +
" for (sealed p : args) {} \n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "4. ERROR in X.java (at line 3)\n" +
- " for (sealed p : args) {} \n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4475,15 +4313,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" try (sealed y = new Y()) {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " try (sealed y = new Y()) {\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4541,15 +4374,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" } catch (sealed e) {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " } catch (sealed e) {\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4591,15 +4419,10 @@
" ^\n" +
"sealed cannot be resolved to a type\n" +
"----------\n" +
- "2. WARNING in X.java (at line 1)\n" +
+ "2. ERROR in X.java (at line 1)\n" +
" record X(sealed p) {\n" +
" ^^^^^^\n" +
- "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 1)\n" +
- " record X(sealed p) {\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
+ "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 17\n" +
"----------\n",
null,
true,
@@ -4646,16 +4469,11 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" <sealed>this(t);\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " <sealed>this(t);\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" <sealed>this(t);\n" +
" ^^^^^^^^\n" +
@@ -4713,15 +4531,10 @@
" ^^^^^^^^^^^^^^^^\n" +
"The parameterized constructor <sealed>X(sealed) of type X is not applicable for the arguments (Integer)\n" +
"----------\n" +
- "2. WARNING in X.java (at line 5)\n" +
+ "2. ERROR in X.java (at line 5)\n" +
" new <sealed>X(t).foo();\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 5)\n" +
- " new <sealed>X(t).foo();\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4770,16 +4583,11 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 6)\n" +
+ "1. ERROR in X.java (at line 6)\n" +
" x.<sealed>foo(0);\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "2. ERROR in X.java (at line 6)\n" +
- " x.<sealed>foo(0);\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" x.<sealed>foo(0);\n" +
" ^^^\n" +
@@ -4825,15 +4633,10 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" X x = new sealed();\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " X x = new sealed();\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -4890,7 +4693,7 @@
"}\n",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" new sealed() {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -4900,7 +4703,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type new sealed(){}\n" +
"----------\n" +
- "3. WARNING in X.java (at line 11)\n" +
+ "3. ERROR in X.java (at line 11)\n" +
" abstract class sealed {\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -4941,15 +4744,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" Object[] p = new sealed[10];\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " Object[] p = new sealed[10];\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -5004,25 +4802,15 @@
" ^^^\n" +
"The method foo(sealed) from the type X refers to the missing type sealed\n" +
"----------\n" +
- "2. WARNING in X.java (at line 3)\n" +
+ "2. ERROR in X.java (at line 3)\n" +
" new X().foo((sealed) null);\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
"----------\n" +
- "3. ERROR in X.java (at line 3)\n" +
- " new X().foo((sealed) null);\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
- "----------\n" +
- "4. WARNING in X.java (at line 5)\n" +
+ "4. ERROR in X.java (at line 5)\n" +
" private void foo(sealed o) {}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "5. ERROR in X.java (at line 5)\n" +
- " private void foo(sealed o) {}\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -5060,15 +4848,10 @@
"}",
},
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" if (o instanceof sealed) {}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " if (o instanceof sealed) {}\n" +
- " ^^^^^^\n" +
- "sealed cannot be resolved to a type\n" +
"----------\n",
null,
true,
@@ -5128,7 +4911,7 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "2. WARNING in X.java (at line 8)\n" +
+ "2. ERROR in X.java (at line 8)\n" +
" class sealed{}\n" +
" ^^^^^^\n" +
"\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" +
@@ -5304,31 +5087,16 @@
"final class Z implements I{}",
},
"----------\n" +
- "1. WARNING in X.java (at line 1)\n" +
- " public sealed class X permits Y {Zork();\n" +
- " ^^^^^^\n" +
- "You are using a preview language feature that may or may not be supported in a future release\n" +
- "----------\n" +
- "2. WARNING in X.java (at line 1)\n" +
- " public sealed class X permits Y {Zork();\n" +
- " ^^^^^^^\n" +
- "You are using a preview language feature that may or may not be supported in a future release\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 1)\n" +
- " public sealed class X permits Y {Zork();\n" +
- " ^^^^^^\n" +
- "Return type for the method is missing\n" +
- "----------\n" +
- "4. ERROR in X.java (at line 1)\n" +
- " public sealed class X permits Y {Zork();\n" +
- " ^^^^^^\n" +
- "This method requires a body instead of a semicolon\n" +
- "----------\n" +
- "5. WARNING in X.java (at line 4)\n" +
- " sealed interface I{}\n" +
- " ^^^^^^\n" +
- "You are using a preview language feature that may or may not be supported in a future release\n" +
- "----------\n",
+ "1. ERROR in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^\n" +
+ "Return type for the method is missing\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^\n" +
+ "This method requires a body instead of a semicolon\n" +
+ "----------\n",
null,
true,
options
@@ -5566,7 +5334,6 @@
"X.java",
"import java.lang.reflect.Modifier;\n"+
"\n"+
- "@SuppressWarnings(\"preview\")\n"+
"sealed interface I {\n"+
" void foo();\n"+
"}\n"+
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
new file mode 100644
index 0000000..5a21459
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
@@ -0,0 +1,4046 @@
+/*******************************************************************************
+ * Copyright (c) 2021 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
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class SwitchPatternTest extends AbstractRegressionTest9 {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] { "testBug575737"};
+ }
+
+ private static String previewLevel = "17";
+
+ public static Class<?> testClass() {
+ return SwitchPatternTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_17);
+ }
+ public SwitchPatternTest(String testName){
+ super(testName);
+ }
+
+ // Enables the tests to run individually
+ protected Map<String, String> getCompilerOptions() {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); // FIXME
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
+ return defaultOptions;
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput) {
+ runConformTest(testFiles, expectedOutput, "", getCompilerOptions());
+ }
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
+ runConformTest(testFiles, expectedOutput, "", customOptions);
+ }
+ protected void runConformTest(String[] testFiles, String expectedOutput, String errorOutput) {
+ runConformTest(testFiles, expectedOutput, errorOutput, getCompilerOptions());
+ }
+ protected void runConformTest(String[] testFiles, String expectedOutput, String expectedErrorOutput, Map<String, String> customOptions) {
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedOutputString = expectedOutput;
+ runner.expectedErrorString = expectedErrorOutput;
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.customOptions = customOptions;
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel);
+ runner.runConformTest();
+ }
+ @Override
+ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
+ runNegativeTest(testFiles, expectedCompilerLog, "");
+ }
+ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog, String javacLog) {
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedCompilerLog = expectedCompilerLog;
+ runner.expectedJavacOutputString = expectedCompilerLog;
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.customOptions = getCompilerOptions();
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel);
+ runner.runNegativeTest();
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel));
+ }
+ protected void runWarningTest(String[] testFiles, String expectedCompilerLog) {
+ runWarningTest(testFiles, expectedCompilerLog, null);
+ }
+ protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map<String, String> customOptions) {
+ runWarningTest(testFiles, expectedCompilerLog, customOptions, null);
+ }
+ protected void runWarningTest(String[] testFiles, String expectedCompilerLog,
+ Map<String, String> customOptions, String javacAdditionalTestOptions) {
+
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedCompilerLog = expectedCompilerLog;
+ runner.customOptions = customOptions;
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel) :
+ JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel, javacAdditionalTestOptions);
+ runner.runWarningTest();
+ }
+
+ public void testBug573516_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i -> System.out.println(\"String:\");\n"+
+ " case String s -> System.out.println(\"String: Hello World!\");\n"+
+ " default -> System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " }\n"+
+ "}",
+ },
+ "String: Hello World!");
+ }
+ public void testBug573516_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s -> System.out.println(\"String:\");\n"+
+ " default -> System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s : System.out.println(\"String:\"); break;\n"+
+ " case Integer i : System.out.println(\"Integer:\");break;\n"+
+ " default : System.out.println(\"Object\");break;\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer t && t > 0 -> System.out.println(\"Integer && t > 0\");\n"+
+ " default -> System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_005() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer t, String s, X x : System.out.println(\"Integer, String or X\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String s, X x : System.out.println(\"Integer, String or X\");\n" +
+ " ^^^^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_006() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n" +
+ " ^^^^^^\n" +
+ "length cannot be resolved or is not a field\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_007() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer t, String : System.out.println(\"Error should be flagged for String\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String : System.out.println(\"Error should be flagged for String\");\n" +
+ " ^^^^^^\n" +
+ "String cannot be resolved to a variable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_008() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o.hashCode()) {\n"+
+ " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n" +
+ " ^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from int to Integer\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n" +
+ " ^^^^^^\n" +
+ "String cannot be resolved to a variable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_009() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o.hashCode()) {\n"+
+ " case default : System.out.println(\"Default\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default : System.out.println(\"Object\");\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_010() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o.hashCode()) {\n"+
+ " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n" +
+ " ^^^^^^^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n" +
+ " ^^^^^^^\n" +
+ "A switch label may not have both a pattern case label element and a default case label element\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 5)\n" +
+ " default : System.out.println(\"Object\");\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573516_011() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o.hashCode()) {\n"+
+ " case var s : System.out.println(\"Error should be ANY_PATTERN\");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case var s : System.out.println(\"Error should be ANY_PATTERN\");\n" +
+ " ^^^\n" +
+ "'var' is not allowed here\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug574228_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case 1: System.out.println(\"Integer\"); break;\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: System.out.println(\"Integer\"); break;\n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from int to Object\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+
+ public void testBug573936_01() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(I); \n"+
+ " case String s && s.length()>1: \n"+
+ " System.out.println(\"String s && s.length()>1\"); \n"+
+ " System.out.println(s); \n"+
+ " break;// error no fallthrough allowed in pattern\n"+
+ " case X x:\n"+
+ " System.out.println(\"X\"); \n"+
+ " System.out.println(x);\n"+
+ " break;\n"+
+ " default : System.out.println(\"Object\"); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " foo(\"H\");\n"+
+ " foo(bar());\n"+
+ " }\n"+
+ " public static Object bar() { return new Object();}\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case String s && s.length()>1: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ public void testBug573939_01() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer s : System.out.println(\"Integer\");\n"+
+ " case String s1: System.out.println(\"String \");\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World\");\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class Y {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case String s1: System.out.println(\"String \");\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug573939_02() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: System.out.println(\"Integer\"); break;\n"+
+ " case String s && s.length()>1: System.out.println(\"String > 1\"); break;\n"+
+ " case String s1: System.out.println(\"String\"); break;\n"+
+ " case X x: System.out.println(\"X\"); break;\n"+
+ " default : System.out.println(\"Object\");\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " foo(\"H\");\n"+
+ " foo(bar());\n"+
+ " }\n"+
+ " public static Object bar() { return new Object();}\n"+
+ "}",
+ },
+ "String > 1\n" +
+ "String\n" +
+ "Object");
+ }
+ public void testBug573939_03() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(I); \n"+
+ " break; \n"+
+ " case String s && s.length()>1: \n"+
+ " System.out.println(\"String s && s.length()>1\"); \n"+
+ " System.out.println(s); \n"+
+ " break;\n"+
+ " case String s1: \n"+
+ " System.out.println(\"String\"); \n"+
+ " System.out.println(s1);\n"+
+ " break; \n"+
+ " case X x:\n"+
+ " System.out.println(\"X\"); \n"+
+ " System.out.println(x);\n"+
+ " break;\n"+
+ " default : System.out.println(\"Object\"); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " foo(\"H\");\n"+
+ " foo(bar());\n"+
+ " }\n"+
+ " public static Object bar() { return new Object();}\n"+
+ "}",
+ },
+ "String s && s.length()>1\n" +
+ "Hello World!\n" +
+ "String\n" +
+ "H\n" +
+ "Object");
+ }
+ public void testBug573939_03b() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(I); \n"+
+ " break; \n"+
+ " case String s && s.length()>1: \n"+
+ " System.out.println(\"String s && s.length()>1\"); \n"+
+ " System.out.println(s); \n"+
+ " break;\n"+
+ " case String s: \n"+
+ " System.out.println(\"String\"); \n"+
+ " System.out.println(s);\n"+
+ " break; \n"+
+ " case X x:\n"+
+ " System.out.println(\"X\"); \n"+
+ " System.out.println(x);\n"+
+ " break;\n"+
+ " default : System.out.println(\"Object\"); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " foo(\"H\");\n"+
+ " foo(bar());\n"+
+ " }\n"+
+ " public static Object bar() { return new Object();}\n"+
+ "}",
+ },
+ "String s && s.length()>1\n" +
+ "Hello World!\n" +
+ "String\n" +
+ "H\n" +
+ "Object");
+ }
+ public void test045() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public abstract class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " switch (args.length) {\n" +
+ " case 1:\n" +
+ " final int j = 1;\n" +
+ " case 2:\n" +
+ " switch (5) {\n" +
+ " case j:\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " case j:\n" +
+ " ^\n" +
+ "The local variable j may not have been initialized\n" +
+ "----------\n");
+ }
+ public void testBug574525_01() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(I); \n"+
+ " break; \n"+
+ " case null:\n"+
+ " System.out.println(\"NULL\"); \n"+
+ " break;\n"+
+ " default : System.out.println(\"Object\"); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(null);\n"+
+ " }\n"+
+ "}",
+ },
+ "NULL");
+ }
+ public void testBug574525_02() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(I); \n"+
+ " break; \n"+
+ " case String s && s.length()>1: \n"+
+ " System.out.println(\"String s && s.length()>1\"); \n"+
+ " System.out.println(s); \n"+
+ " break;\n"+
+ " case String s1: \n"+
+ " System.out.println(\"String\"); \n"+
+ " System.out.println(s1);\n"+
+ " break; \n"+
+ " case X x:\n"+
+ " System.out.println(\"X\"); \n"+
+ " System.out.println(x);\n"+
+ " break;\n"+
+ " case null:\n"+
+ " System.out.println(\"NULL\"); \n"+
+ " break;\n"+
+ " default : System.out.println(\"Object\"); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " foo(null);\n"+
+ " foo(bar());\n"+
+ " }\n"+
+ " public static Object bar() { return new Object();}\n"+
+ "}",
+ },
+ "String s && s.length()>1\n" +
+ "Hello World!\n" +
+ "NULL\n" +
+ "Object");
+ }
+ public void testBug574525_03() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case 10: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(o); \n"+
+ " break; \n"+
+ " case null:\n"+
+ " System.out.println(\"NULL\"); \n"+
+ " break;\n"+
+ " default : System.out.println(o); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(0);\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug574525_04() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(int o) {\n"+
+ " switch (o) {\n"+
+ " case 10: \n"+
+ " System.out.println(\"Integer\"); \n"+
+ " System.out.println(o); \n"+
+ " break; \n"+
+ " case null:\n"+
+ " System.out.println(\"NULL\"); \n"+
+ " break;\n"+
+ " default : System.out.println(o); \n"+
+ " }\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " foo(0);\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " case null:\n" +
+ " ^^^^\n" +
+ "Type mismatch: cannot convert from null to int\n" +
+ "----------\n");
+ }
+ public void testBug574538_01() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(11));\n"+
+ " foo(Integer.valueOf(9));\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i && i>10:\n"+
+ " System.out.println(\"Greater than 10:\" + o);\n"+
+ " break;\n"+
+ " case Integer j && j>0:\n"+
+ " System.out.println(\"Greater than 0:\" + o);\n"+
+ " break;\n"+
+ " default:\n"+
+ " System.out.println(\"Object\" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Greater than 10:11\n" +
+ "Greater than 0:9");
+ }
+ public void testBug574538_02() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo1(Integer.valueOf(10));\n"+
+ " foo1(Integer.valueOf(11));\n"+
+ " foo1(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo1(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i&&i>10 -> System.out.println(\"Greater than 10:\");\n"+
+ " case String s&&s.equals(\"ff\") -> System.out.println(\"String:\" + s);\n"+
+ " default -> System.out.println(\"Object:\" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Object:10\n" +
+ "Greater than 10:\n" +
+ "Object:Hello World!");
+ }
+
+ public void testBug574549_01() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case default:\n"+
+ " System.out.println(\"Object: \" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Object: Hello World!");
+ }
+ public void testBug574549_02() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(11));\n"+
+ " foo(Integer.valueOf(9));\n"+
+ " foo(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i && i>10:\n"+
+ " System.out.println(\"Greater than 10:\" + o);\n"+
+ " break;\n"+
+ " case Integer j && j>0:\n"+
+ " System.out.println(\"Greater than 0:\" + o);\n"+
+ " break;\n"+
+ " case default:\n"+
+ " System.out.println(\"Give Me Some SunShine:\" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Greater than 10:11\n" +
+ "Greater than 0:9\n" +
+ "Give Me Some SunShine:Hello World!");
+ }
+ public void testBug574549_03() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i :\n"+
+ " System.out.println(\"Integer:\" + o);\n"+
+ " break;\n"+
+ " case default:\n"+
+ " System.out.println(\"Object\" + o);\n"+
+ " case default:\n"+
+ " System.out.println(\"Give me Some Sunshine\" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 13)\n" +
+ " case default:\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574549_04() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i :\n"+
+ " System.out.println(\"Integer:\" + o);\n"+
+ " break;\n"+
+ " case default:\n"+
+ " System.out.println(\"Object\" + o);\n"+
+ " default:\n"+
+ " System.out.println(\"Give me Some Sunshine\" + o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 13)\n" +
+ " default:\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ // Test that when a pattern variable is unused and when the OPTION_PreserveUnusedLocal
+ // option is used, no issue is reported at runtime.
+ public void testBug573937_1() {
+ Map<String,String> options = getCompilerOptions();
+ String opt = options.get(CompilerOptions.OPTION_PreserveUnusedLocal);
+ try {
+ options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.DISABLED);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void main(String[] args) {\n"
+ + " System.out.println(\"Hello\");\n"
+ + " }\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s:\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "Hello",
+ options);
+ } finally {
+ options.put(CompilerOptions.OPTION_PreserveUnusedLocal, opt);
+ }
+ }
+ // A simple pattern variable in a case is not visible in the
+ // following case statement
+ public void testBug573937_2() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s:\n"
+ + " System.out.println(s);\n"
+ + " break;\n"
+ + " case Integer i:\n"
+ + " System.out.println(s);\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "s cannot be resolved to a variable\n" +
+ "----------\n");
+ }
+ // Same as above, but without break statement
+ public void testBug573937_3() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s:\n"
+ + " System.out.println(s);\n"
+ + " case Integer i:\n"
+ + " System.out.println(s);\n"
+ + " default:\n"
+ + " System.out.println(s);\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "s cannot be resolved to a variable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "s cannot be resolved to a variable\n" +
+ "----------\n");
+ }
+ // Test that compiler rejects attempts to redeclare local variable
+ // with same name as a pattern variable
+ public void testBug573937_4() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s:\n"
+ + " String s = null;\n"
+ + " System.out.println(s);\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " String s = null;\n" +
+ " ^\n" +
+ "Duplicate local variable s\n" +
+ "----------\n");
+ }
+ // Test that compiler allows local variable with same name as a
+ // pattern variable in a different case statement
+ public void testBug573937_5() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s:\n"
+ + " System.out.println(s);\n"
+ + " break;\n"
+ + " default:\n"
+ + " String s = null;\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + " public static void main(String[] args) {\n"
+ + " foo(\"hello\");\n"
+ + " }\n"
+ + "}",
+ },
+ "hello");
+ }
+ // Test that a pattern variable can't use name of an already existing local
+ // variable
+ public void testBug573937_6() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String o:\n"
+ + " System.out.println(o);\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case String o:\n" +
+ " ^\n" +
+ "Duplicate local variable o\n" +
+ "----------\n");
+ }
+ // Test that compiler rejects attempts to redeclare another pattern
+ // variable (instanceof) with same name as that a pattern variable in
+ // that case statement
+ public void testBug573937_7() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s1:\n"
+ + " if (o instanceof String s1) {\n"
+ + " System.out.println(s1);\n"
+ + " }\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (o instanceof String s1) {\n" +
+ " ^^\n" +
+ "Duplicate local variable s1\n" +
+ "----------\n");
+ }
+ // Test that when multiple case statements declare pattern variables
+ // with same name, correct ones are used in their respective scopes.
+ public void testBug573937_8() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case String s1:\n"
+ + " System.out.println(s1.length());\n"
+ + " break;\n"
+ + " case Integer s1:\n"
+ + " System.out.println(s1.length());\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " System.out.println(s1.length());\n" +
+ " ^^^^^^\n" +
+ "The method length() is undefined for the type Integer\n" +
+ "----------\n");
+ }
+ // Test that a pattern variable declared in the preceding case statement
+ // can't be used in the case statement itself
+ public void testBug573937_9() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " switch (o) {\n"
+ + " case Integer i1:\n"
+ + " break;\n"
+ + " case String s1 && s1.length() > i1:\n"
+ + " System.out.println(s1.length());\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case String s1 && s1.length() > i1:\n" +
+ " ^^\n" +
+ "i1 cannot be resolved to a variable\n" +
+ "----------\n");
+ }
+ // Test that redefining pattern variables with null is allowed
+ // and produce expected result (NPE) when run.
+ public void testBug573937_10() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "public class X {\n"
+ + "@SuppressWarnings(\"null\")"
+ + " public static void foo(Object o) {\n"
+ + " try {\n"
+ + " switch (o) {\n"
+ + " case String s1 && s1.length() == 0:\n"
+ + " break;"
+ + " case String s1:\n"
+ + " s1 = null;\n"
+ + " System.out.println(s1.length());\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " } catch(Exception e) {\n"
+ + " System.out.println(e.getMessage());\n"
+ + " };\n"
+ + " }\n"
+ + " public static void main(String[] args) {\n"
+ + " foo(\"hello\");\n"
+ + " }\n"
+ + "}",
+ };
+ runner.expectedOutputString = "Cannot invoke \"String.length()\" because \"s1\" is null";
+ runner.expectedJavacOutputString = "Cannot invoke \"String.length()\" because \"<local4>\" is null";
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.customOptions = getCompilerOptions();
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel);
+ runner.runConformTest();
+ }
+ // Test that a pattern variable is allowed in a switch label throw
+ // statement and when run, produces expected result
+ public void testBug573937_11() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) throws Exception {\n"
+ + " switch (o) {\n"
+ + " case String s1:\n"
+ + " throw new Exception(s1);\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + " public static void main(String[] args) throws Exception {\n"
+ + " try {\n"
+ + " foo(\"hello\");\n"
+ + " } catch(Exception e) {\n"
+ + " e.printStackTrace(System.out);\n"
+ + " };\n"
+ + " }\n"
+ + "} ",
+ };
+ runner.expectedOutputString = "java.lang.Exception: hello\n" +
+ " at X.foo(X.java:5)\n" +
+ " at X.main(X.java:12)";
+ runner.expectedJavacOutputString = "java.lang.Exception: hello\n"
+ + " at X.foo(X.java:5)\n"
+ + " at X.main(X.java:12)";
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.customOptions = getCompilerOptions();
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel);
+ runner.runConformTest();
+ }
+ // A non effectively final referenced from the RHS of the guarding expression
+ // is reported by the compiler.
+ public void testBug574612_1() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " int len = 2;\n"
+ + " switch (o) {\n"
+ + " case String o1 && o1.length() > len:\n"
+ + " len = 0;\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case String o1 && o1.length() > len:\n" +
+ " ^^^\n" +
+ "Local variable len referenced from a guard must be final or effectively final\n" +
+ "----------\n");
+ }
+ // A non effectively final referenced from the LHS of the guarding expression
+ // is reported by the compiler.
+ public void testBug574612_2() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " int len = 2;\n"
+ + " switch (o) {\n"
+ + " case String o1 && len < o1.length():\n"
+ + " len = 0;\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case String o1 && len < o1.length():\n" +
+ " ^^^\n" +
+ "Local variable len referenced from a guard must be final or effectively final\n" +
+ "----------\n");
+ }
+ // An explicitly final local variable, also referenced in a guarding expression of a pattern
+ // and later on re-assigned is only reported for the explicit final being modified
+ public void testBug574612_3() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " final int len = 2;\n"
+ + " switch (o) {\n"
+ + " case String o1 && len < o1.length():\n"
+ + " len = 0;\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "} ",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " len = 0;\n" +
+ " ^^^\n" +
+ "The final local variable len cannot be assigned. It must be blank and not using a compound assignment\n" +
+ "----------\n");
+ }
+ public void testBug574612_4() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Object o) {\n"
+ + " int len = 2;\n"
+ + " switch (o) {\n"
+ + " case String o1 && len < o1.length():\n"
+ + " System.out.println(o1);\n"
+ + " break;\n"
+ + " default:\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + " public static void main(String[] args) throws Exception {\n"
+ + " foo(\"hello\");\n"
+ + " }\n"
+ + "} ",
+ },
+ "hello");
+ }
+ public void testBug574719_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 0, default : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100 ));\n"+
+ " }\n"+
+ "}",
+ },
+ "1");
+ }
+ public void testBug574719_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 0, default, 1 : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100 ));\n"+
+ " }\n"+
+ "}",
+ },
+ "1");
+ }
+ public void testBug574719_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case default, 1 : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n" +
+ "1");
+ }
+ public void testBug574719_004() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 0 : k = 2; break;\n"+
+ " case default, 1 : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n" +
+ "2");
+ }
+ public void testBug574719_005() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 0 : k = 2; break;\n"+
+ " case 1, default : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n" +
+ "2");
+ }
+ public void testBug574719_006() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 0 : k = 2; break;\n"+
+ " case 1, default, default : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1, default, default : k = 1;\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574719_007() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case 10, default: k = 1;break;\n"+
+ " case 0 : k = 2; break;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " System.out.println(foo(10));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n"+
+ "2\n"+
+ "1");
+ }
+ public void testBug574561_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " default, default : k = 2; break;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default, default : k = 2; break;\n" +
+ " ^\n" +
+ "Syntax error on token \",\", : expected\n" +
+ "----------\n");
+ }
+ public void testBug574561_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case default, 1, default : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case default, 1, default : k = 1;\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574561_003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static int foo(Integer o) {\n"+
+ " int k = 0;\n"+
+ " switch (o) {\n"+
+ " case default, 1, default : k = 1;\n"+
+ " }\n"+
+ " return k;\n"+
+ " } \n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(100));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case default, 1, default : k = 1;\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574793_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {}\n"+
+ " private static void foo1(int o) {\n"+
+ " switch (o) {\n"+
+ " case null -> System.out.println(\"null\");\n"+
+ " case 20 -> System.out.println(\"20\");\n"+
+ " }\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case \"F\" :\n"+
+ " break;\n"+
+ " case 2 :\n"+
+ " break;\n"+
+ " default:\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " switch (o) {\n" +
+ " ^\n" +
+ "An enhanced switch statement should be exhaustive; a default label expected\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " case null -> System.out.println(\"null\");\n" +
+ " ^^^^\n" +
+ "Type mismatch: cannot convert from null to int\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 11)\n" +
+ " case \"F\" :\n" +
+ " ^^^\n" +
+ "Type mismatch: cannot convert from String to Object\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 13)\n" +
+ " case 2 :\n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from int to Object\n" +
+ "----------\n");
+ }
+ public void testBug574559_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {}\n"+
+ " public static void foo1(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case 1, Integer i -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case 1, Integer i -> System.out.println(o);\n" +
+ " ^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ public void testBug574559_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {}\n"+
+ " private static void foo1(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i, 30 -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case Integer i, 30 -> System.out.println(o);\n" +
+ " ^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ // Test that fall-through to a pattern is not allowed (label statement group has one statement)
+ public void testBug573940_1() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "public void foo(Number n) {\n"
+ + " switch (n) {\n"
+ + " case Integer i :\n"
+ + " System.out.println(i);\n"
+ + " case Float f :\n"
+ + " System.out.println(f);\n"
+ + " case Object o : break;\n"
+ + " }\n"
+ + "}\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case Float f :\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " case Object o : break;\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ // Test that fall-through to a pattern is not allowed (label statement group has zero statement)
+ public void testBug573940_2() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "public void foo(Number n) {\n"
+ + " switch (n) {\n"
+ + " case Integer i :\n"
+ + " case Float f :\n"
+ + " System.out.println(f);\n"
+ + " break;\n"
+ + " default : break;\n"
+ + " }\n"
+ + "}\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case Float f :\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ // Test that fall-through to a pattern is not allowed (label statement group has zero statement)
+ public void testBug573940_2a() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "public void foo(Number n) {\n"
+ + " switch (n) {\n"
+ + " default :\n"
+ + " case Float f :\n"
+ + " System.out.println(f);\n"
+ + " break;\n"
+ + " }\n"
+ + "}\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case Float f :\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ // Test that falling through from a pattern to a default is allowed
+ public void testBug573940_3() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + "public static void foo(Number n) {\n"
+ + " switch (n) {\n"
+ + " case Integer i :\n"
+ + " System.out.println(i);\n"
+ + " default:\n"
+ + " System.out.println(\"null\");\n"
+ + " }\n"
+ + " }\n"
+ + "public static void main(String[] args) {\n"
+ + " foo(Integer.valueOf(5));\n"
+ + " }\n"
+ + "}",
+ },
+ "5\n" +
+ "null");
+ }
+ // Test that a case statement with pattern is allowed when statement group ends
+ // with an Throw statement instead of a break statement
+ public void testBug573940_4() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + "public static void foo(Number n) {\n"
+ + " switch (n) {\n"
+ + " case Integer i :\n"
+ + " throw new IllegalArgumentException();\n"
+ + " default:\n"
+ + " System.out.println(\"null\");\n"
+ + " }\n"
+ + " }\n"
+ + "public static void main(String[] args) {\n"
+ + " try{\n"
+ + " foo(Integer.valueOf(5));\n"
+ + " } catch(Exception e) {\n"
+ + " e.printStackTrace(System.out);\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "java.lang.IllegalArgumentException\n" +
+ " at X.foo(X.java:5)\n" +
+ " at X.main(X.java:12)");
+ }
+ // Test that switch expression with pattern variables is reported when a case statement
+ // doesn't return any value.
+ public void testBug573940_5() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public static void foo(Number n) {\n"
+ + " int j = \n"
+ + " switch (n) {\n"
+ + " case Integer i -> {\n"
+ + " }\n"
+ + " default -> {\n"
+ + " yield 1;\n"
+ + " }\n"
+ + " };\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " }\n" +
+ " ^^\n" +
+ "A switch labeled block in a switch expression should not complete normally\n" +
+ "----------\n");
+ }
+ public void testBug574564_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(new String(\"Hello\"));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case var i -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case var i -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "'var' is not allowed here\n" +
+ "----------\n");
+ }
+ public void testBug574564_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(new String(\"Hello\"));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case var i, var j, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case var i, var j, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case var i, var j, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case var i, var j, var k -> System.out.println(0);\n" +
+ " ^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 7)\n" +
+ " case var i, var j, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n");
+ }
+ public void testBug574564_003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case var i, 10 -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case var i, 10 -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n");
+ }
+ public void testBug574564_004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case var i, 10, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case var i, 10, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case var i, 10, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 7)\n" +
+ " case var i, 10, var k -> System.out.println(0);\n" +
+ " ^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n");
+ }
+ public void testBug574564_005() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case 10, null, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case 10, null, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n");
+ }
+ public void testBug574564_006() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case default, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case default, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case default, var k -> System.out.println(0);\n" +
+ " ^^^^^\n" +
+ "A switch label may not have both a pattern case label element and a default case label element\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " default -> System.out.println(o);\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574564_007() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case default, default, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case default, default, var k -> System.out.println(0);\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case default, default, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case default, default, var k -> System.out.println(0);\n" +
+ " ^^^^^\n" +
+ "A switch label may not have both a pattern case label element and a default case label element\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
+ " default -> System.out.println(o);\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574564_008() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(10);\n"+
+ " }\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case default, 1, var k -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case default, 1, var k -> System.out.println(0);\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case default, 1, var k -> System.out.println(0);\n" +
+ " ^^^^^\n" +
+ "A switch label may not have both a pattern case label element and a default case label element\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 8)\n" +
+ " default -> System.out.println(o);\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574564_009() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s, default, Integer i -> System.out.println(0);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case String s, default, Integer i -> System.out.println(0);\n" +
+ " ^^^^^^^\n" +
+ "A switch label may not have both a pattern case label element and a default case label element\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case String s, default, Integer i -> System.out.println(0);\n" +
+ " ^^^^^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n");
+ }
+ public void testBug574564_010() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s, default, Integer i -> System.out.println(0);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case String s, default, Integer i -> System.out.println(0);\n" +
+ " ^\n" +
+ "Syntax error on token \"s\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case String s, default, Integer i -> System.out.println(0);\n" +
+ " ^\n" +
+ "Syntax error on token \"i\", delete this token\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void testBug574564_011() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case null -> System.out.println(0);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case null -> System.out.println(0);\n" +
+ " ^^^^\n" +
+ "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void testBug574564_012() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case 1, default, null -> System.out.println(0);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1, default, null -> System.out.println(0);\n" +
+ " ^^^^^^^\n" +
+ "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case 1, default, null -> System.out.println(0);\n" +
+ " ^^^^\n" +
+ "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void testBug574564_013() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case default, default -> System.out.println(0);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case default, default -> System.out.println(0);\n" +
+ " ^^^^^^^\n" +
+ "The default case is already defined\n" +
+ "----------\n");
+ }
+ public void testBug574563_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {}\n"+
+ " private static void foo1(Integer o) {\n"+
+ " switch (o) {\n"+
+ " case null, null -> System.out.println(o);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case null, null -> System.out.println(o);\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n");
+ }
+ public void testBug574563_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case null, Integer i -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug574563_003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i, null -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug574563_004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case null, Integer i && i > 10 -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case null, Integer i && i > 10 -> System.out.println(0);\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "A null case label and patterns can co-exist only if the pattern is a type pattern\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug574563_005() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i && i > 10, null -> System.out.println(0);\n"+
+ " default -> System.out.println(o);\n"+
+ " }\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer i && i > 10, null -> System.out.println(0);\n" +
+ " ^^^^\n" +
+ "A null case label and patterns can co-exist only if the pattern is a type pattern\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug575030_01() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello World!\");\n"+
+ " }\n"+
+ "\n"+
+ " private static void foo(String o) {\n"+
+ " switch (o) {\n"+
+ " case String s -> System.out.println(s);\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello World!");
+ }
+ public void testBug574614_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(10));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " String s1 = \" Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " switch (o) {\n"+
+ " case Integer I && I > 10: break;\n"+
+ " case X J: break;\n"+
+ " case String s : break;\n"+
+ " default:\n"+
+ " s1 = new StringBuilder(String.valueOf(s1)).append(String.valueOf(s2)).toString();\n"+
+ " System.out.println(s1);\n"+
+ " break; \n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello World!");
+ }
+ public void testBug574614_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(0));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I:\n"+
+ " break;\n"+
+ " case String s :\n"+
+ " break;\n"+
+ " case X J:\n"+
+ " break;\n"+
+ " default:\n"+
+ " String s1 = \"Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " s1 = s1 +s2; \n"+
+ " System.out.println(s1);\n"+
+ " break;\n"+
+ " }\n"+
+ " } \n"+
+ "}",
+ },
+ "Hello World!");
+ }
+ public void testBug573921_1() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case CharSequence cs ->\n" +
+ " System.out.println(\"A sequence of length \" + cs.length());\n" +
+ " case String s && s.length() > 0 -> \n" +
+ " System.out.println(\"A string: \" + s);\n" +
+ " default -> {\n" +
+ " break;\n" +
+ " } \n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case String s && s.length() > 0 -> \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ public void testBug573921_2() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case CharSequence cs:\n" +
+ " System.out.println(\"A sequence of length \" + cs.length());\n" +
+ " break;\n" +
+ " case String s:\n" +
+ " System.out.println(\"A string: \" + s);\n" +
+ " break;\n" +
+ " default: \n" +
+ " break;\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case String s:\n" +
+ " ^^^^^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ public void testBug573921_3() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello!\");\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case String s:\n" +
+ " System.out.println(\"String:\" + s);\n" +
+ " break;\n" +
+ " case CharSequence cs:\n" +
+ " System.out.println(\"A CS:\" + cs);\n" +
+ " break;\n" +
+ " default: \n" +
+ " break;\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "String:Hello!");
+ }
+ public void testBug573921_4() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(new StringBuffer(\"Hello!\"));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case String s:\n" +
+ " System.out.println(\"String:\" + s);\n" +
+ " break;\n" +
+ " case CharSequence cs:\n" +
+ " System.out.println(\"A CS:\" + cs.toString());\n" +
+ " break;\n" +
+ " default: \n" +
+ " break;\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "A CS:Hello!");
+ }
+ public void testBug573921_5() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case String s && s.length() < 5 :\n" +
+ " System.out.println(\"1:\" + s);\n" +
+ " break;\n" +
+ " case String s && s.length() == 5:\n" +
+ " System.out.println(\"2:\" + s);\n" +
+ " break;\n" +
+ " default : System.out.println(\"Object\");\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "2:Hello");
+ }
+ public void testBug573921_6() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"\");\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n" +
+ " case String s && s.length() < 5 :\n" +
+ " System.out.println(\"1:\" + s);\n" +
+ " break;\n" +
+ " case String s && s.length() == 5:\n" +
+ " System.out.println(\"2:\" + s);\n" +
+ " break;\n" +
+ " default : System.out.println(\"Object\");\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "1:");
+ }
+ public void testBug573921_7() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n"+
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n"+
+ " case List cs:\n"+
+ " System.out.println(\"A sequence of length \" + cs.size());\n"+
+ " break;\n"+
+ " case List<String> s: \n"+
+ " System.out.println(\"A string: \" + s);\n"+
+ " break;\n"+
+ " } "+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " switch(o) {\n" +
+ " ^\n" +
+ "An enhanced switch statement should be exhaustive; a default label expected\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " case List<String> s: \n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Type Object cannot be safely cast to List<String>\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " case List<String> s: \n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ public void testBug573921_8() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n"+
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " private static void foo(Object o) {\n"+
+ " switch(o.hashCode()) {\n"+
+ " case String s:\n"+
+ " break;\n"+
+ " default: \n"+
+ " break;\n"+
+ " } "+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case String s:\n" +
+ " ^^^^^^^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
+ "----------\n");
+ }
+ public void testBug573921_9() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n"+
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " private static void foo(Object o) {\n"+
+ " switch(o) {\n"+
+ " case Object o1:\n"+
+ " break;\n"+
+ " default: \n"+
+ " break;\n"+
+ " } "+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " default: \n" +
+ " ^^^^^^^\n" +
+ "Switch case cannot have both a total pattern and default label\n" +
+ "----------\n");
+ }
+ public void testBug573921_10() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n"+
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " private static void foo(List<String> o) {\n"+
+ " switch(o) {\n"+
+ " case List o1:\n"+
+ " break;\n"+
+ " default: \n"+
+ " break;\n"+
+ " } "+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " default: \n" +
+ " ^^^^^^^\n" +
+ "Switch case cannot have both a total pattern and default label\n" +
+ "----------\n");
+ }
+ public void testBug573921_11() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n"+
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " private static void foo(String s) {\n"+
+ " switch(s) {\n"+
+ " case CharSequence cs:\n"+
+ " break;\n"+
+ " default: \n"+
+ " break;\n"+
+ " } "+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " default: \n" +
+ " ^^^^^^^\n" +
+ "Switch case cannot have both a total pattern and default label\n" +
+ "----------\n");
+ }
+ public void testBug575049_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "sealed interface I permits A,B,C {}\n"+
+ "final class A implements I {}\n"+
+ "final class B implements I {}\n"+
+ "record C(int j) implements I {} // Implicitly final\n"+
+ "public class X {\n"+
+ " static int testSealedCoverage(I i) {\n"+
+ " return switch (i) {\n"+
+ " case A a -> 0;\n"+
+ " case B b -> 1;\n"+
+ " case C c -> 2; // No default required!\n"+
+ " default -> 3;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " A a = new A();\n"+
+ " System.out.println(testSealedCoverage(a));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575049_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "sealed interface I permits A,B,C {}\n"+
+ "final class A implements I {}\n"+
+ "final class B implements I {}\n"+
+ "record C(int j) implements I {} // Implicitly final\n"+
+ "public class X {\n"+
+ " static int testSealedCoverage(I i) {\n"+
+ " return switch (i) {\n"+
+ " case A a -> 0;\n"+
+ " case B b -> 1;\n"+
+ " case C c -> 2; // No default required!\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " A a = new A();\n"+
+ " System.out.println(testSealedCoverage(a));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575049_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "sealed interface I permits A,B,C {}\n"+
+ "final class A implements I {}\n"+
+ "final class B implements I {}\n"+
+ "record C(int j) implements I {} // Implicitly final\n"+
+ "public class X {\n"+
+ " static int testSealedCoverage(I i) {\n"+
+ " return switch (i) {\n"+
+ " case A a -> 0;\n"+
+ " case B b -> 1;\n"+
+ " default -> 2; // No default required!\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " A a = new A();\n"+
+ " System.out.println(testSealedCoverage(a));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575049_004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "sealed interface I permits A,B,C {}\n"+
+ "final class A implements I {}\n"+
+ "final class B implements I {}\n"+
+ "record C(int j) implements I {} // Implicitly final\n"+
+ "public class X {\n"+
+ " static int testSealedCoverage(I i) {\n"+
+ " return switch (i) {\n"+
+ " case A a -> 0;\n"+
+ " case B b -> 1;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " A a = new A();\n"+
+ " System.out.println(testSealedCoverage(a));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " return switch (i) {\n" +
+ " ^\n" +
+ "A switch expression should have a default case\n" +
+ "----------\n");
+ }
+ public void testBug575048_01() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " default -> 2;\n"+
+ " case Integer i1 -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(1));\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case Integer i1 -> 0;\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Switch case cannot have both a total pattern and default label\n" +
+ "----------\n");
+ }
+ public void testBug575053_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(String o) {\n" +
+ " switch (o) {\n" +
+ " case String s && s.length() > 0 -> {}\n" +
+ " default -> {}\n" +
+ " } \n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " try{\n" +
+ " (new X()).foo(null);\n" +
+ " } catch(Exception e) {\n" +
+ " e.printStackTrace(System.out);\n" +
+ " }\n" +
+ " }\n"+
+ "}",
+ },
+ "java.lang.NullPointerException\n" +
+ " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n" +
+ " at X.foo(X.java:3)\n" +
+ " at X.main(X.java:10)");
+ }
+ public void testBug575053_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case String s -> {}\n" +
+ " default -> {}\n" +
+ " } \n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " try{\n" +
+ " (new X()).foo(null);\n" +
+ " } catch(Exception t) {\n" +
+ " t.printStackTrace();\n" +
+ " }\n" +
+ " }\n"+
+ "}",
+ },
+ "",
+ "java.lang.NullPointerException\n" +
+ " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n" +
+ " at X.foo(X.java:3)\n" +
+ " at X.main(X.java:10)");
+ }
+ public void testBug575249_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case (String s) : yield 0;\n" +
+ " default : yield 1;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(\"Hello\"));\n" +
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575249_02() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case (String s && s.length() < 10) : yield 0;\n" +
+ " default : yield 1;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(\"Hello\"));\n" +
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575249_03() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case (String s) -> 0;\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(\"Hello\"));\n" +
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575249_04() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case (String s && s.length() < 10) -> 0;\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(\"Hello\"));\n" +
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575241_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case Integer i1 -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(1));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575241_02() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case Object o -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(1));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575241_03() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Object myVar) {\n"+
+ " return switch (myVar) {\n"+
+ " case null -> 0;\n"+
+ " case Integer o -> 1;\n"+
+ " case Object obj ->2;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(Integer.valueOf(0)));\n"+
+ " System.out.println(foo(null));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n" +
+ "0");
+ }
+ public void testBug575241_04() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Object myVar) {\n"+
+ " return switch (myVar) {\n"+
+ " case Integer o -> 1;\n"+
+ " case Object obj ->2;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(Integer.valueOf(0)));\n"+
+ " System.out.println(foo(null));\n"+
+ " }\n"+
+ "}",
+ },
+ "1\n" +
+ "2");
+ }
+ public void testBug575241_05() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Integer myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case null -> System.out.println(100);\n"+
+ " case Integer o -> System.out.println(o);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(0));\n"+
+ " foo(null);\n"+
+ " }\n"+
+ "}",
+ },
+ "0\n" +
+ "100");
+ }
+ public void testBug575241_06() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Integer myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case Integer o -> System.out.println(o);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(0));\n"+
+ " foo(null);\n"+
+ " }\n"+
+ "}",
+ },
+ "0\n" +
+ "null");
+ }
+ public void testBug575241_07() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(String myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case null -> System.out.println(100);\n"+
+ " case String o -> System.out.println(o);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " foo(null);\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello\n" +
+ "100");
+ }
+ public void testBug575241_08() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(String myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case String o -> System.out.println(o);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " foo(null);\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello\n" +
+ "null");
+ }
+ public void testBug575356_01() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Integer myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case default -> System.out.println(\"hello\");\n"+
+ " }; \n"+
+ " } \n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(10)); \n"+
+ " } \n"+
+ "}",
+ },
+ "hello");
+ }
+ public void testBug575356_02() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Integer myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case null, default -> System.out.println(\"hello\");\n"+
+ " }; \n"+
+ " } \n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(10)); \n"+
+ " } \n"+
+ "}",
+ },
+ "hello");
+ }
+ public void testBug575356_03() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Integer myVar) {\n"+
+ " switch (myVar) {\n"+
+ " case default, null -> System.out.println(\"hello\");\n"+
+ " }; \n"+
+ " } \n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(10)); \n"+
+ " } \n"+
+ "}",
+ },
+ "hello");
+ }
+ public void testBug575356_04() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer i ->\n"+
+ " System.out.println(\"Integer:\"+ i );\n"+
+ " case default -> System.out.println(o.toString() );\n"+
+ " }\n"+
+ "}\n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Integer.valueOf(10)); \n"+
+ " foo(new String(\"Hello\")); \n"+
+ " } \n"+
+ "}",
+ },
+ "Integer:10\n" +
+ "Hello");
+ }
+ public void testBug575052_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s -> System.out.println(s);\n"+
+ " default -> System.out.println(0);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello");
+ }
+ public void testBug575052_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case String s -> System.out.println(s);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " switch (o) {\n" +
+ " ^\n" +
+ "An enhanced switch statement should be exhaustive; a default label expected\n" +
+ "----------\n");
+ }
+ public void testBug575052_003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case null -> System.out.println(0);\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " switch (o) {\n" +
+ " ^\n" +
+ "An enhanced switch statement should be exhaustive; a default label expected\n" +
+ "----------\n");
+ }
+ public void testBug575052_004() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private static int foo(int i) {\n"+
+ " switch (i) {\n"+
+ " case 1:\n"+
+ " break;\n"+
+ " }\n"+
+ " return 0;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "0");
+ }
+ public void testBug575050_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Object o) {\n"+
+ " return switch (o) {\n"+
+ " case String s -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return switch (o) {\n" +
+ " ^\n" +
+ "A switch expression should have a default case\n" +
+ "----------\n");
+ }
+ public void testBug575050_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Object o) {\n"+
+ " return switch (o) {\n"+
+ " case null -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(\"Hello\");\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return switch (o) {\n" +
+ " ^\n" +
+ "A switch expression should have a default case\n" +
+ "----------\n");
+ }
+ // From 14.11.1: A switch label that has a pattern case label element p that is
+ // total for the type of the selector expression of the enclosing
+ // switch statement or switch expression dominates a switch label that has
+ // a null case label element.
+ public void testBug575047_01() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case Integer i1 -> 0;\n"+
+ " case null -> 2;\n"+
+ " };\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case null -> 2;\n" +
+ " ^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ // A switch label that has a pattern case label element p dominates another
+ // switch label that has a constant case label element c if either of the
+ // following is true:
+ // * the type of c is a primitive type and its wrapper class (5.1.7) is a subtype of the erasure of the type of p.
+ // * the type of c is a reference type and is a subtype of the erasure of the type of p.
+ public void testBug575047_02() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case Integer i1 -> i1;\n"+
+ " case 0 -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case 0 -> 0;\n" +
+ " ^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ public void testBug575047_03() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Color c) {\n"+
+ " switch (c) {\n" +
+ " case Color c1 : \n" +
+ " break;\n" +
+ " case Blue :\n" +
+ " break;\n" +
+ " }\n"+
+ " }\n"+
+ "enum Color { Blue, Red; }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case Blue :\n" +
+ " ^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ public void testBug575047_04() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case null -> 2;\n"+
+ " case Integer i1 -> 0;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(null));\n"+
+ " System.out.println(foo(Integer.valueOf(0)));\n"+
+ " }\n"+
+ "}",
+ },
+ "2\n" +
+ "0");
+ }
+ public void testBug575047_05() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(float c) {\n"+
+ " switch (c) {\n" +
+ " case 0 : \n" +
+ " break;\n" +
+ " default :\n" +
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 0 : \n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from int to float\n" +
+ "----------\n");
+ }
+ public void testBug575047_06() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(String o) {\n"+
+ " return switch (o) {\n" +
+ " case String s && s.length() > 0 -> 3;\n" +
+ " case String s1 -> 1;\n" +
+ " case String s -> -1;\n"+
+ " };\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case String s -> -1;\n" +
+ " ^^^^^^^^\n" +
+ "The switch statement cannot have more than one total pattern\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case String s -> -1;\n" +
+ " ^^^^^^^^\n" +
+ "This case label is dominated by one of the preceding case label\n" +
+ "----------\n");
+ }
+ // Test that when a literal is used as case constant
+ // we report type mismatch error against the literal's type and
+ // not on other types the case statement may have resolved too
+ public void testBug575047_07() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(Number i) {\n"+
+ " switch (i) {\n"+
+ " case Integer j, \"\":\n"+
+ " System.out.println(0);\n"+
+ " default:\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer j, \"\":\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from String to Number\n" +
+ "----------\n");
+ }
+ public void testBug575047_08() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(Integer i) {\n"+
+ " return switch (i) {\n"+
+ " case 0 -> 0;\n"+
+ " case Integer i1 -> i1;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(3));\n"+
+ " System.out.println(foo(0));\n"+
+ " }\n"+
+ "}",
+ },
+ "3\n"+
+ "0");
+ }
+ public void testBug575047_09() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(String i) {\n"+
+ " return switch (i) {\n"+
+ " case \"\" -> 0;\n"+
+ " case String s -> -1;\n"+
+ " };\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(foo(\"\"));\n"+
+ " System.out.println(foo(\"abc\"));\n"+
+ " }\n"+
+ "}",
+ },
+ "0\n" +
+ "-1");
+ }
+ public void testBug575047_10() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static String foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case String i && i.length() == 0 -> \"empty\";\n" +
+ " case String i && i.length() > 0 -> \"zero+\";\n" +
+ " case Color s -> s.toString();\n" +
+ " default -> \"unknown\";\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(\"abc\"));\n" +
+ " System.out.println(foo(\"\"));\n" +
+ " System.out.println(Color.Blue);\n" +
+ " System.out.println(foo(args));\n" +
+ " }\n" +
+ "} \n" +
+ "enum Color {\n" +
+ " Blue, Red; \n" +
+ "}",
+ },
+ "zero+\n" +
+ "empty\n" +
+ "Blue\n" +
+ "unknown");
+ }
+ // Positive - Mix enum constants as well as suitable pattern var
+ public void testBug575047_11() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static String foo(Color o) {\n" +
+ " return switch (o) {\n" +
+ " case Red -> \"Red\";\n" +
+ " case Color s -> s.toString();\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(Color.Red);\n" +
+ " System.out.println(Color.Blue);\n" +
+ " }\n" +
+ "} \n" +
+ "enum Color {\n" +
+ " Blue, Red; \n" +
+ "}",
+ },
+ "Red\n" +
+ "Blue");
+ }
+ public void testBug575047_12() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static String foo(Color o) {\n" +
+ " return switch (o) {\n" +
+ " case Red -> \"Red\";\n" +
+ " case Color s && s == Color.Blue -> s.toString();" +
+ " case Color s -> s.toString();\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(Color.Red);\n" +
+ " System.out.println(Color.Blue);\n" +
+ " }\n" +
+ "} \n" +
+ "enum Color {\n" +
+ " Blue, Red; \n" +
+ "}",
+ },
+ "Red\n" +
+ "Blue");
+ }
+ public void testBug575047_13() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static String foo(Color o) {\n" +
+ " return switch (o) {\n" +
+ " case Color s && s == Color.Blue -> s.toString();" +
+ " case Red -> \"Red\";\n" +
+ " case null -> \"\";\n" +
+ " };\n" +
+ " }\n" +
+ "} \n" +
+ "enum Color {\n" +
+ " Blue, Red; \n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return switch (o) {\n" +
+ " ^\n" +
+ "A Switch expression should cover all possible values\n" +
+ "----------\n");
+ }
+ public void testBug575047_14() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static String foo(Color o) {\n" +
+ " return switch (o) {\n" +
+ " case Color s && s == Color.Blue -> s.toString();" +
+ " case Red -> \"Red\";\n" +
+ " };\n" +
+ " }\n" +
+ "} \n" +
+ "enum Color {\n" +
+ " Blue, Red; \n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return switch (o) {\n" +
+ " ^\n" +
+ "A Switch expression should cover all possible values\n" +
+ "----------\n");
+ }
+ public void testBug575047_15() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static void foo(Integer o) {\n" +
+ " switch (o) {\n" +
+ " case 1: break;\n" +
+ " case Integer s && s == 2:\n" +
+ " System.out.println(s);break;\n" +
+ " case null, default:\n" +
+ " System.out.println(\"null/default\");\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " foo(null);\n" +
+ " }\n" +
+ "}",
+ },
+ "null/default");
+ }
+ public void testBug575360_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo(String myVar) { // String\n"+
+ " switch (myVar) {\n"+
+ " case null, default : System.out.println(\"hello\");\n"+
+ " }; \n"+
+ " }\n"+
+ " public static void main(String[] args) { \n"+
+ " foo(new String(\"Hello\")); \n"+
+ " }\n"+
+ "}",
+ },
+ "hello");
+ }
+ public void testBug575055_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(CharSequence c) {\n" +
+ " return switch (c) {\n" +
+ " case CharSequence c1 && (c instanceof String c1 && c1.length() > 0) -> 0;\n" +
+ " default -> 0;\n" +
+ " };\n" +
+ " }" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case CharSequence c1 && (c instanceof String c1 && c1.length() > 0) -> 0;\n" +
+ " ^^\n" +
+ "Duplicate local variable c1\n" +
+ "----------\n");
+ }
+ // Fails with Javac as it prints Javac instead of throwing NPE
+ // https://bugs.openjdk.java.net/browse/JDK-8272776
+ public void testBug575051_1() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Object o) {\n" +
+ " try{\n" +
+ " switch (o) {\n" +
+ " default:\n" +
+ " break;\n" +
+ " case String s :\n" +
+ " System.out.println(s);\n" +
+ " } \n" +
+ " } catch(Exception t) {\n" +
+ " t.printStackTrace(System.out);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " (new X()).foo(null);\n" +
+ " }\n" +
+ "}",
+ },
+ "java.lang.NullPointerException\n"
+ + " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n"
+ + " at X.foo(X.java:4)\n"
+ + " at X.main(X.java:15)");
+ }
+ // Test we don't report any illegal fall-through to null case
+ public void testBug575051_2() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case String s :\n" +
+ " System.out.println(s);\n" +
+ " //$FALL-THROUGH$\n" +
+ " case null:\n" +
+ " break;\n" +
+ " default : \n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " (new X()).foo(null);\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ }
+ // Test we do report illegal fall-through to pattern
+ public void testBug575051_3() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " default : \n" +
+ " case String s :\n" +
+ " System.out.println();\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " (new X()).foo(null);\n" +
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case String s :\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n",
+ "");
+ }
+ public void testBug575571_1() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
+ runWarningTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Color o) {\n" +
+ " switch (o) {\n" +
+ " case Blue:\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {}\n" +
+ "}\n" +
+ "enum Color { Blue; }\n",
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " switch (o) {\n" +
+ " ^\n" +
+ "The switch over the enum type Color should have a default case\n" +
+ "----------\n",
+ options);
+ }
+ public void testBug575571_2() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Color o) {\n" +
+ " switch (o) {\n" +
+ " case Blue:\n" +
+ " case Color c:\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {}\n" +
+ "}\n" +
+ "enum Color { Blue, Red; }\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case Color c:\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Illegal fall-through to a pattern\n" +
+ "----------\n");
+ }
+ public void testBug575714_01() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static Object foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Object __ -> throw new AssertionError(); \n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n");
+ }
+ public void testBug575714_02() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static Object foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Object __ -> System.out.println(\"Hello\"); \n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo(new X());\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " static Object foo(Object o) {\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "This method must return a result of type Object\n" +
+ "----------\n");
+ }
+ public void testBug575714_03() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static Object foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Object __ -> System.out.println(\"Hello\"); \n"+
+ " }\n"+
+ " return null;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo(new X());\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello");
+ }
+ public void testBug575714_04() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static Object foo(Object o) throws Exception {\n"+
+ " switch (o) {\n"+
+ " case Object __ -> throw new Exception(); \n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " try {\n"+
+ " X.foo(new X());\n"+
+ " } catch (Exception e) {\n"+
+ " System.out.println(\"Hello\");\n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello");
+ }
+ public void testBug575687_1() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static void number(Number i) {\n" +
+ " switch (i) {\n" +
+ " case Integer i2, 4.5:\n" +
+ " case 4.3: System.out.println();\n" +
+ " default: System.out.println(\"nothing\");\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {}\n" +
+ "}\n" +
+ "enum Color { Blue, Red; }\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer i2, 4.5:\n" +
+ " ^^^\n" +
+ "Type mismatch: cannot convert from double to Number\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " case 4.3: System.out.println();\n" +
+ " ^^^\n" +
+ "Type mismatch: cannot convert from double to Number\n" +
+ "----------\n");
+ }
+ public void testBug575686_1() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i1, String s1 ->\n" +
+ " System.out.print(s1);\n" +
+ " default -> System.out.print(\"default\");\n" +
+ " case Number n, null ->\n" +
+ " System.out.print(o);\n" +
+ " case null, Class c ->\n" +
+ " System.out.print(o);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {}\n" +
+ "}\n" +
+ "enum Color { Blue, Red; }\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer i1, String s1 ->\n" +
+ " ^^^^^^^^^\n" +
+ "A switch label may not have more than one pattern case label element\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case Number n, null ->\n" +
+ " ^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " case null, Class c ->\n" +
+ " ^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "4. WARNING in X.java (at line 9)\n" +
+ " case null, Class c ->\n" +
+ " ^^^^^\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "----------\n");
+ }
+ public void testBug575737_001() {
+ Map<String, String> options =getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo1(String o) {\n"+
+ " switch (o) {\n"+
+ " case null -> System.out.println(\"null\");\n"+
+ " case String s -> String.format(\"String %s\", s);\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 4)\n" +
+ " case null -> System.out.println(\"null\");\n" +
+ " ^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 5)\n" +
+ " case String s -> String.format(\"String %s\", s);\n" +
+ " ^^^^^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n",
+ null,
+ true,
+ options
+ );
+ }
+ public void testBug575737_002() {
+ Map<String, String> options =getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.INFO);
+
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static void foo1(String o) {\n"+
+ " switch (o) {\n"+
+ " case null -> System.out.println(\"null\");\n"+
+ " case String s -> String.format(\"String %s\", s);\n"+
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. INFO in X.java (at line 4)\n" +
+ " case null -> System.out.println(\"null\");\n" +
+ " ^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "2. INFO in X.java (at line 5)\n" +
+ " case String s -> String.format(\"String %s\", s);\n" +
+ " ^^^^^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n",
+ null,
+ true,
+ options
+ );
+ }
+ public void testBug575738_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " private static void foo(Object o) {\n" +
+ " switch (o.hashCode()) {\n" +
+ " case int t: System.out.println(\"Integer\"); \n" +
+ " default : System.out.println(\"Object\"); \n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) { \n" +
+ " foo(\"Hello World\");\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case int t: System.out.println(\"Integer\"); \n" +
+ " ^^^^^\n" +
+ "Unexpected type int, expected class or array type\n" +
+ "----------\n");
+ }
+ public void testBug575738_002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " private static void foo(Object o) {\n" +
+ " switch (o.hashCode()) {\n" +
+ " case Integer t: System.out.println(\"Integer\"); \n" +
+ " default : System.out.println(\"Object\"); \n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) { \n" +
+ " foo(\"Hello World\");\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case Integer t: System.out.println(\"Integer\"); \n" +
+ " ^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from int to Integer\n" +
+ "----------\n");
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
index 22ea1ed..764f060 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.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
* Technical University Berlin - adapted for Object Teams
@@ -201,7 +205,7 @@
// add 15 specific test here (check duplicates)
ArrayList since_15 = new ArrayList();
- since_15.add(ClassFileReaderTest_15.class);
+ since_15.add(ClassFileReaderTest_17.class);
since_15.add(JavadocTest_15.class);
since_15.add(Unicode13Test.class);
since_15.add(BatchCompilerTest_15.class);
@@ -209,16 +213,22 @@
// add 16 specific test here (check duplicates)
ArrayList since_16 = new ArrayList();
- since_16.add(SealedTypesTests.class);
since_16.add(LocalEnumTest.class);
since_16.add(LocalStaticsTest.class);
since_16.add(PreviewFeatureTest.class);
since_16.add(ValueBasedAnnotationTests.class);
since_16.add(BatchCompilerTest_16.class);
- since_16.add(RecordsRestrictedClassTest.class);
since_16.add(PatternMatching16Test.class);
+ since_16.add(RecordsRestrictedClassTest.class);
since_16.add(JavadocTestForRecord.class);
+ // add 17 specific test here (check duplicates)
+ ArrayList since_17 = new ArrayList();
+ since_17.add(SealedTypesTests.class);
+ since_17.add(SwitchPatternTest.class);
+ since_17.add(InstanceofPrimaryPatternTest.class);
+ since_17.add(NullAnnotationTests17.class);
+
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
all.addTest(new TestSuite(StandAloneASTParserTest.class));
@@ -396,6 +406,25 @@
TestCase.resetForgottenFilters(tests_16);
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16), tests_16));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_17) != 0) {
+ ArrayList tests_17 = (ArrayList)standardTests.clone();
+ tests_17.addAll(since_1_4);
+ tests_17.addAll(since_1_5);
+ tests_17.addAll(since_1_6);
+ tests_17.addAll(since_1_7);
+ tests_17.addAll(since_1_8);
+ tests_17.addAll(since_9);
+ tests_17.addAll(since_10);
+ tests_17.addAll(since_11);
+ tests_17.addAll(since_12);
+ tests_17.addAll(since_13);
+ tests_17.addAll(since_14);
+ tests_17.addAll(since_15);
+ tests_17.addAll(since_16);
+ tests_17.addAll(since_17);
+ TestCase.resetForgottenFilters(tests_17);
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17), tests_17));
+ }
all.addTest(new TestSuite(Jsr14Test.class));
return all;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ValueBasedAnnotationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ValueBasedAnnotationTests.java
index 2ea38de..0728691 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ValueBasedAnnotationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ValueBasedAnnotationTests.java
@@ -8,11 +8,17 @@
*
* 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
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
public class ValueBasedAnnotationTests extends AbstractRegressionTest {
@@ -34,12 +40,9 @@
@Override
protected Map<String, String> getCompilerOptions() {
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
- defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
+ if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel()) {
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ }
return defaultOptions;
}
protected void runWarningTest(String[] testFiles, String expectedCompilerLog) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
index 35b6bba..164dad7 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -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
*******************************************************************************/
@@ -48,6 +52,7 @@
public static final int F_14 = 0x800;
public static final int F_15 = 0x1000;
public static final int F_16 = 0x2000;
+ public static final int F_17 = 0x4000;
public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));
public static final boolean PERFORMANCE_ASSERTS = !CompilerOptions.DISABLED.equals(System.getProperty("jdt.performance.asserts"));
@@ -66,6 +71,7 @@
protected static boolean isJRE14Plus = false;
protected static boolean isJRE15Plus = false;
protected static boolean isJRE16Plus = false;
+ protected static boolean isJRE17Plus = false;
protected static boolean reflectNestedClassUseDollar;
public static int[][] complianceTestLevelMapping = new int[][] {
@@ -83,6 +89,7 @@
new int[] {F_14, ClassFileConstants.MAJOR_VERSION_14},
new int[] {F_15, ClassFileConstants.MAJOR_VERSION_15},
new int[] {F_16, ClassFileConstants.MAJOR_VERSION_16},
+ new int[] {F_17, ClassFileConstants.MAJOR_VERSION_17},
};
/**
@@ -312,7 +319,8 @@
public static int getPossibleComplianceLevels() {
if (possibleComplianceLevels == UNINITIALIZED) {
String specVersion = System.getProperty("java.specification.version");
- isJRE16Plus = CompilerOptions.VERSION_16.equals(specVersion);
+ isJRE17Plus = CompilerOptions.VERSION_17.equals(specVersion);
+ isJRE16Plus = isJRE17Plus || CompilerOptions.VERSION_16.equals(specVersion);
isJRE15Plus = isJRE16Plus || CompilerOptions.VERSION_15.equals(specVersion);
isJRE14Plus = isJRE15Plus || CompilerOptions.VERSION_14.equals(specVersion);
isJRE13Plus = isJRE14Plus || CompilerOptions.VERSION_13.equals(specVersion);
@@ -365,6 +373,9 @@
} else if (CompilerOptions.VERSION_16.equals(compliance)) {
if (isJRE16Plus)
possibleComplianceLevels |= F_16;
+ } else if (CompilerOptions.VERSION_17.equals(compliance)) {
+ if (isJRE17Plus)
+ possibleComplianceLevels |= F_17;
} else {
System.out.println("Ignoring invalid compliance (" + compliance + ")");
System.out.print("Use one of ");
@@ -448,6 +459,10 @@
if (canRun16) {
possibleComplianceLevels |= F_16;
}
+ boolean canRun17 = canRun16 && !CompilerOptions.VERSION_16.equals(specVersion);
+ if (canRun17) {
+ possibleComplianceLevels |= F_17;
+ }
} else if ("1.0".equals(specVersion)
|| CompilerOptions.VERSION_1_1.equals(specVersion)
|| CompilerOptions.VERSION_1_2.equals(specVersion)
@@ -478,6 +493,9 @@
possibleComplianceLevels |= F_15;
if (!CompilerOptions.VERSION_15.equals(specVersion)) {
possibleComplianceLevels |= F_16;
+ if (!CompilerOptions.VERSION_16.equals(specVersion)) {
+ possibleComplianceLevels |= F_17;
+ }
}
}
}
@@ -666,7 +684,7 @@
int major = Integer.parseInt(ver) + ClassFileConstants.MAJOR_VERSION_0;
return "version " + ver + " : " + major + ".0";
}
- if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16)) return version; // keep this stmt for search for next bump up
+ if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17)) return version; // keep this stmt for search for next bump up
return version;
}
diff --git a/org.eclipse.jdt.core.tests.model/JCL/build.xml b/org.eclipse.jdt.core.tests.model/JCL/build.xml
index ddc9f08..0099d07 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/build.xml
+++ b/org.eclipse.jdt.core.tests.model/JCL/build.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2020 GK Software SE and others.
+ Copyright (c) 2020, 2021 GK Software SE and others.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
@@ -60,11 +60,16 @@
<param name="suffix" value="14"/>
</antcall>
<antcall target="converterJclMin">
+ <param name="compliance" value="17"/>
+ <param name="suffix" value="17"/>
+ </antcall>
+ <antcall target="converterJclMin">
<param name="compliance" value="15"/>
<param name="suffix" value="15"/>
</antcall>
</target>
<target name="converterJclMin">
+ <mkdir dir="${jclbase}/converterJclMin${suffix}/bin" />
<javac srcdir="${jclbase}/converterJclMin${suffix}/src" destdir="${jclbase}/converterJclMin${suffix}/bin"
debuglevel="lines,source"
source="${compliance}"
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin.jar
index 7e7a03b..3a45069 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5.jar
index 62b6fde..9c0a735 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5src.zip
index e40166b..8fd6721 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.5src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7.jar
index 9c37fe9..b68bd85 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7src.zip
index f5af3b3..90c91c1 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.7src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8.jar
index a8c56d4..5d25633 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8src.zip
index 6c59c10..6bbe4c9 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin1.8src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar
index 1fde0c9..9ef6dfd 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip
index 509eaf4..d27f821 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11.jar
index cad83d9..8796dd9 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11src.zip
index 694b4a9..b4e9b6f 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin11src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar
index 1e31f3f..56e0019 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip
index 694b4a9..fc6cd99 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13.jar
index 1f4437e..f9619b9 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13src.zip
index 2316ed3..b5ba021 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin13src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14.jar
index 567d680..edfd11d 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14src.zip
index ac63004..7d19bc5 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin14src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15.jar
index a0725dc..e4f6c63 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15src.zip
index e1866a8..6876082 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin15src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17.jar
new file mode 100644
index 0000000..539375b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17src.zip
new file mode 100644
index 0000000..8674e83
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin17src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
index 9cd2cba..b968f8a 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
index 106b5ee..fee9e90 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMinsrc.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMinsrc.zip
index 3c0206a..1b34dee 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMinsrc.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMinsrc.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin17.jar b/org.eclipse.jdt.core.tests.model/JCL/jclMin17.jar
new file mode 100644
index 0000000..35eef29
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin17.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin17src.zip b/org.eclipse.jdt.core.tests.model/JCL/jclMin17src.zip
new file mode 100644
index 0000000..f2cbf85
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin17src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
index 0c6c687..8ba2eca 100644
--- a/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.model;singleton:=true
-Bundle-Version: 3.11.0.qualifier
+Bundle-Version: 3.11.50.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests,
diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml
index 02bce45..56bfc3b 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2020 Eclipse Foundation and others.
+ Copyright (c) 2012, 2021 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.model</artifactId>
- <version>3.11.0-SNAPSHOT</version>
+ <version>3.11.50-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
@@ -47,6 +47,12 @@
</build>
<profiles>
+ <profile>
+ <id>build-individual-bundles</id>
+ <properties>
+ <code.ignoredWarnings>-warn:+fieldHiding,-unavoidableGenericProblems,-discouraged</code.ignoredWarnings>
+ </properties>
+ </profile>
<profile>
<id>test-on-javase-9</id>
<build>
@@ -230,6 +236,36 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,15,16</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-17</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <id>JavaSE-17</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,14,17</tycho.surefire.argLine>
+ </properties>
+ </profile>
</profiles>
</project>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
index 52673d8..40b4367 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
@@ -7,6 +7,9 @@
* 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
*******************************************************************************/
@@ -61,9 +64,9 @@
this.ast = AST.newAST(getAST15(), false);
this.currentProject = getJavaProject("Converter_15");
if (this.ast.apiLevel() == AST.JLS15 ) {
- this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_16);
- this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16);
- this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16);
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
}
}
@@ -940,7 +943,8 @@
}
}
- public void testSealed001() throws CoreException {
+ // Move sealed test to AST 17 converter class
+ public void _testSealed001() throws CoreException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
@@ -986,7 +990,8 @@
}
}
- public void testSealed002() throws CoreException {
+ // Move sealed test to AST 17 converter class
+ public void _testSealed002() throws CoreException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
@@ -1022,7 +1027,8 @@
}
}
- public void testSealed003() throws CoreException {
+ // Move sealed test to AST 17 converter class
+ public void _testSealed003() throws CoreException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
@@ -1067,7 +1073,8 @@
}
}
- public void testSealed004() throws CoreException {
+ // Move sealed test to AST 17 converter class
+ public void _testSealed004() throws CoreException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java
index 031ba91..1c7ea3e 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java
@@ -7,6 +7,9 @@
* 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
@@ -53,6 +56,7 @@
ICompilationUnit workingCopy;
+ @SuppressWarnings("deprecation")
public void setUpSuite() throws Exception {
super.setUpSuite();
this.ast = AST.newAST(getAST16(), false);
@@ -73,6 +77,7 @@
return buildModelTestSuite(ASTConverter_16Test.class);
}
+ @SuppressWarnings("deprecation")
static int getAST16() {
return AST.JLS16;
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java
new file mode 100644
index 0000000..01e7575
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Copyright (c) 2021 IBM Corporation 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
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.dom;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+import junit.framework.Test;
+
+@SuppressWarnings("rawtypes")
+public class ASTConverter_17Test extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(getAST17(), false);
+ this.currentProject = getJavaProject("Converter_17");
+ if (this.ast.apiLevel() == AST.JLS17 ) {
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
+
+ }
+ }
+
+ public ASTConverter_17Test(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverter_17Test.class);
+ }
+
+ static int getAST17() {
+ return AST.JLS17;
+ }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+
+
+ public void testSealed001() throws CoreException {
+ if (!isJRE17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return;
+ }
+ String contents = "public sealed class X permits X1{\n" +
+ "\n" +
+ "}\n" +
+ "non-sealed class X1 extends X {\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = ((AbstractTypeDeclaration)compilationUnit.types().get(0));
+ assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration type = (TypeDeclaration)node;
+ List modifiers = type.modifiers();
+ assertEquals("Incorrect no of modifiers", 2, modifiers.size());
+ Modifier modifier = (Modifier) modifiers.get(1);
+ assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
+ List permittedTypes = type.permittedTypes();
+ assertEquals("Incorrect no of permits", 1, permittedTypes.size());
+ assertEquals("Incorrect type of permit", "org.eclipse.jdt.core.dom.SimpleType", permittedTypes.get(0).getClass().getName());
+ node = ((AbstractTypeDeclaration)compilationUnit.types().get(1));
+ assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ type = (TypeDeclaration)node;
+ modifiers = type.modifiers();
+ assertEquals("Incorrect no of modfiers", 1, modifiers.size());
+ modifier = (Modifier) modifiers.get(0);
+ assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.NON_SEALED_KEYWORD, modifier.getKeyword());
+
+ }
+
+ public void testSealed002() throws CoreException {
+ if (!isJRE17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return;
+ }
+ String contents = "public sealed interface X permits X1{\n" +
+ "\n" +
+ "}\n" +
+ "non-sealed interface X1 extends X {\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = ((AbstractTypeDeclaration)compilationUnit.types().get(0));
+ assertEquals("Not a Record Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration type = (TypeDeclaration)node;
+ List modifiers = type.modifiers();
+ assertEquals("Incorrect no of modfiers", 2, modifiers.size());
+ Modifier modifier = (Modifier) modifiers.get(1);
+ assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
+
+ }
+
+ public void testSealed003() throws CoreException {
+ if (!isJRE17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return;
+ }
+ String contents = "public sealed interface X permits X1{\n" +
+ "\n" +
+ "}\n" +
+ "non-sealed interface X1 extends X {\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ List<AbstractTypeDeclaration> types = compilationUnit.types();
+ assertEquals("No. of Types is not 2", types.size(), 2);
+ AbstractTypeDeclaration type = types.get(0);
+ if (!type.getName().getIdentifier().equals("X")) {
+ type = types.get(1);
+ }
+ assertTrue("type not a type", type instanceof TypeDeclaration);
+ TypeDeclaration typeDecl = (TypeDeclaration)type;
+ assertTrue("type not an interface", typeDecl.isInterface());
+ List modifiers = type.modifiers();
+ assertEquals("Incorrect no of modifiers", 2, modifiers.size());
+ Modifier modifier = (Modifier) modifiers.get(1);
+ assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
+ int startPos = modifier.getStartPosition();
+ assertEquals("Restricter identifier position for sealed is not 7", startPos, contents.indexOf("sealed"));
+ startPos = typeDecl.getRestrictedIdentifierStartPosition();
+ assertEquals("Restricter identifier position for permits is not 26", startPos, contents.indexOf("permits"));
+ }
+
+ public void _testSealed004() throws CoreException {
+ if (!isJRE17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return;
+ }
+ String contents = "public sealed class X permits X1{\n" +
+ "\n" +
+ "}\n" +
+ "non-sealed class X1 extends X {\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ List<AbstractTypeDeclaration> types = compilationUnit.types();
+ assertEquals("No. of Types is not 2", types.size(), 2);
+ AbstractTypeDeclaration type = types.get(0);
+ if (!type.getName().getIdentifier().equals("X")) {
+ type = types.get(1);
+ }
+ assertTrue("type not a type", type instanceof TypeDeclaration);
+ TypeDeclaration typeDecl = (TypeDeclaration)type;
+ assertTrue("type not an class", !typeDecl.isInterface());
+ List modifiers = type.modifiers();
+ assertEquals("Incorrect no of modifiers", 2, modifiers.size());
+ Modifier modifier = (Modifier) modifiers.get(1);
+ assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
+ int startPos = modifier.getStartPosition();
+ assertEquals("Restricter identifier position for sealed is not 7", startPos, contents.indexOf("sealed"));
+ startPos = typeDecl.getRestrictedIdentifierStartPosition();
+ assertEquals("Restricter identifier position for permits is not 26", startPos, contents.indexOf("permits"));
+ }
+
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_PreviewTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_PreviewTest.java
index 49e7c10..e55ee24 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_PreviewTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_PreviewTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 IBM Corporation and others.
+ * Copyright (c) 2020, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,39 +8,53 @@
*
* 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
*******************************************************************************/
package org.eclipse.jdt.core.tests.dom;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.GuardedPattern;
+import org.eclipse.jdt.core.dom.ParenthesizedExpression;
+import org.eclipse.jdt.core.dom.Pattern;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.SwitchCase;
+import org.eclipse.jdt.core.dom.SwitchStatement;
+import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypePattern;
import junit.framework.Test;
-@SuppressWarnings("rawtypes")
public class ASTConverter_PreviewTest extends ConverterTestSetup {
ICompilationUnit workingCopy;
public void setUpSuite() throws Exception {
super.setUpSuite();
- this.ast = AST.newAST(getAST16(), false);
- this.currentProject = getJavaProject("Converter_16");
- if (this.ast.apiLevel() == AST.JLS16 ) {
- this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_16);
- this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16);
- this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16);
+ this.ast = AST.newAST(getASTLatest(), false);
+ this.currentProject = getJavaProject("Converter_17");
+ if (this.ast.apiLevel() == AST.JLS17) {
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
+ this.currentProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ this.currentProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
}
}
@@ -53,8 +67,8 @@
return buildModelTestSuite(ASTConverter_PreviewTest.class);
}
- static int getAST16() {
- return AST.JLS16;
+ static int getASTLatest() {
+ return AST.JLS17;
}
protected void tearDown() throws Exception {
super.tearDown();
@@ -64,175 +78,272 @@
}
}
- public void testSealed001() throws CoreException {
- if (!isJRE16) {
- System.err.println("Test "+getName()+" requires a JRE 16");
- return;
- }
- String contents = "public sealed class X permits X1{\n" +
- "\n" +
- "}\n" +
- "non-sealed class X1 extends X {\n" +
- "\n" +
- "}\n";
- this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
- IJavaProject javaProject = this.workingCopy.getJavaProject();
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- ASTNode node = buildAST(
- contents,
- this.workingCopy);
- assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
- CompilationUnit compilationUnit = (CompilationUnit) node;
- assertProblemsSize(compilationUnit, 0);
- node = ((AbstractTypeDeclaration)compilationUnit.types().get(0));
- assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
- TypeDeclaration type = (TypeDeclaration)node;
- List modifiers = type.modifiers();
- assertEquals("Incorrect no of modifiers", 2, modifiers.size());
- Modifier modifier = (Modifier) modifiers.get(1);
- assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
- List permittedTypes = type.permittedTypes();
- assertEquals("Incorrect no of permits", 1, permittedTypes.size());
- assertEquals("Incorrect type of permit", "org.eclipse.jdt.core.dom.SimpleType", permittedTypes.get(0).getClass().getName());
- node = ((AbstractTypeDeclaration)compilationUnit.types().get(1));
- assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
- type = (TypeDeclaration)node;
- modifiers = type.modifiers();
- assertEquals("Incorrect no of modfiers", 1, modifiers.size());
- modifier = (Modifier) modifiers.get(0);
- assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.NON_SEALED_KEYWORD, modifier.getKeyword());
-
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
+ private void printJREError() {
+ System.err.println("Test "+getName()+" requires a JRE 17");
}
- public void testSealed002() throws CoreException {
- if (!isJRE16) {
- System.err.println("Test "+getName()+" requires a JRE 16");
+ @SuppressWarnings("rawtypes")
+ public void testTypePattern() throws CoreException {
+ if (!isJRE17) {
+ printJREError();
return;
}
- String contents = "public sealed interface X permits X1{\n" +
- "\n" +
- "}\n" +
- "non-sealed interface X1 extends X {\n" +
+ String contents = "public class X {\n" +
+ "void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(i.toString());\n" +
+ " case String s -> System.out.println(s);\n" +
+ " default -> System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n" +
"\n" +
"}\n";
- this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
- IJavaProject javaProject = this.workingCopy.getJavaProject();
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- ASTNode node = buildAST(
- contents,
- this.workingCopy);
- assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
- CompilationUnit compilationUnit = (CompilationUnit) node;
- assertProblemsSize(compilationUnit, 0);
- node = ((AbstractTypeDeclaration)compilationUnit.types().get(0));
- assertEquals("Not a Record Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
- TypeDeclaration type = (TypeDeclaration)node;
- List modifiers = type.modifiers();
- assertEquals("Incorrect no of modfiers", 2, modifiers.size());
- Modifier modifier = (Modifier) modifiers.get(1);
- assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ List statements = ((SwitchStatement)node).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ SwitchCase caseInteger = (SwitchCase) statements.get(0);
+ Expression typePattern = (Expression)caseInteger.expressions().get(0);
+ assertEquals("Type Pattern", typePattern.getNodeType(), ASTNode.TYPE_PATTERN);
+ SingleVariableDeclaration patternVariable = ((TypePattern)typePattern).getPatternVariable();
+ assertEquals("Type Pattern Integer", "Integer", patternVariable.getType().toString());
+ SingleVariableDeclaration patternVariable2 = ((TypePattern)typePattern).patternVariables().get(0);
+ assertEquals(patternVariable, patternVariable2);
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
+ SwitchCase caseString = (SwitchCase) statements.get(2);
+ typePattern = (Expression)caseString.expressions().get(0);
+ assertEquals("Type Pattern", typePattern.getNodeType(), ASTNode.TYPE_PATTERN);
+ patternVariable = ((TypePattern)typePattern).getPatternVariable();
+ assertEquals("Type Pattern Integer", "String", patternVariable.getType().toString());
+ patternVariable2 = ((TypePattern)typePattern).patternVariables().get(0);
+ assertEquals(patternVariable, patternVariable2);
+
+ SwitchCase caseDefault = (SwitchCase) statements.get(4);
+ assertTrue("Default case", caseDefault.isDefault());
+
}
- public void testSealed003() throws CoreException {
- if (!isJRE16) {
- System.err.println("Test "+getName()+" requires a JRE 16");
+ @SuppressWarnings("rawtypes")
+ public void testGuardedPattern() throws CoreException {
+ if (!isJRE17) {
+ printJREError();
return;
}
- String contents = "public sealed interface X permits X1{\n" +
- "\n" +
- "}\n" +
- "non-sealed interface X1 extends X {\n" +
+ String contents = "public class X {\n" +
+ "void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i && (i.intValue() > 10) -> System.out.println(\"Greater than 10 \");\n" +
+ " case String s && s.equals(\"ff\") -> System.out.println(s);\n" +
+ " default -> System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n" +
"\n" +
"}\n";
- this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
- IJavaProject javaProject = this.workingCopy.getJavaProject();
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- ASTNode node = buildAST(
- contents,
- this.workingCopy);
- assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
- CompilationUnit compilationUnit = (CompilationUnit) node;
- assertProblemsSize(compilationUnit, 0);
- List<AbstractTypeDeclaration> types = compilationUnit.types();
- assertEquals("No. of Types is not 2", types.size(), 2);
- AbstractTypeDeclaration type = types.get(0);
- if (!type.getName().getIdentifier().equals("X")) {
- type = types.get(1);
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ List statements = ((SwitchStatement)node).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ SwitchCase caseInteger = (SwitchCase) statements.get(0);
+ Expression guardedPattern = (Expression)caseInteger.expressions().get(0);
+ assertEquals("Guarded Pattern", guardedPattern.getNodeType(), ASTNode.GUARDED_PATTERN);
+ Pattern pattern = ((GuardedPattern)guardedPattern).getPattern();
+ SingleVariableDeclaration patternVariable = ((TypePattern)pattern).getPatternVariable();
+ assertEquals("Type Pattern Integer", "Integer", patternVariable.getType().toString());
+ SingleVariableDeclaration patternVariable2 = ((TypePattern)pattern).patternVariables().get(0);
+ assertEquals(patternVariable, patternVariable2);
+ Expression expression = ((GuardedPattern)guardedPattern).getExpression();
+ Expression expression2 = ((ParenthesizedExpression)expression).getExpression();
+ assertEquals("Infix expression", "i.intValue() > 10", expression2.toString());
+
+
+ SwitchCase caseString = (SwitchCase) statements.get(2);
+ guardedPattern = (Expression)caseString.expressions().get(0);
+ assertEquals("Guarded Pattern", guardedPattern.getNodeType(), ASTNode.GUARDED_PATTERN);
+ pattern = ((GuardedPattern)guardedPattern).getPattern();
+ patternVariable = ((TypePattern)pattern).getPatternVariable();
+ assertEquals("Type Pattern String", "String", patternVariable.getType().toString());
+ patternVariable2 = ((TypePattern)pattern).patternVariables().get(0);
+ assertEquals(patternVariable, patternVariable2);
+ expression = ((GuardedPattern)guardedPattern).getExpression();
+ assertEquals("Infix expression", "s.equals(\"ff\")",expression.toString());
+
+ SwitchCase caseDefault = (SwitchCase) statements.get(4);
+ assertTrue("Default case", caseDefault.isDefault());
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testParenthesizedExpressionPattern() throws CoreException {
+ if (!isJRE17) {
+ printJREError();
+ return;
+ }
+ String contents = "public class X {\n" +
+ "void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case (Integer i) : System.out.println(i.toString());\n" +
+ " default : System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ List statements = ((SwitchStatement)node).statements();
+ assertEquals("incorrect no of statements", 4, statements.size());
+ SwitchCase caseInteger = (SwitchCase) statements.get(0);
+ Expression parenthesizedExpression = (Expression)caseInteger.expressions().get(0);
+ assertEquals("Parenthesized Expression", parenthesizedExpression.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ Expression targetPattern = ((ParenthesizedExpression)parenthesizedExpression).getExpression();
+ assertEquals("Type Pattern", targetPattern.getNodeType(), ASTNode.TYPE_PATTERN);
+ SingleVariableDeclaration patternVariable = ((TypePattern)targetPattern).getPatternVariable();
+ assertEquals("Type Pattern Integer", "Integer", patternVariable.getType().toString());
+ SingleVariableDeclaration patternVariable2 = ((TypePattern)targetPattern).patternVariables().get(0);
+ assertEquals(patternVariable, patternVariable2);
+
+ SwitchCase caseDefault = (SwitchCase) statements.get(2);
+ assertTrue("Default case", caseDefault.isDefault());
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testNullPattern() throws CoreException {
+ if (!isJRE17) {
+ printJREError();
+ return;
+ }
+ String contents = "public class X {\n" +
+ "void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(i.toString());\n" +
+ " break;\n" +
+ " case null : System.out.println(\"null\");\n" +
+ " default : System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ List statements = ((SwitchStatement)node).statements();
+ assertEquals("incorrect no of statements", 7, statements.size());
+ SwitchCase caseInteger = (SwitchCase) statements.get(3);
+ Expression nullExpression = (Expression)caseInteger.expressions().get(0);
+ assertEquals("Null Expression", nullExpression.getNodeType(), ASTNode.NULL_LITERAL);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testCaseDefaultExpressionPattern() throws CoreException {
+ if (!isJRE17) {
+ printJREError();
+ return;
+ }
+ String contents = "public class X {\n" +
+ "void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(i.toString());\n" +
+ " case default : System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ List statements = ((SwitchStatement)node).statements();
+ assertEquals("incorrect no of statements", 4, statements.size());
+ SwitchCase caseDefault = (SwitchCase) statements.get(2);
+ Expression caseDefaultExpression = (Expression) caseDefault.expressions().get(0);
+ assertEquals("Case Default Expression",caseDefaultExpression.getNodeType() , ASTNode.CASE_DEFAULT_EXPRESSION);
+
+
+ }
+
+ public void testBug575250() throws CoreException {
+ if (!isJRE17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return;
+ }
+ String contents = "public class X {\n" +
+ " static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case (Integer i_1): System.out.println(\"Integer\");\n" +
+ " default: System.out.println(\"Object\");" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter_17/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ List<AbstractTypeDeclaration> types = compilationUnit.types();
+ assertEquals("incorrect types", types.size(), 1);
+ AbstractTypeDeclaration type = types.get(0);
+ assertTrue("should be a type", type instanceof TypeDeclaration);
+ TypeDeclaration typeDecl = (TypeDeclaration)type;
+ final List<TypePattern> result = new ArrayList<>();
+ typeDecl.accept(new ASTVisitor() {
+ public boolean visit(TypePattern n) {
+ result.add(n);
+ return true;
}
- assertTrue("type not a type", type instanceof TypeDeclaration);
- TypeDeclaration typeDecl = (TypeDeclaration)type;
- assertTrue("type not an interface", typeDecl.isInterface());
- List modifiers = type.modifiers();
- assertEquals("Incorrect no of modifiers", 2, modifiers.size());
- Modifier modifier = (Modifier) modifiers.get(1);
- assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
- int startPos = modifier.getStartPosition();
- assertEquals("Restricter identifier position for sealed is not 7", startPos, contents.indexOf("sealed"));
- startPos = typeDecl.getRestrictedIdentifierStartPosition();
- assertEquals("Restricter identifier position for permits is not 26", startPos, contents.indexOf("permits"));
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
+ });
+ assertEquals("incorrect no of patterns", 1, result.size());
+ TypePattern typePattern = result.get(0);
+ assertNotNull("pattern is null", typePattern);
+ int start = contents.indexOf("Integer");
+ int length = "Integer i_1".length();
+ assertEquals("wrong source range", typePattern.getStartPosition(), start);
+ assertEquals("wrong source range", typePattern.getLength(), length);
- public void testSealed004() throws CoreException {
- if (!isJRE16) {
- System.err.println("Test "+getName()+" requires a JRE 16");
- return;
- }
- String contents = "public sealed class X permits X1{\n" +
- "\n" +
- "}\n" +
- "non-sealed class X1 extends X {\n" +
- "\n" +
- "}\n";
- this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
- IJavaProject javaProject = this.workingCopy.getJavaProject();
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- ASTNode node = buildAST(
- contents,
- this.workingCopy);
- assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
- CompilationUnit compilationUnit = (CompilationUnit) node;
- assertProblemsSize(compilationUnit, 0);
- List<AbstractTypeDeclaration> types = compilationUnit.types();
- assertEquals("No. of Types is not 2", types.size(), 2);
- AbstractTypeDeclaration type = types.get(0);
- if (!type.getName().getIdentifier().equals("X")) {
- type = types.get(1);
- }
- assertTrue("type not a type", type instanceof TypeDeclaration);
- TypeDeclaration typeDecl = (TypeDeclaration)type;
- assertTrue("type not an class", !typeDecl.isInterface());
- List modifiers = type.modifiers();
- assertEquals("Incorrect no of modifiers", 2, modifiers.size());
- Modifier modifier = (Modifier) modifiers.get(1);
- assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.SEALED_KEYWORD, modifier.getKeyword());
- int startPos = modifier.getStartPosition();
- assertEquals("Restricter identifier position for sealed is not 7", startPos, contents.indexOf("sealed"));
- startPos = typeDecl.getRestrictedIdentifierStartPosition();
- assertEquals("Restricter identifier position for permits is not 26", startPos, contents.indexOf("permits"));
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
+ SingleVariableDeclaration patternVariable = typePattern.getPatternVariable();
+ assertEquals("wrong source range", patternVariable.getStartPosition(), start);
+ assertEquals("wrong source range", patternVariable.getLength(), length);
+
+ Type type2 = patternVariable.getType();
+ assertEquals("wrong source range", type2.getStartPosition(), start);
+ assertEquals("wrong source range", type2.getLength(), "Integer".length());
+
+ SimpleName name = patternVariable.getName();
+ start = contents.indexOf("i_1");
+ assertEquals("wrong source range", name.getStartPosition(), start);
+ assertEquals("wrong source range", name.getLength(), "i_1".length());
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
index 1136e84..606a9b5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2019 IBM Corporation and others.
+ * Copyright (c) 2004, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -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
* Technical University Berlin - adapted for Object Teams
@@ -447,9 +451,9 @@
}
// {ObjectTeams: adapted for OT specific ASTNodes
/* orig:
- assertEquals("Wrong last known type", 105, hi); // last known one
+ assertEquals("Wrong last known type", 109, hi); // last known one
:giro */
- assertEquals("Wrong last known type", 121, hi); // last known one
+ assertEquals("Wrong last known type", 125, hi); // last known one
// jwl}
assertEquals("Wrong number of distinct types", hi, classes.size()); // all classes are distinct
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java
index 9048872..eedea28 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.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
* Technical University Berlin - adapted for Object Teams
@@ -9502,6 +9506,10 @@
ASTNode.RECORD_DECLARATION,
ASTNode.PATTERN_INSTANCEOF_EXPRESSION,
ASTNode.MODULE_QUALIFIED_NAME,
+ ASTNode.TYPE_PATTERN,
+ ASTNode.GUARDED_PATTERN,
+ ASTNode.NULL_PATTERN,
+ ASTNode.CASE_DEFAULT_EXPRESSION,
//{ObjectTeams:
ASTNode.METHOD_SPEC,
ASTNode.CALLIN_MAPPING_DECLARATION,
@@ -9571,7 +9579,7 @@
@SuppressWarnings("deprecation")
public void testASTLevels() throws Exception {
- int[] apilLevels = {AST.JLS2, AST.JLS3, AST.JLS4, AST.JLS8, AST.JLS9, AST.JLS10, AST.JLS11, AST.JLS12, AST.JLS13, AST.JLS14, AST.JLS15, AST.JLS16};
+ int[] apilLevels = {AST.JLS2, AST.JLS3, AST.JLS4, AST.JLS8, AST.JLS9, AST.JLS10, AST.JLS11, AST.JLS12, AST.JLS13, AST.JLS14, AST.JLS15, AST.JLS16, AST.JLS17};
for (int level : apilLevels) {
try {
DOMASTUtil.checkASTLevel(level);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java
index a08d511..44107f7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java
@@ -493,7 +493,9 @@
String option = cu.getJavaProject().getOption(JavaCore.COMPILER_COMPLIANCE, true);
long jdkLevel = CompilerOptions.versionToJdkLevel(option);
int JLSLevel = AST_INTERNAL_JLS3;
- if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16)) {
+ if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17)) {
+ JLSLevel = AST_INTERNAL_JLS17;
+ } else if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16)) {
JLSLevel = AST_INTERNAL_JLS16;
} else if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_15)) {
JLSLevel = AST_INTERNAL_JLS15;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
index 6b44610..4b631c17 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
@@ -7,7 +7,9 @@
* 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
*******************************************************************************/
@@ -108,6 +110,10 @@
this.deleteProject("Converter11"); //$NON-NLS-1$
this.deleteProject("Converter13"); //$NON-NLS-1$
this.deleteProject("Converter14"); //$NON-NLS-1$
+ this.deleteProject("Converter_15"); //$NON-NLS-1$
+ this.deleteProject("Converter_15_1"); //$NON-NLS-1$
+ this.deleteProject("Converter_16"); //$NON-NLS-1$
+ this.deleteProject("Converter_17"); //$NON-NLS-1$
PROJECT_SETUP = false;
} else {
TEST_SUITES.remove(getClass());
@@ -122,6 +128,10 @@
this.deleteProject("Converter11"); //$NON-NLS-1$
this.deleteProject("Converter13"); //$NON-NLS-1$
this.deleteProject("Converter14"); //$NON-NLS-1$
+ this.deleteProject("Converter_15"); //$NON-NLS-1$
+ this.deleteProject("Converter_15_1"); //$NON-NLS-1$
+ this.deleteProject("Converter_16"); //$NON-NLS-1$
+ this.deleteProject("Converter_17"); //$NON-NLS-1$
PROJECT_SETUP = false;
}
}
@@ -208,6 +218,14 @@
new IPath[] {getConverterJCLPath("14"), getConverterJCLSourcePath("14"), getConverterJCLRootSourcePath()},
null);
}
+ } else if ("17".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("CONVERTER_JCL_17_LIB") == null) {
+ setupExternalJCL("converterJclMin17");
+ JavaCore.setClasspathVariables(
+ new String[] {"CONVERTER_JCL_17_LIB", "CONVERTER_JCL_17_SRC", "CONVERTER_JCL_17_SRCROOT"},
+ new IPath[] {getConverterJCLPath("17"), getConverterJCLSourcePath("17"), getConverterJCLRootSourcePath()},
+ null);
+ }
} else if (JavaCore.getClasspathVariable("CONVERTER_JCL_LIB") == null) {
setupExternalJCL("converterJclMin");
JavaCore.setClasspathVariables(
@@ -238,6 +256,7 @@
setUpJavaProject("Converter_15", "15"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter_15_1", "15"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter_16", "16"); //$NON-NLS-1$ //$NON-NLS-2$
+ setUpJavaProject("Converter_17", "17"); //$NON-NLS-1$ //$NON-NLS-2$
waitUntilIndexesReady(); // needed to find secondary types
PROJECT_SETUP = true;
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java
index c428626..491c776 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java
@@ -8,6 +8,9 @@
*
* 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
*******************************************************************************/
@@ -57,6 +60,7 @@
ASTConverter14Test.class,
ASTConverter_15Test.class,
ASTConverter_16Test.class,
+ ASTConverter_PreviewTest.class,
};
}
public static Test suite() {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index ba82e20..0973f7d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15941,4 +15941,48 @@
"}\n"
);
}
+
+/**
+ * https://bugs.eclipse.org/573949 - [17][switch pattern][formatter] JEP 406 changes
+ */
+public void testBug573949() {
+ setComplianceLevel(CompilerOptions.VERSION_17);
+ String source =
+ "public class X {\n" +
+ " private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n" +
+ " default : System.out.println(\"Object\");\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ "static void testTriangle(Shape s) {\n" +
+ " switch (s) {\n" +
+ " case Triangle t&&(t.calculateArea() > 100) ->\n" +
+ " System.out.println(\"Large triangle\");\n" +
+ " default ->\n" +
+ " System.out.println(\"A shape, possibly a small triangle\");\n" +
+ " }\n" +
+ "}\n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ " private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer t, String:\n" +
+ " System.out.println(\"Error should be flagged for Integer and String\");\n" +
+ " default:\n" +
+ " System.out.println(\"Object\");\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " static void testTriangle(Shape s) {\n" +
+ " switch (s) {\n" +
+ " case Triangle t && (t.calculateArea() > 100) -> System.out.println(\"Large triangle\");\n" +
+ " default -> System.out.println(\"A shape, possibly a small triangle\");\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ );
+}
}
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 04a09d1..1686ebc 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
@@ -1,11 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation 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/
*
+ * 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.
+ *
* SPDX-License-Identifier: EPL-2.0
* Contributors:
* IBM Corporation - initial API and implementation
@@ -157,6 +161,7 @@
protected static boolean isJRE14 = false;
protected static boolean isJRE15 = false;
protected static boolean isJRE16 = false;
+ protected static boolean isJRE17 = false;
static {
String javaVersion = System.getProperty("java.version");
String vmName = System.getProperty("java.vm.name");
@@ -169,6 +174,9 @@
}
}
long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion.length() > 3 ? javaVersion.substring(0, 3) : javaVersion);
+ if (jdkLevel >= ClassFileConstants.JDK17) {
+ isJRE17 = true;
+ }
if (jdkLevel >= ClassFileConstants.JDK16) {
isJRE16 = true;
}
@@ -244,10 +252,16 @@
/**
* Internal synonym for constant AST.JSL16
* to alleviate deprecation warnings once AST.JLS16 is deprecated in future.
+ * @deprecated
*/
protected static final int AST_INTERNAL_JLS16 = AST.JLS16;
/**
+ * Internal synonym for constant AST.JSL17
+ */
+ protected static final int AST_INTERNAL_JLS17 = AST.JLS17;
+
+ /**
* Internal synonym for the latest AST level.
*
*/
@@ -2249,6 +2263,12 @@
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
javaProject.setOptions(options);
+ } else if ("17".equals(compliance)) {
+ Map options = new HashMap();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17);
+ javaProject.setOptions(options);
}
result[0] = javaProject;
@@ -3390,7 +3410,11 @@
newJclSrcString = "JCL18_SRC"; // Use the same source
}
} else {
- if (compliance.equals("16")) {
+ if (compliance.equals("17")) {
+ // Reuse the same 14 stuff as of now. No real need for a new one
+ newJclLibString = "JCL_17_LIB";
+ newJclSrcString = "JCL_17_SRC";
+ } else if (compliance.equals("16")) {
// Reuse the same 14 stuff as of now. No real need for a new one
newJclLibString = "JCL14_LIB";
newJclSrcString = "JCL14_SRC";
@@ -3467,11 +3491,12 @@
IPath jcl12Lib = new Path("JCL12_LIB");
IPath jcl13Lib = new Path("JCL13_LIB");
IPath jcl14Lib = new Path("JCL14_LIB");
+ IPath jcl17Lib = new Path("JCL_17_LIB");
IPath jclFull = new Path("JCL18_FULL");
return path.equals(jclLib) || path.equals(jcl5Lib) || path.equals(jcl8Lib) || path.equals(jcl9Lib)
|| path.equals(jcl10Lib) || path.equals(jcl11Lib) || path.equals(jcl12Lib) || path.equals(jcl13Lib)
- || path.equals(jcl14Lib) || path.equals(jclFull);
+ || path.equals(jcl14Lib) || path.equals(jcl17Lib) || path.equals(jclFull);
}
public void setUpJCLClasspathVariables(String compliance) throws JavaModelException, IOException {
setUpJCLClasspathVariables(compliance, false);
@@ -3574,6 +3599,14 @@
new IPath[] {getExternalJCLPath("14"), getExternalJCLSourcePath("14"), getExternalJCLRootSourcePath()},
null);
}
+ } else if ("17".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("JCL_17_LIB") == null) {
+ setupExternalJCL("jclMin17");
+ JavaCore.setClasspathVariables(
+ new String[] {"JCL_17_LIB", "JCL_17_SRC", "JCL_SRCROOT"},
+ new IPath[] {getExternalJCLPath("17"), getExternalJCLSourcePath("17"), getExternalJCLRootSourcePath()},
+ null);
+ }
} else {
if (JavaCore.getClasspathVariable("JCL_LIB") == null) {
setupExternalJCL("jclMin");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests16_1.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests16_1.java
index 0e3eca7..8c509b1 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests16_1.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests16_1.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 IBM Corporation and others.
+ * Copyright (c) 2020, 2021 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
@@ -31,11 +31,11 @@
public void setUpSuite() throws Exception {
if (COMPLETION_PROJECT == null) {
- COMPLETION_PROJECT = setUpJavaProject("Completion", "16");
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "17");
} else {
- setUpProjectCompliance(COMPLETION_PROJECT, "16");
+ setUpProjectCompliance(COMPLETION_PROJECT, "17");
}
- COMPLETION_PROJECT.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ COMPLETION_PROJECT.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.DISABLED);
super.setUpSuite();
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java
new file mode 100644
index 0000000..33826b5
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java
@@ -0,0 +1,661 @@
+/*******************************************************************************
+ * Copyright (c) 2021 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
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+import junit.framework.Test;
+
+public class CompletionTests17 extends AbstractJavaModelCompletionTests {
+
+ private static int expected_Rel = R_DEFAULT+R_RESOLVED+ R_CASE+ R_INTERESTING+R_EXACT_EXPECTED_TYPE+R_NON_STATIC+R_NON_RESTRICTED;
+ private static int void_Rel = R_DEFAULT+R_RESOLVED+ R_CASE+ R_INTERESTING+ R_VOID +R_NON_STATIC+R_NON_RESTRICTED;
+ private static int nonVoid_Rel = R_DEFAULT+R_RESOLVED+ R_CASE+ R_INTERESTING +R_NON_STATIC+R_NON_RESTRICTED;
+ private static int unqualified_Rel = R_DEFAULT+R_RESOLVED+ R_CASE+ R_INTERESTING +R_UNQUALIFIED+R_NON_RESTRICTED;
+ private static int unqualifiedExact_Rel = R_DEFAULT+R_RESOLVED+R_EXACT_EXPECTED_TYPE+ R_CASE+ R_INTERESTING +R_UNQUALIFIED+R_NON_RESTRICTED;
+ private static int keyword_Rel= R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED;
+ static {
+ // TESTS_NAMES = new String[]{"test034"};
+ }
+
+ public CompletionTests17(String name) {
+ super(name);
+ }
+
+ public void setUpSuite() throws Exception {
+ if (COMPLETION_PROJECT == null) {
+
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "17");
+ } else {
+ setUpProjectCompliance(COMPLETION_PROJECT, "17");
+ }
+ super.setUpSuite();
+ COMPLETION_PROJECT.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(CompletionTests17.class);
+ }
+ //content assist of a java lang class in case statement in switch pattern
+ public void test001() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String /*here*/s -> System.out.println(\"String:\" + s.);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "s.";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+void_Rel+"}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+void_Rel+"}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+void_Rel+"}\n"
+ + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+nonVoid_Rel+"}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+nonVoid_Rel+"}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, "+nonVoid_Rel+"}\n"
+ + "codePointAt[METHOD_REF]{codePointAt(), Ljava.lang.String;, (I)I, codePointAt, (index), "+expected_Rel+"}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+expected_Rel+"}\n"
+ + "length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+expected_Rel+"}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+expected_Rel+"}",
+ requestor.getResults());
+
+ }
+
+ //content assist of a local variable in case statement in switch pattern
+ public void test002() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static int field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + /*here*/fie);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/fie";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("field[FIELD_REF]{field, LX;, I, field, null, "+unqualifiedExact_Rel+"}",
+ requestor.getResults());
+
+ }
+
+ //content assist of a field in guarded expression in switch pattern
+ public void test003() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static int field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s && /*here*/fie -> System.out.println(\"String:\" + s );\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/fie";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("field[FIELD_REF]{field, LX;, I, field, null, "+unqualified_Rel+"}",
+ requestor.getResults());
+
+ }
+ //content assist of a primitive local in switch pattern's case statement
+ public void test004() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " int local=0;" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + /*here*/loc);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/loc";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("local[LOCAL_VARIABLE_REF]{local, null, I, local, null, "+unqualifiedExact_Rel+"}",
+ requestor.getResults());
+
+
+
+ }
+
+ //content assist of a primitive local in switch pattern's guarded expression
+ public void test005() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " int local=0;" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s && /*here*/loc -> System.out.println(\"String:\" + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/loc";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("local[LOCAL_VARIABLE_REF]{local, null, I, local, null, "+unqualified_Rel+"}",
+ requestor.getResults());
+
+ }
+
+ //content assist of a class field in switch pattern's guarded expression
+ public void test006() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static String field = new String();\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s && /*here*/field. -> System.out.println(\"String:\" + s );\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/field.";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+nonVoid_Rel+"}\n"
+ + "codePointAt[METHOD_REF]{codePointAt(), Ljava.lang.String;, (I)I, codePointAt, (index), "+nonVoid_Rel+"}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+nonVoid_Rel+"}\n"
+ + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+nonVoid_Rel+"}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, "+nonVoid_Rel+"}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+nonVoid_Rel+"}\n"
+ + "length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+nonVoid_Rel+"}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+nonVoid_Rel+"}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+nonVoid_Rel+"}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+nonVoid_Rel+"}",
+ requestor.getResults());
+
+ }
+ //content assist of a custom class in switch pattern's guarded expression ( switch statement)
+ public void test007() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "sealed interface I permits AClass, B {}\n" +
+ "final class AClass implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case *here*ACla : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "*here*ACla";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("AClass[TYPE_REF]{AClass, , LAClass;, null, null, "+unqualified_Rel+"}",
+ requestor.getResults());
+
+ }
+
+ //content assist of a custom class's methods in switch pattern's guarded expression ( switch statement)
+ public void test008() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "sealed interface I permits AClass, B {}\n" +
+ "final class AClass implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case AClass a && a. : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "a.";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+nonVoid_Rel+"}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+nonVoid_Rel+"}\n"
+ + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+nonVoid_Rel+"}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, "+nonVoid_Rel+"}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+nonVoid_Rel+"}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+nonVoid_Rel+"}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+nonVoid_Rel+"}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+nonVoid_Rel+"}",
+ requestor.getResults());
+
+ }
+ //content assist of a java lang class in switch pattern's case statement ( switch statement)
+ public void test009() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(\"Integer:\" + i);break;\n" +
+ " case String /*here*/s : System.out.println(\"String:\" + s.);break;\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "s.";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+void_Rel+"}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+void_Rel+"}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+void_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+void_Rel+"}\n"
+ + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+nonVoid_Rel+"}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+nonVoid_Rel+"}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, "+nonVoid_Rel+"}\n"
+ + "codePointAt[METHOD_REF]{codePointAt(), Ljava.lang.String;, (I)I, codePointAt, (index), "+expected_Rel+"}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+expected_Rel+"}\n"
+ + "length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+expected_Rel+"}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+expected_Rel+"}",
+ requestor.getResults());
+
+ }
+
+ //content assist of a java lang class in switch pattern's guarded expression ( switch statement)
+ public void test010() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(\"Integer:\" + i);break;\n" +
+ " case String /*here*/s && s. : System.out.println(\"String:\" + s);break;\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "s.";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+nonVoid_Rel+"}\n"
+ + "codePointAt[METHOD_REF]{codePointAt(), Ljava.lang.String;, (I)I, codePointAt, (index), "+nonVoid_Rel+"}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+nonVoid_Rel+"}\n"
+ + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+nonVoid_Rel+"}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, "+nonVoid_Rel+"}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+nonVoid_Rel+"}\n"
+ + "length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+nonVoid_Rel+"}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+nonVoid_Rel+"}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+nonVoid_Rel+"}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+nonVoid_Rel+"}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+nonVoid_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test011() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case : System.out.println(\"Integer:\" + i);break;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case ";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("default[KEYWORD]{default, null, null, default, null, "+keyword_Rel+"}\n"
+ + "null[KEYWORD]{null, null, null, null, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test012() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case nu : System.out.println(\"Integer:\" + i);break;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case nu";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("null[KEYWORD]{null, null, null, null, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test013() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case de : System.out.println(\"Integer:\" + i);break;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case de";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("default[KEYWORD]{default, null, null, default, null, "+keyword_Rel+"}",
+ 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 main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case null : System.out.println(\"Integer:\" + i);break;\n" +
+ " /*here*/case nu : System.out.println(\"Integer:\" + i);break;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/case nu";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("",
+ requestor.getResults());
+
+ }
+ public void test015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case default : System.out.println(\"Integer:\" + i);break;\n" +
+ " /*here*/case de : System.out.println(\"Integer:\" + i);break;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/case de";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("",
+ requestor.getResults());
+
+ }
+ public void test016() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case nu -> System.out.println(\"Integer:\" + i);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case nu";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("null[KEYWORD]{null, null, null, null, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test017() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case de -> System.out.println(\"Integer:\" + i);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case de";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("default[KEYWORD]{default, null, null, default, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test018() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" +i);\n" +
+ " case de -> System.out.println(\"Integer:\" + i);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case de";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("default[KEYWORD]{default, null, null, default, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+ public void test019() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" +i);\n" +
+ " case n -> System.out.println(\"Integer:\" + i);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case n";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("null[KEYWORD]{null, null, null, null, null, "+keyword_Rel+"}",
+ requestor.getResults());
+
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs17Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs17Tests.java
new file mode 100644
index 0000000..10a438f
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs17Tests.java
@@ -0,0 +1,1526 @@
+/*******************************************************************************
+ * Copyright (c) 2021 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
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.ReferenceMatch;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.SearchMatch;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.core.search.TypeReferenceMatch;
+import org.eclipse.jdt.internal.core.LocalVariable;
+import org.eclipse.jdt.internal.core.SourceField;
+
+import junit.framework.Test;
+
+public class JavaSearchBugs17Tests extends AbstractJavaSearchTests {
+
+ static {
+ // org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
+ // TESTS_NUMBERS = new int[] { 19 };
+ // TESTS_RANGE = new int[] { 1, -1 };
+ // TESTS_NAMES = new String[] {"testBug542559_001"};
+ }
+
+ public JavaSearchBugs17Tests(String name) {
+ super(name);
+ this.endChar = "";
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(JavaSearchBugs17Tests.class, BYTECODE_DECLARATION_ORDER);
+ }
+
+ class TestCollector extends JavaSearchResultCollector {
+ public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
+ super.acceptSearchMatch(searchMatch);
+ }
+ }
+
+ class ReferenceCollector extends JavaSearchResultCollector {
+ protected void writeLine() throws CoreException {
+ super.writeLine();
+ ReferenceMatch refMatch = (ReferenceMatch) this.match;
+ IJavaElement localElement = refMatch.getLocalElement();
+ if (localElement != null) {
+ this.line.append("+[");
+ if (localElement.getElementType() == IJavaElement.ANNOTATION) {
+ this.line.append('@');
+ this.line.append(localElement.getElementName());
+ this.line.append(" on ");
+ this.line.append(localElement.getParent().getElementName());
+ } else {
+ this.line.append(localElement.getElementName());
+ }
+ this.line.append(']');
+ }
+ }
+ }
+
+ class TypeReferenceCollector extends ReferenceCollector {
+ protected void writeLine() throws CoreException {
+ super.writeLine();
+ TypeReferenceMatch typeRefMatch = (TypeReferenceMatch) this.match;
+ IJavaElement[] others = typeRefMatch.getOtherElements();
+ int length = others == null ? 0 : others.length;
+ if (length > 0) {
+ this.line.append("+[");
+ for (int i = 0; i < length; i++) {
+ IJavaElement other = others[i];
+ if (i > 0)
+ this.line.append(',');
+ if (other.getElementType() == IJavaElement.ANNOTATION) {
+ this.line.append('@');
+ this.line.append(other.getElementName());
+ this.line.append(" on ");
+ this.line.append(other.getParent().getElementName());
+ } else {
+ this.line.append(other.getElementName());
+ }
+ }
+ this.line.append(']');
+ }
+ }
+ }
+
+ protected IJavaProject setUpJavaProject(final String projectName, String compliance, boolean useFullJCL)
+ throws CoreException, IOException {
+ // copy files in project from source workspace to target workspace
+ IJavaProject setUpJavaProject = super.setUpJavaProject(projectName, compliance, useFullJCL);
+ return setUpJavaProject;
+ }
+
+ IJavaSearchScope getJavaSearchScope() {
+ return SearchEngine.createJavaSearchScope(new IJavaProject[] { getJavaProject("JavaSearchBugs") });
+ }
+
+ IJavaSearchScope getJavaSearchScopeBugs(String packageName, boolean addSubpackages) throws JavaModelException {
+ if (packageName == null)
+ return getJavaSearchScope();
+ return getJavaSearchPackageScope("JavaSearchBugs", packageName, addSubpackages);
+ }
+
+ public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException {
+ if (this.wcOwner == null) {
+ this.wcOwner = new WorkingCopyOwner() {
+ };
+ }
+ return getWorkingCopy(path, source, this.wcOwner);
+ }
+
+ @Override
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ JAVA_PROJECT = setUpJavaProject("JavaSearchBugs", "17");
+ }
+
+ public void tearDownSuite() throws Exception {
+ deleteProject("JavaSearchBugs");
+ super.tearDownSuite();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.resultCollector = new TestCollector();
+ this.resultCollector.showAccuracy(true);
+ }
+
+ // switch pattern search - test reference of an object in case statement
+ public void testBug573943_001() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String /*here*/s -> System.out.println(\"String:\" + s + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find reference on a field in switch pattern
+ public void testBug573943_002() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + field);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/field";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ SourceField field = (SourceField) elements[0];
+ search(field, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [field] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all occurrence of a field in switch pattern
+ public void testBug573943_003() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + field);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/field";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ SourceField field = (SourceField) elements[0];
+ search(field, ALL_OCCURRENCES, EXACT_RULE);
+ assertSearchResults("src/X.java X.field [field] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [field] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ // find all reference of a local variable in switch pattern
+ public void testBug573943_004() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " int /*here*/local=0" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + local);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/local";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable field = (ILocalVariable) elements[0];
+ search(field, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [local] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all reference of a local variable in switch pattern
+ public void testBug573943_005() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " int /*here*/local=0" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i +local);\n" +
+ " case String s -> System.out.println(\"String:\" + s + local);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/local";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable field = (ILocalVariable) elements[0];
+ search(field, ALL_OCCURRENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object).local [local] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [local] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [local] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all occurrence of a field in switch case statement and switch expression
+ public void testBug573943_006() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i && field > 0 -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + field);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/field";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ SourceField field = (SourceField) elements[0];
+ search(field, ALL_OCCURRENCES, EXACT_RULE);
+ assertSearchResults("src/X.java X.field [field] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [field] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [field] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all reference of a local variable in switch pattern amd case statements
+ public void testBug573943_007() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/field \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " int /*here*/local=0" +
+ " switch (o) {\n" +
+ " case Integer i && local >9 -> System.out.println(\"Integer:\" + i +local);\n" +
+ " case String s -> System.out.println(\"String:\" + s + local);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/local";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable field = (ILocalVariable) elements[0];
+ search(field, ALL_OCCURRENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object).local [local] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [local] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [local] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [local] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an object in case statement as well as switch expression
+ public void testBug573943_008() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String /*here*/s && s.hashCode()>0 -> System.out.println(\"String:\" );\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ // switch pattern search - test reference of an custom class object in case statement
+ public void testBug573943_009() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "final class A implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an custom class object in case statement amd switch statement
+ public void testBug573943_010() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "final class A implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a && a.hashCode()> 0 : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an custom record object in case statement
+ public void testBug573943_011() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "record A (int i) implements S {}\n" +
+ "record B (int i) implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);break;\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an custom record object in case statement and switch statement
+ public void testBug573943_012() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "record A (int i) implements S {}\n" +
+ "record B (int i) implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a && a.hashCode() : System.out.println(\"A:\" + a +a); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an custom class object in case statement and switch expression
+ public void testBug573943_013() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "final class A implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static int foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a && a.hashCode()> 0 -> 1;\n" +
+ " case B b ->2;\n" +
+ " default -> 3;\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java int X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an object in case statement as well as switch pattern
+ public void testBug573943_014() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(\"Integer:\" + i);break;\n" +
+ " case String /*here*/s : System.out.println(\"String:\" + s + s);break;\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ System.out.println(str);
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // switch pattern search - test reference of an object in case statement as well as switch pattern
+ public void testBug573943_015() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i : System.out.println(\"Integer:\" + i);break;\n" +
+ " case String /*here*/s && s.hashCode()>0 : System.out.println(\"String:\" );break;\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // type reference with a switch expression pattern
+ // see testBug573943_012 for switch pattern and type reference
+ public void testBug573943_016() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "final class A implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a -> System.out.println(\"A:\" + a +a); \n" +
+ " case B b -> System.out.println(\"B:\" + b);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ // type reference with a switch expression pattern
+ public void testBug573943_017() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A, B {}\n" +
+ "final class A implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case A /*here*/a && a.toString().length()>2 -> System.out.println(\"A:\" + a +a); \n" +
+ " case B b -> System.out.println(\"B:\" + b);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/a";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ +"src/X.java void X.foo(S) [a] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [a] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // selection of pattern variable in case statement and verify that it is local variable
+ public void testBug573943_018() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + /*here*/s + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements[0] instanceof LocalVariable);
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // selection of pattern variable in case statement and search for declaration
+ public void testBug573943_019() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + /*here*/s + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, DECLARATIONS, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object).s [s] EXACT_MATCH");
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // selection of guarded pattern variable in case statement and verify that it is local variable
+ public void testBug573943_020() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " final int a=0; \n" +
+ " switch (o) {\n" +
+ " case Integer i && a > 5 -> System.out.println(\"Integer:\" + /*here*/i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/i";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements[0] instanceof LocalVariable);
+
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // selection of pattern variable in case statement and search for declaration
+ public void testBug573943_021() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " final int a=0; \n" +
+ " switch (o) {\n" +
+ " case Integer i && a > 5 -> System.out.println(\"Integer:\" + /*here*/i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + s);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/i";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ ILocalVariable local = (ILocalVariable) elements[0];
+ search(local, DECLARATIONS, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object).i [i] EXACT_MATCH");
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ //not a working copy test
+ public void testBug573943_022() throws Exception {
+ try {
+ IJavaProject project = createJavaProject("first", new String[] {"src"}, new String[] {"JCL17_LIB"}, "bin", "17");
+ project.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ project.open(null);
+ createFolder("/first/src/p1");
+ createFile("/first/src/p1/BClass.java",
+ "package p1;\n" +
+ "public class BClass {\n" +
+ "}\n"
+ );
+ createFile("/first/src/p1/X.java",
+ "package p1;\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case BClass i -> System.out.println(\"Integer:\" + i);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ project.close();
+ project.open(null);
+ waitUntilIndexesReady();
+
+ SearchPattern pattern = SearchPattern.createPattern("BClass", IJavaSearchConstants.TYPE, REFERENCES, SearchPattern.R_EXACT_MATCH);
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[]
+ {project});
+ search(pattern, scope, this.resultCollector);
+ assertSearchResults(
+ "src/p1/X.java void p1.X.foo(Object) [BClass] EXACT_MATCH",
+ this.resultCollector);
+ }
+ finally {
+
+ deleteProject("first");
+ }
+ }
+ // find reference on a field in switch pattern - without select
+ public void testBug573943_023() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/fieldj17 \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + fieldj17 +fieldj17);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+
+ search("fieldj17", FIELD, REFERENCES);
+ assertSearchResults("src/X.java void X.foo(Object) [fieldj17] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [fieldj17] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all occurrence on a field in switch pattern - without select
+ public void testBug573943_024() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static int /*here*/fieldj17 \n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s -> System.out.println(\"String:\" + s + fieldj17 +fieldj17);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+
+ search("fieldj17", FIELD, ALL_OCCURRENCES);
+ assertSearchResults("src/X.java X.fieldj17 [fieldj17] EXACT_MATCH\n"+
+ "src/X.java void X.foo(Object) [fieldj17] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [fieldj17] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all occurrence on a class in switch pattern - without select ( switch statement)
+ public void testBug573943_026() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A17, B {}\n" +
+ "final class AJ17 implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case AJ17 /*here*/a : System.out.println(); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ search("AJ17", CLASS, ALL_OCCURRENCES);
+ assertSearchResults("src/X.java AJ17 [AJ17] EXACT_MATCH\n"
+ + "src/X.java void X.foo(S) [AJ17] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all reference on a class in switch pattern - without select ( Switch Statement)
+ public void testBug573943_027() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A17, B {}\n" +
+ "final class AJ17 implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case AJ17 /*here*/a : System.out.println(); break;\n" +
+ " case B b : System.out.println(\"B:\" + b);\n" +
+ " default : System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ search("AJ17", CLASS, REFERENCES);
+ assertSearchResults("src/X.java void X.foo(S) [AJ17] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all reference on a class in switch pattern - without select
+ public void testBug573943_028() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "sealed interface I permits A17, B {}\n" +
+ "final class AJ17 implements S {}\n" +
+ "final class B implements S {}\n" +
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(new A());\n" +
+ "}\n" +
+ "private static void foo(S o) {\n" +
+ " switch (o) {\n" +
+ " case AJ17 /*here*/a -> System.out.println(); \n" +
+ " case B b -> System.out.println(\"B:\" + b);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ search("AJ17", CLASS, REFERENCES);
+ assertSearchResults("src/X.java void X.foo(S) [AJ17] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // find all occurrence on a class in switch pattern - without select
+ public void testBug573943_029() throws Exception {
+ try {
+ IJavaProject project = createJavaProject("first", new String[] {"src"}, new String[] {"JCL17_LIB"}, "bin", "17");
+ project.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ project.open(null);
+ createFolder("/first/src/p1");
+ createFile("/first/src/p1/BClass.java",
+ "package p1;\n" +
+ "public class BClass {\n" +
+ "}\n"
+ );
+ createFile("/first/src/p1/X.java",
+ "package p1;\n" +
+ "public class X {\n" +
+ " public int field_j17; "+
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case BClass i && field_j17>0 -> System.out.println(\"Integer:\" + i);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ project.close();
+ project.open(null);
+ waitUntilIndexesReady();
+
+ SearchPattern pattern = SearchPattern.createPattern("field_j17", IJavaSearchConstants.FIELD, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH);
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[]
+ {project});
+ search(pattern, scope, this.resultCollector);
+ assertSearchResults(
+ "src/p1/X.java p1.X.field_j17 [field_j17] EXACT_MATCH\n"
+ + "src/p1/X.java void p1.X.foo(Object) [field_j17] EXACT_MATCH",
+ this.resultCollector);
+ }
+ finally {
+
+ deleteProject("first");
+ }
+ }
+ // find all references on a class in switch pattern - without select
+ public void testBug573943_030() throws Exception {
+ try {
+ IJavaProject project = createJavaProject("first", new String[] {"src"}, new String[] {"JCL17_LIB"}, "bin", "17");
+ project.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ project.open(null);
+ createFolder("/first/src/p1");
+ createFile("/first/src/p1/BClass.java",
+ "package p1;\n" +
+ "public class BClass {\n" +
+ "}\n"
+ );
+ createFile("/first/src/p1/X.java",
+ "package p1;\n" +
+ "public class X {\n" +
+ " public int field_j17; "+
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case BClass i && field_j17>0 -> System.out.println(\"Integer:\" + i);\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }\n" +
+ "}\n" +
+ "}\n"
+ );
+ project.close();
+ project.open(null);
+ waitUntilIndexesReady();
+
+ SearchPattern pattern = SearchPattern.createPattern("field_j17", IJavaSearchConstants.FIELD, REFERENCES, SearchPattern.R_EXACT_MATCH);
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[]
+ {project});
+ search(pattern, scope, this.resultCollector);
+ assertSearchResults(
+ "src/p1/X.java void p1.X.foo(Object) [field_j17] EXACT_MATCH",
+ this.resultCollector);
+ }
+ finally {
+
+ deleteProject("first");
+ }
+ }
+ public void testBug573943_031() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s && /*here*/s.hashCode()>0 -> System.out.println(\"String:\" );\n" +
+ " default -> System.out.println(\"Object\" + o);\n" +
+ " }}\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements.length ==1);
+ assertTrue(elements[0] instanceof ILocalVariable);
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ public void testBug573943_032() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " String myVar= new String();" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s1 && s1 != myVar && 0 < /*here*/s1.length() -> System.out.println(s1 );\n" +
+ " default -> {\n" +
+ " String s1 = new String();\n" +
+ " System.out.println(s1);\n" +
+ " }}\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s1";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements.length ==1);
+ assertTrue(elements[0] instanceof ILocalVariable);
+ search(elements[0], REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s1] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s1] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s1] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void testBug573943_033() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " String myVar= new String();" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s1 && /*here*/s1 != myVar && 0 < s1.length() -> System.out.println(s1 );\n" +
+ " default -> {\n" +
+ " String s1 = new String();\n" +
+ " System.out.println(s1);\n" +
+ " }}\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s1";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements.length ==1);
+ assertTrue(elements[0] instanceof ILocalVariable);
+ search(elements[0], REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s1] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s1] EXACT_MATCH\n"
+ + "src/X.java void X.foo(Object) [s1] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void testBug573943_034() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static void foo(Object o) {\n" +
+ " String myVar= new String();" +
+ " switch (o) {\n" +
+ " case Integer i -> System.out.println(\"Integer:\" + i);\n" +
+ " case String s1 && s1 != myVar && 0 < s1.length() -> System.out.println(s1 );\n" +
+ " default -> {\n" +
+ " String s1 = new String();\n" +
+ " System.out.println(/*here*/s1);\n" +
+ " }}\n" +
+ "}\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "/*here*/s1";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements.length ==1);
+ assertTrue(elements[0] instanceof ILocalVariable);
+ search(elements[0], REFERENCES, EXACT_RULE);
+ assertSearchResults("src/X.java void X.foo(Object) [s1] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ // selection of guarded pattern variable along with instance of expression in case statement and verify that it is local variable
+ public void testBug575718_035() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case String strGP && (o instanceof String c3 && c3.length() > 0) -> 0;\n" +
+ " default -> 0;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "strGP";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements[0] instanceof LocalVariable);
+
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ // selection of guarded pattern variable in case statement along with instanceof expression and verify it gets all references
+ public void testBug575718_036() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case String strGP && (o instanceof String c3 && c3.length() > 0) && strGP.length() > 0 -> 0;\n" +
+ " default -> 0;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "strGP";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements[0] instanceof LocalVariable);
+ search(elements[0], REFERENCES, EXACT_RULE);
+ assertSearchResults(
+ "src/X.java int X.foo(Object) [strGP] EXACT_MATCH");
+
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ // selection of guarded pattern variable in case statement along with instanceof expression and verify that it gets all occurences
+ public void testBug575718_037() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "public static void main(String[] args) {\n" +
+ "foo(Integer.valueOf(5));\n" +
+ "foo(new Object());\n" +
+ "}\n" +
+ "private static int foo(Object o) {\n" +
+ " return switch (o) {\n" +
+ " case String strGP && (o instanceof String c3 && c3.length() > 0) && strGP.length() > 0 -> 0;\n" +
+ " default -> 0;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCopies[0].getJavaProject(); // assuming single project for all
+ // working copies
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ String str = this.workingCopies[0].getSource();
+ String selection = "strGP";
+ int start = str.indexOf(selection);
+ int length = selection.length();
+
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
+ assertTrue(elements[0] instanceof LocalVariable);
+ search(elements[0], ALL_OCCURRENCES, EXACT_RULE);
+ assertSearchResults(
+ "src/X.java int X.foo(Object).strGP [strGP] EXACT_MATCH\n"
+ + "src/X.java int X.foo(Object) [strGP] EXACT_MATCH");
+
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+
+}
+
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
index 04c4c96..71c53fb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
@@ -6074,13 +6074,13 @@
}
}
public void testBug564613_001() throws CoreException, IOException, InterruptedException {
- if (!isJRE15) return;
+ if (!isJRE17) return;
IJavaProject project15 = null;
try {
project15 = createJava15Project("Reconciler_15", new String[] {"src"});
- project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16);
- project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_16);
- project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16);
+ project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17);
+ project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
+ project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
project15.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
project15.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
index 0ac8382..4e809d5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
@@ -35,7 +35,8 @@
protected ICompilationUnit workingCopy;
protected ProblemRequestor problemRequestor;
- /*package*/ static final int JLS_LATEST = AST.JLS16;
+ /*package*/ @SuppressWarnings("deprecation")
+ static final int JLS_LATEST = AST.JLS16;
/**
*/
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 15f3b1d..7756816 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
@@ -44,6 +44,7 @@
COMPLETION_SUITES.add(CompletionTests14.class);
COMPLETION_SUITES.add(CompletionTests16_1.class);
COMPLETION_SUITES.add(CompletionTests16_2.class);
+ COMPLETION_SUITES.add(CompletionTests17.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.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java
index 131c537..4d71f79 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java
@@ -69,6 +69,7 @@
allClasses.add(JavaSearchBugs13Tests.class);
allClasses.add(JavaSearchBugs15Tests.class);
allClasses.add(JavaSearchBugs16Tests.class);
+ allClasses.add(JavaSearchBugs17Tests.class);
allClasses.add(JavaSearchMultipleProjectsTests.class);
allClasses.add(SearchTests.class);
allClasses.add(JavaSearchScopeTests.class);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SealedTypeModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SealedTypeModelTests.java
index 243c874..a9a9ace 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SealedTypeModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SealedTypeModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 IBM Corporation.
+ * Copyright (c) 2020, 2021 IBM Corporation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -53,11 +53,10 @@
};
}
public static Test suite() {
- return buildModelTestSuite(AbstractCompilerTest.F_15, SealedTypeModelTests.class);
+ return buildModelTestSuite(AbstractCompilerTest.F_17, SealedTypeModelTests.class);
}
protected IJavaProject createJavaProject(String projectName) throws CoreException {
- IJavaProject createJavaProject = super.createJavaProject(projectName, new String[] {"src"}, new String[] {"JCL14_LIB"}, "bin", "15");
- createJavaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ IJavaProject createJavaProject = super.createJavaProject(projectName, new String[] {"src"}, new String[] {"JCL14_LIB"}, "bin", "17");
return createJavaProject;
}
// Check types with neither sealed nor non-sealed don't return those modifiers
@@ -65,8 +64,7 @@
try {
IJavaProject project = createJavaProject("SealedTypes");
project.open(null);
- String fileContent = "@SuppressWarnings(\"preview\")\n" +
- "interface I {}\n" +
+ String fileContent = "interface I {}\n" +
"public class X implements I {}\n" +
"interface Y extends I {}\n";
@@ -178,7 +176,7 @@
String outputDirectory = Util.getOutputDirectory();
String jarPath = outputDirectory + File.separator + "sealed.jar";
- Util.createJar(sources, jarPath, "15", true);
+ Util.createJar(sources, jarPath, "17", true);
IJavaProject project = createJavaProject("SealedTypes");
addClasspathEntry(project, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, null, false));
@@ -239,7 +237,7 @@
String outputDirectory = Util.getOutputDirectory();
String jarPath = outputDirectory + File.separator + "sealed.jar";
- Util.createJar(sources, jarPath, "15", true);
+ Util.createJar(sources, jarPath, "17", true);
IJavaProject project = createJavaProject("SealedTypes");
addClasspathEntry(project, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, null, false));
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
index 0dd523f..80e8adb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
@@ -7,7 +7,9 @@
* 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
*******************************************************************************/
@@ -43,6 +45,7 @@
return createSuite(ASTRewritingInstanceOfPatternExpressionTest.class, 16);
}
+ @SuppressWarnings("deprecation")
@Override
protected void setUp() throws Exception {
super.setUp();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordAnnotationsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordAnnotationsTest.java
index de630b7..b6d8505 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordAnnotationsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordAnnotationsTest.java
@@ -7,6 +7,9 @@
* 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
*******************************************************************************/
@@ -57,6 +60,7 @@
return createSuite(ASTRewritingRecordAnnotationsTest.class, getAST16());
}
+ @SuppressWarnings("deprecation")
protected static int getAST16() {
return AST.JLS16;
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
index d7aa800..926d17f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
@@ -7,7 +7,9 @@
* 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
*******************************************************************************/
@@ -63,6 +65,7 @@
protected void setUp() throws Exception {
super.setUp();
setUpProjectAbove16();
+ setUpProjectAbove17();
}
@SuppressWarnings("deprecation")
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
index eaa5b76..9587c92 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
@@ -7,6 +7,9 @@
* 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
*******************************************************************************/
@@ -53,7 +56,8 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- //super.setUpProjectAbove14();
+ super.setUpProjectAbove14();
+ setUpProjectAbove17();
}
@@ -309,7 +313,9 @@
buf.append(" int z = 100;\n");
buf.append(" yield z;\n");
buf.append(" }\n");
- buf.append(" case 100, 200 -> {yield 2048;}\n");
+ buf.append(" case 100, 200 -> {\n");
+ buf.append(" yield 2048;\n");
+ buf.append("}\n");
buf.append(" default -> {\n");
buf.append(" yield 12;\n");
buf.append(" }\n");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchPatternTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchPatternTest.java
new file mode 100644
index 0000000..5f9cc39
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchPatternTest.java
@@ -0,0 +1,1085 @@
+/*******************************************************************************
+ * Copyright (c) 2021 IBM Corporation 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
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.rewrite.describing;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CaseDefaultExpression;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.GuardedPattern;
+import org.eclipse.jdt.core.dom.InfixExpression;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.NullPattern;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.SwitchCase;
+import org.eclipse.jdt.core.dom.SwitchExpression;
+import org.eclipse.jdt.core.dom.SwitchStatement;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypePattern;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.YieldStatement;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+
+import junit.framework.Test;
+
+@SuppressWarnings({"rawtypes", "deprecation"})
+public class ASTRewritingSwitchPatternTest extends ASTRewritingTest {
+
+
+ public ASTRewritingSwitchPatternTest(String name, int apiLevel) {
+ super(name, apiLevel);
+ }
+
+ public static Test suite() {
+ return createSuite(ASTRewritingSwitchPatternTest.class, 17);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (this.apiLevel == AST.JLS17 ) { // Remove this after it is a standard feature
+ this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
+ this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17);
+ this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
+ this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ }
+ }
+
+ private boolean checkAPILevel() {
+ if (this.apiLevel < 17) {
+ System.err.println("Test "+getName()+" requires a JRE 17");
+ return true;
+ }
+ return false;
+ }
+
+
+ public void testAddTypePattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i -> 1;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // insert type pattern
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)blockStatements.get(0);
+
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)variableDeclarationStatement.fragments().get(0);
+ SwitchExpression switchStatement= (SwitchExpression) variableDeclarationFragment.getInitializer();
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 4", statements.size() == 4);
+
+ SwitchCase caseStatement= ast.newSwitchCase();
+ caseStatement.setSwitchLabeledRule(true);
+ TypePattern typePattern = ast.newTypePattern();
+ SingleVariableDeclaration patternVariable = ast.newSingleVariableDeclaration();
+ patternVariable.setType(ast.newSimpleType(ast.newSimpleName("String")));
+ patternVariable.setName(ast.newSimpleName("s"));
+ typePattern.setPatternVariable(patternVariable);
+ caseStatement.expressions().add(typePattern);
+
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchExpression.STATEMENTS_PROPERTY);
+ listRewrite.insertAt(caseStatement, 2, null);
+
+ YieldStatement yieldStatement = ast.newYieldStatement();
+ yieldStatement.setExpression(ast.newNumberLiteral("2"));
+ listRewrite.insertAt(yieldStatement, 3, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i -> 1;\n");
+ buf.append( " case String s -> yield 2;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void tesModifyTypePattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i -> 1;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // replace type pattern
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)blockStatements.get(0);
+
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)variableDeclarationStatement.fragments().get(0);
+ SwitchExpression switchStatement= (SwitchExpression) variableDeclarationFragment.getInitializer();
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 4", statements.size() == 4);
+
+ SwitchCase caseStatement= (SwitchCase)statements.get(0);
+ TypePattern typePattern = ast.newTypePattern();
+ SingleVariableDeclaration patternVariable = ast.newSingleVariableDeclaration();
+ patternVariable.setType(ast.newSimpleType(ast.newSimpleName("String")));
+ patternVariable.setName(ast.newSimpleName("s"));
+ typePattern.setPatternVariable(patternVariable);
+ rewrite.replace((ASTNode) caseStatement.expressions().get(0), typePattern, null);
+
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case String s -> 1;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testRemoveTypePattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i -> 1;\n");
+ buf.append( " case String s -> 2;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // remove type pattern statement
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)blockStatements.get(0);
+
+
+
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)variableDeclarationStatement.fragments().get(0);
+ SwitchExpression switchStatement= (SwitchExpression) variableDeclarationFragment.getInitializer();
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 6", statements.size() == 6);
+
+ // remove statements
+
+ rewrite.remove((ASTNode) statements.get(2), null);
+ rewrite.remove((ASTNode) statements.get(3), null);
+ }
+
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i -> 1;\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+
+ public void testAddGuardedPattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " switch (o) {\n");
+ buf.append( " default : System.out.println(\"0\");\n");
+ buf.append( " }\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // insert Guarded pattern
+ SwitchStatement switchStatement = (SwitchStatement) blockStatements.get(0);
+
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 2", statements.size() == 2);
+
+ SwitchCase caseStatement= ast.newSwitchCase();
+ caseStatement.setSwitchLabeledRule(false);
+ GuardedPattern guardedPattern = ast.newGuardedPattern();
+ TypePattern typePattern = ast.newTypePattern();
+ SingleVariableDeclaration patternVariable = ast.newSingleVariableDeclaration();
+ patternVariable.setType(ast.newSimpleType(ast.newSimpleName("Integer")));
+ patternVariable.setName(ast.newSimpleName("i"));
+ typePattern.setPatternVariable(patternVariable);
+ guardedPattern.setPattern(typePattern);
+ InfixExpression infixExpression = ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.GREATER);
+ infixExpression.setLeftOperand(ast.newSimpleName("i"));
+ infixExpression.setRightOperand(ast.newNumberLiteral("10"));//$NON-NLS
+ guardedPattern.setExpression(infixExpression);
+ caseStatement.expressions().add(guardedPattern);
+
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
+ listRewrite.insertAt(caseStatement, 0, null);
+
+ MethodInvocation methodInvocation = ast.newMethodInvocation();
+ QualifiedName name =
+ ast.newQualifiedName(
+ ast.newSimpleName("System"),//$NON-NLS-1$
+ ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(ast.newSimpleName("println")); //$NON-NLS-1$
+ StringLiteral stringLiteral = ast.newStringLiteral();
+ stringLiteral.setLiteralValue("Greater than 10");//$NON-NLS-1$
+ methodInvocation.arguments().add(stringLiteral);//$NON-NLS-1$
+ ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
+ listRewrite.insertAt(expressionStatement, 1, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " switch (o) {\n");
+ buf.append( " case Integer i && i > 10:\n");
+ buf.append( " System.out.println(\"Greater than 10\");\n");
+ buf.append( " default : System.out.println(\"0\");\n");
+ buf.append( " }\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testModifyGuardedPattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " switch (o) {\n");
+ buf.append( " case String s && s.equals(\"hi\") : System.out.println(\"hi\");\n");
+ buf.append( " default : System.out.println(\"0\");\n");
+ buf.append( " }\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // replace Guarded pattern
+ SwitchStatement switchStatement = (SwitchStatement) blockStatements.get(0);
+
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 4", statements.size() == 4);
+
+ SwitchCase caseStatement= (SwitchCase)statements.get(0);
+ GuardedPattern guardedPattern = ast.newGuardedPattern();
+ TypePattern typePattern = ast.newTypePattern();
+ SingleVariableDeclaration patternVariable = ast.newSingleVariableDeclaration();
+ patternVariable.setType(ast.newSimpleType(ast.newSimpleName("Integer")));
+ patternVariable.setName(ast.newSimpleName("i"));
+ typePattern.setPatternVariable(patternVariable);
+ guardedPattern.setPattern(typePattern);
+ InfixExpression infixExpression = ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.GREATER);
+ infixExpression.setLeftOperand(ast.newSimpleName("i"));
+ infixExpression.setRightOperand(ast.newNumberLiteral("10"));//$NON-NLS
+ guardedPattern.setExpression(infixExpression);
+ rewrite.replace((ASTNode) caseStatement.expressions().get(0),guardedPattern, null);
+
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " switch (o) {\n");
+ buf.append( " case Integer i && i > 10 : System.out.println(\"hi\");\n");
+ buf.append( " default : System.out.println(\"0\");\n");
+ buf.append( " }\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testRemoveGuardedPattern() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case Integer i && i > 10 : System.out.println(\"hi\");\n");
+ buf.append( " case String s && s.equals(\"hi\") : System.out.println(\"hi\");\n");
+ buf.append( " default -> 0;\n");
+ buf.append( " };\n");
+ buf.append( "}\n");
+ buf.append( "\n");
+ buf.append( "}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(this.apiLevel, cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // remove guarded pattern statement
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)blockStatements.get(0);
+
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)variableDeclarationStatement.fragments().get(0);
+ SwitchExpression switchStatement= (SwitchExpression) variableDeclarationFragment.getInitializer();
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 6", statements.size() == 6);
+
+ // remove statements
+
+ rewrite.remove((ASTNode) statements.get(0), null);
+ rewrite.remove((ASTNode) statements.get(1), null);
+ }
+
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuilder();
+ buf.append("public class X {\n");
+ buf.append( "void foo(Object o) {\n");
+ buf.append( " int i = switch (o) {\n");
+ buf.append( " case String s && s.equals(\"hi\") : System.out.println(\"hi\");\n"