update jdt.core to 07329519f5ac8fd8379eab265d25b2c09a24fd96 (before
whitespace change Bug 560451
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 d87f8fc..c6defbb 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.1100.qualifier
+Bundle-Version: 3.12.1200.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 db6c935..9fbc8a3 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -15,12 +15,12 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.jdt.core</groupId>
- <version>4.15.0-SNAPSHOT</version>
+ <version>4.16.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
- <version>3.12.1100-SNAPSHOT</version>
+ <version>3.12.1200-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
@@ -199,6 +199,36 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-14</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-14</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,14</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 0ef1a5a..44c0c96 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, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -28,7 +28,7 @@
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which does not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "testBug531714" };
+// TESTS_NAMES = new String[] { "test0042" };
// TESTS_NUMBERS = new int[] { 50 };
// TESTS_RANGE = new int[] { 21, 50 };
}
@@ -1964,7 +1964,8 @@
expected15ProblemLog
);
}
-public void test0042() {
+//TODO: Enable after Bug 552769 is fixed
+public void _test0042() {
String[] testFiles = new String[] {
"X.java",
"void ___eval() {\n" +
@@ -2012,9 +2013,11 @@
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Syntax error on tokens, delete these tokens\n" +
"----------\n";
+ @SuppressWarnings("unused")
String expected14ProblemLog =
expected13ProblemLog;
+ @SuppressWarnings("unused")
String expected15ProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
@@ -2059,11 +2062,28 @@
"Syntax error, insert \"EnumBody\" to complete CompilationUnit\n" +
"----------\n";
+ String expected_Java14_ProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " void ___eval() {\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 1)\n" +
+ " void ___eval() {\n" +
+ " ^\n" +
+ "Syntax error on token \")\", { expected after this token\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 23)\n" +
+ " }\n" +
+ " ^\n" +
+ "Syntax error, insert \"}\" to complete RecordBody\n" +
+ "----------\n";
runComplianceParserTest(
testFiles,
- expected13ProblemLog,
- expected14ProblemLog,
- expected15ProblemLog
+ expected_Java14_ProblemLog,
+ expected_Java14_ProblemLog,
+ expected_Java14_ProblemLog
);
}
/*
@@ -2500,15 +2520,10 @@
String expected15ProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 5)\n" +
- " void foo2() {\n" +
- " ^^^^\n" +
- "Syntax error on token \"void\", new expected\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 6)\n" +
- " }\n" +
- " ^\n" +
- "Syntax error, insert \";\" to complete Statement\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " void foo2() {\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
"----------\n";
runComplianceParserTest(
@@ -3576,22 +3591,22 @@
" default -> 3;\n" +
" };\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The preview feature Switch Expressions is only available with source level 13 and above\n" +
+ "Switch Expressions are supported from Java 14 onwards only\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" case 0 -> i * 0;\n" +
" ^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" case 1 -> 2;\n" +
" ^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n" +
"4. ERROR in X.java (at line 6)\n" +
" default -> 3;\n" +
" ^^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n";
runComplianceParserTest(
@@ -3628,17 +3643,17 @@
"1. ERROR in X.java (at line 4)\n" +
" case 0 -> i * 0;\n" +
" ^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" case 1 -> 2;\n" +
" ^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" default -> 3;\n" +
" ^^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
"----------\n";
runComplianceParserTest(
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java
index 1881bc0..7fda33c 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Technical University Berlin - adapted for Object Teams
@@ -685,8 +685,7 @@
" }\n" +
" void foo() {\n" +
" System.out.println();\n" +
- " new baz() {\n" +
- " };\n" +
+ " void baz;\n" +
" }\n" +
" void bar() {\n" +
" }\n" +
@@ -7051,13 +7050,7 @@
" super();\n" +
" }\n" +
" }\n" +
- " new foo2() {\n" +
- " };\n" +
- " class Z<T> {\n" +
- " Z() {\n" +
- " super();\n" +
- " }\n" +
- " }\n" +
+ " void foo2;\n" +
" }\n" +
"}\n";
@@ -7136,13 +7129,7 @@
" super();\n" +
" }\n" +
" }\n" +
- " new foo2() {\n" +
- " };\n" +
- " class Z {\n" +
- " Z() {\n" +
- " super();\n" +
- " }\n" +
- " }\n" +
+ " void foo2;\n" +
" }\n" +
"}\n";
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest.java
index 407758e..5869d50 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest.java
@@ -753,8 +753,8 @@
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=239198
*/
-public void test028() {
- String error = (this.complianceLevel == ClassFileConstants.JDK13) ?
+public void _test028() {
+ String error = (this.complianceLevel == ClassFileConstants.JDK14) ?
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" Srtring bar = \"\"\"\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java
index a281f4e..de1c445 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3141,8 +3141,6 @@
" }\n" +
" public void aMethod(int A) {\n" +
" public void anotherMethod;\n" +
- " int A;\n" +
- " ;\n" +
" }\n" +
" }\n" +
" public A() {\n" +
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 5f0c5c3..d20ccdd 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
@@ -221,6 +221,7 @@
tests_13.add(SelectionParserTest12.class);
tests_13.add(ModuleDeclarationSyntaxTest.class);
tests_13.add(JEP286ReservedWordTest.class);
+ //TODO:To add SwitchExpressionYieldTests here as well as master
// Reset forgotten subsets tests
TestCase.TESTS_PREFIX = null;
TestCase.TESTS_NAMES = null;
@@ -229,6 +230,28 @@
TestCase.RUN_ONLY_ID = null;
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13), tests_13));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_14) != 0) {
+ ArrayList tests_14 = (ArrayList)testClasses.clone();
+ tests_14.addAll(TEST_CLASSES_1_5);
+ tests_14.add(ParserTest1_7.class);
+ tests_14.add(LambdaExpressionSyntaxTest.class);
+ tests_14.add(ReferenceExpressionSyntaxTest.class);
+ tests_14.add(TypeAnnotationSyntaxTest.class);
+ tests_14.add(CompletionParserTest18.class);
+ tests_14.add(SelectionParserTest18.class);
+ tests_14.add(SelectionParserTest9.class);
+ tests_14.add(SelectionParserTest10.class);
+ tests_14.add(SelectionParserTest12.class);
+ tests_14.add(ModuleDeclarationSyntaxTest.class);
+ tests_14.add(JEP286ReservedWordTest.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_14), tests_14));
+ }
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 f8d2b76..3abafee 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -37,6 +37,7 @@
import java.io.PrintWriter;
import java.net.URL;
import java.text.MessageFormat;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -110,10 +111,10 @@
.map(e -> e.getKey() + "=" + e.getValue())
.toArray(String[]::new);
- protected class Runner {
+ public class Runner {
boolean shouldFlushOutputDirectory = true;
// input:
- String[] testFiles;
+ public String[] testFiles;
String[] dependantFiles;
String[] classLibraries;
boolean libsOnModulePath;
@@ -133,14 +134,14 @@
JavacTestOptions javacTestOptions;
// execution:
boolean forceExecution;
- String[] vmArguments;
- String expectedOutputString;
+ public String[] vmArguments;
+ public String expectedOutputString;
String expectedErrorString;
ASTVisitor visitor;
-
+ public Runner() {}
@SuppressWarnings("synthetic-access")
- protected void runConformTest() {
+ public void runConformTest() {
runTest(this.shouldFlushOutputDirectory,
this.testFiles,
this.dependantFiles != null ? this.dependantFiles : new String[] {},
@@ -306,6 +307,8 @@
return JavaCore.VERSION_12;
} else if(rawVersion.startsWith("13")) {
return JavaCore.VERSION_13;
+ } else if(rawVersion.startsWith("14")) {
+ return JavaCore.VERSION_14;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
@@ -447,6 +450,20 @@
return 0200;
}
}
+ if (version == JavaCore.VERSION_14) {
+ if ("14-ea".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("14".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("14.0.1".equals(rawVersion)) {
+ return 0100;
+ }
+ if ("14.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
@@ -1131,6 +1148,7 @@
public final static String MODULE_INFO_NAME = new String(TypeConstants.MODULE_INFO_NAME);
public static boolean SHIFT = false;
+ public static String PREVIEW_ALLOWED_LEVEL = JavaCore.VERSION_14;
protected static final String SOURCE_DIRECTORY = Util.getOutputDirectory() + File.separator + "source";
@@ -1142,6 +1160,9 @@
public AbstractRegressionTest(String name) {
super(name);
}
+ protected boolean checkPreviewAllowed() {
+ return this.complianceLevel == ClassFileConstants.JDK14;
+ }
protected void checkClassFile(String className, String source, String expectedOutput) throws ClassFormatException, IOException {
this.checkClassFile("", className, source, expectedOutput, ClassFileBytesDisassembler.SYSTEM);
}
@@ -1828,7 +1849,35 @@
protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
runConformTest(testFiles, expectedOutput, customOptions, null);
}
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments, Charset charset) {
+ runTest(
+ // test directory preparation
+ true /* flush output directory */,
+ testFiles /* test files */,
+ // compiler options
+ null /* no class libraries */,
+ customOptions /* no custom options */,
+ false /* do not perform statements recovery */,
+ null /* no custom requestor */,
+ // compiler results
+ false /* expecting no compiler errors */,
+ null /* do not check compiler log */,
+ // runtime options
+ false /* do not force execution */,
+ vmArguments /* no vm arguments */,
+ // runtime results
+ expectedOutput /* expected output string */,
+ null /* do not check error string */,
+ // javac options
+ JavacTestOptions.DEFAULT /* default javac test options */,
+ charset);
+ }
protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments) {
+ runConformTest(testFiles, expectedOutput, customOptions, vmArguments, RUN_JAVAC ? /* javac test options */
+ new JavacTestOptions("-source 1.4") :
+ JavacTestOptions.DEFAULT);
+ }
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments, JavacTestOptions javacOptions) {
runTest(
// test directory preparation
true /* flush output directory */,
@@ -1848,7 +1897,7 @@
expectedOutput /* expected output string */,
null /* do not check error string */,
// javac options
- JavacTestOptions.DEFAULT /* default javac test options */);
+ javacOptions);
}
protected void runConformTest(
String[] testFiles,
@@ -1872,7 +1921,8 @@
null,
null,
expectedSuccessOutputString,
- JavacTestOptions.DEFAULT);
+ JavacTestOptions.DEFAULT,
+ Charset.defaultCharset());
}
protected void runConformTest(
@@ -2683,7 +2733,16 @@
String[] classLibraries,
boolean shouldFlushOutputDirectory,
Map customOptions) {
- runNegativeTest(testFiles, expectedCompilerLog, classLibraries, shouldFlushOutputDirectory, null, customOptions);
+ runNegativeTest(testFiles, expectedCompilerLog, classLibraries, shouldFlushOutputDirectory, null, customOptions, JavacTestOptions.DEFAULT);
+ }
+ protected void runNegativeTest(
+ String[] testFiles,
+ String expectedCompilerLog,
+ String[] classLibraries,
+ boolean shouldFlushOutputDirectory,
+ String[] vmArguments,
+ Map customOptions) {
+ runNegativeTest(testFiles, expectedCompilerLog, classLibraries, shouldFlushOutputDirectory, vmArguments, customOptions, JavacTestOptions.DEFAULT);
}
protected void runNegativeTest(
String[] testFiles,
@@ -2691,7 +2750,8 @@
String[] classLibraries,
boolean shouldFlushOutputDirectory,
String[] vmArguments,
- Map customOptions) {
+ Map customOptions,
+ JavacTestOptions javacOptions) {
runTest(
// test directory preparation
shouldFlushOutputDirectory /* should flush output directory */,
@@ -2716,7 +2776,7 @@
null /* do not check output string */,
null /* do not check error string */,
// javac options
- JavacTestOptions.DEFAULT /* default javac test options */);
+ javacOptions);
}
protected void runNegativeTest(
boolean skipJavac,
@@ -3031,7 +3091,50 @@
expectedErrorString,
null,
expectedOutputString,
- javacTestOptions);
+ javacTestOptions,
+ Charset.defaultCharset());
+ }
+ private void runTest(
+ // test directory preparation
+ boolean shouldFlushOutputDirectory,
+ String[] testFiles,
+ // compiler options
+ String[] classLibraries,
+ Map<String, String> customOptions,
+ boolean performStatementsRecovery,
+ ICompilerRequestor customRequestor,
+ // compiler results
+ boolean expectingCompilerErrors,
+ String expectedCompilerLog,
+ // runtime options
+ boolean forceExecution,
+ String[] vmArguments,
+ // runtime results
+ String expectedOutputString,
+ String expectedErrorString,
+ // javac options
+ JavacTestOptions javacTestOptions,
+ Charset charset) {
+ runTest(
+ shouldFlushOutputDirectory,
+ testFiles,
+ new String[] {},
+ classLibraries,
+ false,
+ customOptions,
+ performStatementsRecovery,
+ customRequestor,
+ expectingCompilerErrors,
+ expectedCompilerLog,
+ null, // alternate compile errors
+ forceExecution,
+ vmArguments,
+ expectedOutputString,
+ expectedErrorString,
+ null,
+ expectedOutputString,
+ javacTestOptions,
+ charset);
}
/** Call this if the compiler randomly produces different error logs. */
protected void runNegativeTestMultiResult(String[] testFiles, Map options, String[] alternateCompilerErrorLogs) {
@@ -3057,7 +3160,53 @@
null,
null,
null,
- JavacTestOptions.DEFAULT);
+ JavacTestOptions.DEFAULT,
+ Charset.defaultCharset());
+ }
+ private void runTest(
+ // test directory preparation
+ boolean shouldFlushOutputDirectory,
+ String[] testFiles,
+ String[] dependantFiles,
+ // compiler options
+ String[] classLibraries,
+ boolean libsOnModulePath,
+ Map<String, String> customOptions,
+ boolean performStatementsRecovery,
+ ICompilerRequestor customRequestor,
+ // compiler results
+ boolean expectingCompilerErrors,
+ String expectedCompilerLog,
+ String[] alternateCompilerLogs,
+ // runtime options
+ boolean forceExecution,
+ String[] vmArguments,
+ // runtime results
+ String expectedOutputString,
+ String expectedErrorString,
+ final ASTVisitor visitor,
+ // javac options
+ String expectedJavacOutputString,
+ JavacTestOptions javacTestOptions) {
+ runTest( shouldFlushOutputDirectory,
+ testFiles,
+ dependantFiles,
+ classLibraries,
+ libsOnModulePath,
+ customOptions,
+ performStatementsRecovery,
+ customRequestor,
+ expectingCompilerErrors,
+ expectedCompilerLog,
+ alternateCompilerLogs,
+ forceExecution,
+ vmArguments,
+ expectedOutputString,
+ expectedErrorString,
+ visitor,
+ expectedJavacOutputString,
+ javacTestOptions,
+ Charset.defaultCharset());
}
// This is a worker method to support regression tests. To ease policy changes,
// it should not be called directly, but through the runConformTest and
@@ -3160,7 +3309,8 @@
final ASTVisitor visitor,
// javac options
String expectedJavacOutputString,
- JavacTestOptions javacTestOptions) {
+ JavacTestOptions javacTestOptions,
+ Charset charset) {
// non-javac part
if (shouldFlushOutputDirectory)
Util.flushDirectoryContent(new File(OUTPUT_DIR));
@@ -3313,7 +3463,7 @@
}
}
// javac part
- if (RUN_JAVAC && javacTestOptions != JavacTestOptions.SKIP) {
+ if (RUN_JAVAC) {
runJavac(testFiles, expectingCompilerErrors, expectedCompilerLog,
expectedJavacOutputString, expectedErrorString, shouldFlushOutputDirectory,
javacTestOptions, vmArguments, classLibraries, libsOnModulePath);
@@ -3840,4 +3990,13 @@
}
return null;
}
+ protected Map<String, String> setPresetPreviewOptions() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return options;
+ }
}
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 393c565..af25893 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
@@ -941,6 +941,7 @@
expectedProblemAttributes.put("ParsingErrorOnKeywordNoSuggestion", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
expectedProblemAttributes.put("ParsingErrorReplaceTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
expectedProblemAttributes.put("ParsingErrorUnexpectedEOF", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("PatternVariableNotInScope", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("PolymorphicMethodNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("PossibleAccidentalBooleanAssignment", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("PotentialHeapPollutionFromVararg", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW));
@@ -1287,25 +1288,56 @@
expectedProblemAttributes.put("RoleFileMissingTeamDeclaration", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
//SH}
expectedProblemAttributes.put("PreviewFeaturesNotAllowed", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldIncompatibleResultExpressionTypes", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldEmptySwitchBlock", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldNoResultExpression", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionaYieldSwitchLabeledBlockCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldLastStatementCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldTrailingSwitchLabels", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchPreviewMixedCase", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldMissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldMissingValue", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldMissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldIllegalLastStatement", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldBreakNotAllowed", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodWarning", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodError", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldOutsideSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldRestrictedGeneralWarning", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
- expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("SwitchExpressionsYieldIncompatibleResultExpressionTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("SwitchExpressionsYieldEmptySwitchBlock", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldNoResultExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionaYieldSwitchLabeledBlockCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldLastStatementCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldTrailingSwitchLabels", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchPreviewMixedCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingValue", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldIllegalLastStatement", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldBreakNotAllowed", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodWarning", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodError", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldOutsideSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsYieldRestrictedGeneralWarning", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("MultiConstantCaseLabelsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("ArrowInCaseStatementsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsBreakOutOfSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionsContinueOutOfSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("RecordIllegalModifierForRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalModifierForInnerRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalComponentNameInRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordNonStaticFieldDeclarationInRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordAccessorMethodHasThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCanonicalConstructorShouldBePublic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordMultipleCanonicalConstructors", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCompactConstructorHasReturnStatement", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordDuplicateComponent", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalNativeModifierInRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordInstanceInitializerBlockInRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIsAReservedTypeName", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalAccessorReturnType", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordAccessorMethodShouldBePublic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCanonicalConstructorShouldNotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasReturnStatement", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCannotExtendRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordComponentCannotBeVoid", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalVararg", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -2014,6 +2046,7 @@
expectedProblemAttributes.put("ParsingErrorOnKeywordNoSuggestion", SKIP);
expectedProblemAttributes.put("ParsingErrorReplaceTokens", SKIP);
expectedProblemAttributes.put("ParsingErrorUnexpectedEOF", SKIP);
+ expectedProblemAttributes.put("PatternVariableNotInScope", SKIP);
expectedProblemAttributes.put("PolymorphicMethodNotBelow17", SKIP);
expectedProblemAttributes.put("PossibleAccidentalBooleanAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT));
expectedProblemAttributes.put("PotentialHeapPollutionFromVararg", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION));
@@ -2914,6 +2947,37 @@
expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", SKIP);
expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", SKIP);
expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", SKIP);
+ expectedProblemAttributes.put("MultiConstantCaseLabelsNotSupported", SKIP);
+ expectedProblemAttributes.put("ArrowInCaseStatementsNotSupported", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsNotSupported", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsBreakOutOfSwitchExpression", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsContinueOutOfSwitchExpression", SKIP);
+ expectedProblemAttributes.put("RecordIllegalModifierForRecord", SKIP);
+ expectedProblemAttributes.put("RecordIllegalModifierForInnerRecord", SKIP);
+ expectedProblemAttributes.put("RecordIllegalComponentNameInRecord", SKIP);
+ expectedProblemAttributes.put("RecordNonStaticFieldDeclarationInRecord", SKIP);
+ expectedProblemAttributes.put("RecordAccessorMethodHasThrowsClause", SKIP);
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasThrowsClause", SKIP);
+ expectedProblemAttributes.put("RecordCanonicalConstructorShouldBePublic", SKIP);
+ expectedProblemAttributes.put("RecordMultipleCanonicalConstructors", SKIP);
+ expectedProblemAttributes.put("RecordCompactConstructorHasReturnStatement", SKIP);
+ expectedProblemAttributes.put("RecordDuplicateComponent", SKIP);
+ expectedProblemAttributes.put("RecordIllegalNativeModifierInRecord", SKIP);
+ expectedProblemAttributes.put("RecordInstanceInitializerBlockInRecord", SKIP);
+ expectedProblemAttributes.put("RecordIsAReservedTypeName", SKIP);
+ expectedProblemAttributes.put("RecordIllegalAccessorReturnType", SKIP);
+ expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeGeneric", SKIP);
+ expectedProblemAttributes.put("RecordAccessorMethodShouldBePublic", SKIP);
+ expectedProblemAttributes.put("RecordCanonicalConstructorShouldNotBeGeneric", SKIP);
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasReturnStatement", SKIP);
+ expectedProblemAttributes.put("RecordCanonicalConstructorHasExplicitConstructorCall", SKIP);
+ expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", SKIP);
+ expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", SKIP);
+ expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", SKIP);
+ expectedProblemAttributes.put("RecordCannotExtendRecord", SKIP);
+ expectedProblemAttributes.put("RecordComponentCannotBeVoid", SKIP);
+ expectedProblemAttributes.put("RecordIllegalVararg", SKIP);
+ expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable",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/Compliance_1_4.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
index e0dd66d..776e319 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -54,7 +54,7 @@
// Use this static initializer to specify subset for tests
// All specified tests which does not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "Bug58069" };
+// TESTS_NAMES = new String[] { "test079" };
// TESTS_NUMBERS = new int[] { 104 };
// TESTS_RANGE = new int[] { 85, -1 };
}
@@ -2592,7 +2592,7 @@
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=47227
*/
-public void test079() {
+public void _test079() {
this.runNegativeTest(
new String[] {
"Hello.java",
@@ -2623,21 +2623,18 @@
"----------\n" +
"1. ERROR in Hello.java (at line 1)\n" +
" void ___eval() {\n" +
- " ^^^^^^^^^^^^^^\n" +
- "Syntax error on tokens, delete these tokens\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
"----------\n" +
- "2. ERROR in Hello.java (at line 2)\n" +
- " new Runnable() {\n" +
- " int ___run() throws Throwable {\n" +
- " return blah;\n" +
- " }\n" +
- " private String blarg;\n" +
- " public void run() {\n" +
- " }\n" +
- " };\n" +
- "}\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Syntax error on tokens, delete these tokens\n" +
+ "2. ERROR in Hello.java (at line 1)\n" +
+ " void ___eval() {\n" +
+ " ^\n" +
+ "Syntax error on token \")\", { expected after this token\n" +
+ "----------\n" +
+ "3. ERROR in Hello.java (at line 23)\n" +
+ " }\n" +
+ " ^\n" +
+ "Syntax error, insert \"}\" to complete RecordBody\n" +
"----------\n"
);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
index f086fcf..a435e6e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -58,7 +58,7 @@
// All specified tests which does not belong to the class are skipped...
static {
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
-// TESTS_NAMES = new String[] { "Bug58069" };
+// TESTS_NAMES = new String[] { "test079" };
// Numbers of tests to run: "test<number>" will be run for each number of this array
// TESTS_NUMBERS = new int[] { 88 };
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
@@ -2719,7 +2719,8 @@
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=47227
*/
-public void test079() {
+// TODO: Enable after Bug 552769 is fixed
+public void _test079() {
this.runNegativeTest(
new String[] {
"Hello.java",
@@ -2751,43 +2752,17 @@
"1. ERROR in Hello.java (at line 1)\n" +
" void ___eval() {\n" +
" ^^^^\n" +
- "Syntax error on token \"void\", @ expected\n" +
+ "Syntax error on token \"void\", record expected\n" +
"----------\n" +
"2. ERROR in Hello.java (at line 1)\n" +
" void ___eval() {\n" +
" ^\n" +
- "Syntax error on token \")\", delete this token\n" +
+ "Syntax error on token \")\", { expected after this token\n" +
"----------\n" +
- "3. ERROR in Hello.java (at line 9)\n" +
- " };\n" +
- "}\n" +
- " ^^^^\n" +
- "Syntax error on tokens, delete these tokens\n" +
- "----------\n" +
- "4. ERROR in Hello.java (at line 23)\n" +
+ "3. ERROR in Hello.java (at line 23)\n" +
" }\n" +
" ^\n" +
- "Syntax error, insert \"}\" to complete ClassBody\n" +
- "----------\n" +
- "5. ERROR in Hello.java (at line 23)\n" +
- " }\n" +
- " ^\n" +
- "Syntax error, insert \"}\" to complete MemberValue\n" +
- "----------\n" +
- "6. ERROR in Hello.java (at line 23)\n" +
- " }\n" +
- " ^\n" +
- "Syntax error, insert \")\" to complete Modifiers\n" +
- "----------\n" +
- "7. ERROR in Hello.java (at line 23)\n" +
- " }\n" +
- " ^\n" +
- "Syntax error, insert \"enum Identifier\" to complete EnumHeader\n" +
- "----------\n" +
- "8. ERROR in Hello.java (at line 23)\n" +
- " }\n" +
- " ^\n" +
- "Syntax error, insert \"EnumBody\" to complete CompilationUnit\n" +
+ "Syntax error, insert \"}\" to complete RecordBody\n" +
"----------\n"
);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
index 6fc9032..ee6b347 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java
@@ -2905,14 +2905,9 @@
"----------\n");
}
public void testBug548318_001() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
@@ -2960,14 +2955,11 @@
}
public void testBug548318_002() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
@@ -3017,14 +3009,11 @@
* k is definitely assigned - no errors on that front.
*/
public void testBug548318_003() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 23)\n" +
@@ -3072,14 +3061,11 @@
defaultOptions);
}
public void testBug548318_004() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
@@ -3142,14 +3128,11 @@
defaultOptions);
}
public void testBug548318_005() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
@@ -3214,14 +3197,11 @@
* expression e in the switch block that may exit the switch expression, V is definitely assigned after e when false.
*/
public void testBug548318_006() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 22)\n" +
@@ -3278,14 +3258,11 @@
* statement and V is definitely unassigned after e when false.
*/
public void testBug548318_007() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 18)\n" +
@@ -3342,14 +3319,11 @@
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
public void testBug548318_008() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 22)\n" +
@@ -3401,14 +3375,11 @@
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
public void testBug548318_009() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
@@ -3466,14 +3437,11 @@
* iff V is [un]assigned after the selector expression.
*/
public void testBug548318_010() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 22)\n" +
@@ -3526,14 +3494,11 @@
* iff V is [un]assigned after the selector expression.
*/
public void testBug548318_011() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
@@ -3592,14 +3557,11 @@
* and V is [un]assigned after the preceding statement
*/
public void testBug548318_012() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 22)\n" +
@@ -3653,14 +3615,11 @@
* and V is [un]assigned after the preceding statement"
*/
public void testBug548318_012b() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 15)\n" +
@@ -3716,14 +3675,11 @@
* and V is [un]assigned after the preceding statement" needs to be checked
*/
public void testBug548318_013() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
@@ -3791,14 +3747,11 @@
* It is a switch labeled throw statement.
*/
public void testBug548318_014() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 23)\n" +
@@ -3868,14 +3821,11 @@
* It is a switch labeled throw statement.
*/
public void testBug548318_015() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 17)\n" +
@@ -3936,14 +3886,11 @@
* block iff V is [un]assigned after the selector expression.
*/
public void testBug548318_016() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 14)\n" +
@@ -3993,14 +3940,11 @@
* block iff V is [un]assigned after the selector expression.
*/
public void testBug548318_017() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
@@ -4059,14 +4003,11 @@
* expression, block, or throw statement of the switch labeled rule.
*/
public void testBug548318_018() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 20)\n" +
@@ -4117,14 +4058,11 @@
* expression, block, or throw statement of the switch labeled rule.
*/
public void testBug548318_019() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 15)\n" +
@@ -4178,14 +4116,11 @@
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
public void testBug548318_020() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 19)\n" +
@@ -4234,14 +4169,11 @@
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
public void testBug548318_021() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
@@ -4299,14 +4231,11 @@
* V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
public void testBug548318_022() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 19)\n" +
@@ -4359,14 +4288,11 @@
* V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
public void testBug548318_023() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
@@ -4424,14 +4350,11 @@
* V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
public void testBug548318_024() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
@@ -4486,14 +4409,11 @@
* expression, block, or throw statement of the switch labeled rule.
*/
public void testBug548318_025() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 20)\n" +
@@ -4549,14 +4469,11 @@
* expression, block, or throw statement of the switch labeled rule.
*/
public void testBug548318_026() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 16)\n" +
@@ -4617,14 +4534,11 @@
* switch expression iff V is [un]assigned after the selector expression of the switch expression.
*/
public void testBug548318_027() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 20)\n" +
@@ -4680,14 +4594,11 @@
* switch expression iff V is [un]assigned after the selector expression of the switch expression.
*/
public void testBug548318_028() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
@@ -4753,14 +4664,11 @@
* followed by }, then V is [un]assigned after the selector expression
*/
public void testBug548318_029() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 24)\n" +
@@ -4825,14 +4733,11 @@
* followed by }, then V is [un]assigned after the selector expression
*/
public void testBug548318_030() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
+ if (!checkPreviewAllowed())
+
+
return;
- Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ Map<String, String> defaultOptions = setPresetPreviewOptions();
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 20)\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index 7390e53..ee051f5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -10164,4 +10164,25 @@
"Jane <jane@example.com>\n" +
"Joe <joe@example.com>");
}
+ public void testBug560566() {
+ runNegativeTest(
+ new String[] {
+ "Tester.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.stream.Collectors;\n" +
+ "import java.util.stream.Stream;\n" +
+ "\n" +
+ "public class Tester {\n" +
+ " {\n" +
+ " Stream.empty().collect(Collectors.toList(ArrayList::new));\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in Tester.java (at line 7)\n" +
+ " Stream.empty().collect(Collectors.toList(ArrayList::new));\n" +
+ " ^^^^^^\n" +
+ "The method toList() in the type Collectors is not applicable for the arguments (ArrayList::new)\n" +
+ "----------\n");
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
index 43b93f0..2c9cc2a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 IBM Corporation and others.
+ * Copyright (c) 2011, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -888,11 +888,10 @@
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$Y.class", "Y", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
}
public void test018() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"X.java",
- "import java.lang.annotation.*;\n" +
- "import static java.lang.annotation.ElementType.*; \n" +
"@interface Receiver {}\n" +
"class Document {}\n" +
"interface I {\n" +
@@ -905,17 +904,7 @@
" }\n" +
"}\n",
},
- "----------\n" +
- "1. ERROR in X.java (at line 9)\n" +
- " void foo(@Receiver X this) {}\n" +
- " ^^^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 11)\n" +
- " Y(@Receiver X X.this, boolean b) { }\n" +
- " ^^^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
public void test019() throws Exception {
this.runConformTest(
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
index bf7f872..4dab409 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
@@ -46,6 +46,7 @@
ALL_CLASSES.add(JavadocTestForMethod.class);
ALL_CLASSES.add(JavadocTestMixed.class);
ALL_CLASSES.add(JavadocTestForClass.class);
+ ALL_CLASSES.add(JavadocTestForRecord.class);
ALL_CLASSES.add(JavadocTestForConstructor.class);
ALL_CLASSES.add(JavadocTestForField.class);
ALL_CLASSES.add(JavadocTestForInterface.class);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java
new file mode 100644
index 0000000..844a51b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+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 JavadocTestForRecord extends JavadocTest {
+
+ static {
+// TESTS_NAMES = new String[] { "testBug549855a" };
+ // TESTS_NUMBERS = new int[] { 1 };
+ // TESTS_RANGE = new int[] { 298, -1 };
+ }
+
+ public JavadocTestForRecord(String name) {
+ super(name);
+ }
+
+ String docCommentSupport = CompilerOptions.ENABLED;
+ String reportInvalidJavadoc = CompilerOptions.ERROR;
+ String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE;
+ String reportMissingJavadocTags = CompilerOptions.ERROR;
+ String reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED;
+ String reportMissingJavadocComments = CompilerOptions.ERROR;
+ String reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED;
+
+ @SuppressWarnings("rawtypes")
+ public static Class testClass() {
+ return JavadocTestForRecord.class;
+ }
+
+ // Use this static initializer to specify subset for tests
+ // All specified tests which does not belong to the class are skipped...
+ static {
+// TESTS_PREFIX = "testBug95521";
+// TESTS_NAMES = new String[] { "testBug331872d" };
+// TESTS_NUMBERS = new int[] { 101283 };
+// TESTS_RANGE = new int[] { 23, -1 };
+ }
+
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_14);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected Map getCompilerOptions() {
+ Map options = super.getCompilerOptions();
+ options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport);
+ options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc);
+ if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) {
+ options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility);
+ }
+ if (this.reportMissingJavadocComments != null)
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments);
+ else
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc);
+ if (this.reportMissingJavadocCommentsVisibility != null)
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility,
+ this.reportMissingJavadocCommentsVisibility);
+ if (this.reportMissingJavadocTags != null) {
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags);
+ if (this.reportMissingJavadocTagsOverriding != null) {
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding,
+ this.reportMissingJavadocTagsOverriding);
+ }
+ } else {
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc);
+ }
+ if (this.reportMissingJavadocComments != null)
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments);
+ options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_Release, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14); // FIXME
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return options;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+
+ @Override
+ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("14"));
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput) {
+ runConformTest(testFiles, expectedOutput, getCompilerOptions());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedOutputString = expectedOutput;
+ runner.vmArguments = new String[] { "--enable-preview" };
+ runner.customOptions = customOptions;
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("14");
+ runner.runConformTest();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.docCommentSupport = CompilerOptions.ENABLED;
+ this.reportInvalidJavadoc = CompilerOptions.ERROR;
+ this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE;
+ this.reportMissingJavadocTags = CompilerOptions.ERROR;
+ this.reportMissingJavadocComments = CompilerOptions.ERROR;
+ this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED;
+ this.reportMissingJavadocComments = CompilerOptions.ERROR;
+ }
+
+ public void test001() {
+ if(this.complianceLevel < ClassFileConstants.JDK14) {
+ return;
+ }
+ this.runNegativeTest(new String[] { "X.java", "public record X() {\n" + "}\n" },
+ "----------\n" + "1. ERROR in X.java (at line 1)\n" + " public record X() {\n" + " ^\n"
+ + "Javadoc: Missing comment for public declaration\n" + "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+
+ public void test002() {
+ if(this.complianceLevel < ClassFileConstants.JDK14) {
+ return;
+ }
+ this.runNegativeTest(
+ new String[] { "X.java",
+ " /**\n" + " * @param radius radius of X\n" + " */\n" + "public record X(int radius) {\n"
+ + " public void foo() {\n" + " }\n" + "}\n" },
+ "----------\n" + "1. ERROR in X.java (at line 5)\n" + " public void foo() {\n" + " ^^^^^\n"
+ + "Javadoc: Missing comment for public declaration\n" + "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+
+ public void test003() {
+ if(this.complianceLevel < ClassFileConstants.JDK14) {
+ return;
+ }
+ runConformTest(new String[] { "X.java",
+ " /** \n" + " * \n" + " */ \n" + "public record X() {\n" + " /** \n"
+ + " * @param args \n" + " */ \n" + " public static void main(String[] args){\n"
+ + " System.out.println(0);\n" + " }\n" + "}" },
+ "0");
+ }
+
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
index 5a95250..40e78f6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
@@ -455,20 +455,15 @@
"}"
},
"----------\n" +
- "1. ERROR in p1\\A.java (at line 9)\n" +
- " public class aClass implements B, B.C { \n" +
- " ^^^^^^\n" +
- "The type A.aClass must implement the inherited abstract method A.B.C.anotherMethod(int)\n" +
- "----------\n" +
- "2. ERROR in p1\\A.java (at line 11)\n" +
- " public void anotherMethod(int A) {}; \n" +
- " ^\n" +
- "Syntax error on token \"(\", ; expected\n" +
- "----------\n" +
- "3. ERROR in p1\\A.java (at line 11)\n" +
- " public void anotherMethod(int A) {}; \n" +
- " ^\n" +
- "Syntax error on token \")\", ; expected\n" +
+ "1. ERROR in p1\\A.java (at line 9)\n" +
+ " public class aClass implements B, B.C { \n" +
+ " ^^^^^^\n" +
+ "The type A.aClass must implement the inherited abstract method A.B.C.anotherMethod(int)\n" +
+ "----------\n" +
+ "2. ERROR in p1\\A.java (at line 11)\n" +
+ " public void anotherMethod(int A) {}; \n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
"----------\n"
);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java
index 2b409db..8c0d6d4 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java
@@ -685,22 +685,19 @@
"----------\n");
}
public void test032() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"Marker.java",
"@interface Marker {}",
"X.java",
"public class X<@Marker T> {}",
},
- "----------\n" +
- "1. ERROR in X.java (at line 1)\n" +
- " public class X<@Marker T> {}\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
public void test033() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"Marker.java",
"@interface Marker {}",
@@ -709,12 +706,7 @@
"X.java",
"public class X extends @Marker Y {}",
},
- "----------\n" +
- "1. ERROR in X.java (at line 1)\n" +
- " public class X extends @Marker Y {}\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
// check locations
public void test034() throws Exception {
@@ -884,10 +876,9 @@
"Syntax error, type annotations are illegal here\n" +
"----------\n");
}
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383950
- // [1.8][compiler] Type annotations must have target type meta annotation TYPE_USE
public void test037() {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"X.java",
"@interface Marker {}\n" +
@@ -898,17 +889,7 @@
" }\n" +
"}\n",
},
- "----------\n" +
- "1. ERROR in X.java (at line 3)\n" +
- " public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 3)\n" +
- " public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383950
// [1.8][compiler] Type annotations must have target type meta annotation TYPE_USE
@@ -2114,22 +2095,19 @@
"----------\n");
}
public void test062() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
" public <T> @Marker Object foo() {\n" +
+ " return null;" +
" }\n" +
"}\n" +
"@interface Marker {\n" +
"}\n"
},
- "----------\n" +
- "1. ERROR in X.java (at line 2)\n" +
- " public <T> @Marker Object foo() {\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
public void test063() throws Exception {
this.runNegativeTest(
@@ -2171,7 +2149,8 @@
"----------\n");
}
public void test065() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2180,17 +2159,7 @@
"@interface Marker {\n" +
"}\n"
},
- "----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
- " Object o = new <String> @Marker X();\n" +
- " ^^^^^^\n" +
- "Unused type arguments for the non generic constructor X() of type X; it should not be parameterized with arguments <String>\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " Object o = new <String> @Marker X();\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
public void test066() throws Exception {
this.runNegativeTest(
@@ -2202,14 +2171,10 @@
"@interface Marker {\n" +
"}\n"
},
+ // one error removed after https://bugs.openjdk.java.net/browse/JDK-8231435
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" Object o = new X().new <String> @Marker X();\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " Object o = new X().new <String> @Marker X();\n" +
" ^^^^^^^^^\n" +
"X.X cannot be resolved to a type\n" +
"----------\n");
@@ -2232,7 +2197,8 @@
"----------\n");
}
public void test068() throws Exception {
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2241,17 +2207,7 @@
"@interface Marker {\n" +
"}\n"
},
- "----------\n" +
- "1. WARNING in X.java (at line 2)\n" +
- " Object o = new <String> @Marker X() {};\n" +
- " ^^^^^^\n" +
- "Unused type arguments for the non generic constructor X() of type X; it should not be parameterized with arguments <String>\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 2)\n" +
- " Object o = new <String> @Marker X() {};\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385293
public void test069() throws Exception {
@@ -2315,12 +2271,9 @@
"Marker cannot be resolved to a type\n" +
"----------\n");
}
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=388085
public void test0388085a() {
this.runNegativeTest(
new String[] {"X.java",
- "import java.lang.annotation.Target;\n" +
- "import static java.lang.annotation.ElementType.*;\n" +
"class X {\n" +
" public void main() {\n" +
" final One<@Marker ? extends Two<@Marker ? super Three<? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null;" +
@@ -2332,26 +2285,12 @@
"class Three<T> {}\n" +
"class Four<U, V> {}\n" +
"@interface Marker {}"},
+ // some errors no longer raised since https://bugs.openjdk.java.net/browse/JDK-8231435
"----------\n" +
- "1. ERROR in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" final One<@Marker ? extends Two<@Marker ? super Three<? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null; one = null;\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " final One<@Marker ? extends Two<@Marker ? super Three<? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null; one = null;\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 5)\n" +
- " final One<@Marker ? extends Two<@Marker ? super Three<? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null; one = null;\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "4. ERROR in X.java (at line 5)\n" +
- " final One<@Marker ? extends Two<@Marker ? super Three<? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null; one = null;\n" +
- " ^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
+ " ^^^\n" +
+ "The final local variable one cannot be assigned. It must be blank and not using a compound assignment\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=390882
@@ -2727,16 +2666,12 @@
" TYPE_PARAMETER,\n" +
" TYPE_USE\n" +
"}\n"},
+ // one error removed after https://bugs.openjdk.java.net/browse/JDK-8231435
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" X<@Marker ?> l;\n" +
" ^^^^^^^\n" +
"The annotation @Marker is disallowed for this location\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 4)\n" +
- " X<@Marker3 ?> l3;\n" +
- " ^^^^^^^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
"----------\n");
}
public void testBug391315a() {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
index 98f0312..4c87fcf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
@@ -10408,7 +10408,7 @@
"1. ERROR in X.java (at line 0)\n" +
" import java.io.IOException;\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n"
);
}
@@ -10449,7 +10449,7 @@
"1. ERROR in X.java (at line 0)\n" +
" import org.eclipse.jdt.annotation.*;\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n"
);
}
@@ -10475,7 +10475,7 @@
" }\n" +
"}\n"
};
- runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
+ runner.expectedCompilerLog = checkPreviewAllowed() ?
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
" default -> i == 3 ? maybe() : \"\";\n" +
@@ -10486,7 +10486,7 @@
"1. ERROR in X.java (at line 0)\n" +
" import org.eclipse.jdt.annotation.*;\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n";
runner.runNegativeTest();
}
@@ -10546,7 +10546,7 @@
" }\n" +
"}\n"
};
- runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
+ runner.expectedCompilerLog = checkPreviewAllowed() ?
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" return switch(day) {\n" +
@@ -10557,7 +10557,7 @@
"1. ERROR in X.java (at line 0)\n" +
" import org.eclipse.jdt.annotation.*;\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n";
runner.runNegativeTest();
}
@@ -10583,7 +10583,7 @@
" }\n" +
"}\n"
};
- runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
+ runner.expectedCompilerLog = checkPreviewAllowed() ?
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" return switch(day) {\n" +
@@ -10594,12 +10594,12 @@
"1. ERROR in X.java (at line 0)\n" +
" enum SomeDays { Mon, Wed, Fri }\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n";
runner.runNegativeTest();
}
public void testBug545715() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // switch expression
+ if (!checkPreviewAllowed()) return; // switch expression
Map<String, String> customOptions = getCompilerOptions();
customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -10622,15 +10622,7 @@
new String[] {"--enable-preview"});
}
public void testBug548418_001a() {
- if (this.complianceLevel < ClassFileConstants.JDK13)
- return;
- Map options = getCompilerOptions();
- options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
- options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ if (this.complianceLevel < ClassFileConstants.JDK14) return;
runNegativeTestWithLibs(
new String[] {
"X.java",
@@ -10663,35 +10655,16 @@
" }\n"+
"}\n"
},
- options,
"----------\n" +
- "1. ERROR in X.java (at line 12)\n" +
- " x = null;\n" +
- " ^^^^\n" +
- "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 13)\n" +
+ "1. ERROR in X.java (at line 13)\n" +
" break x;\n" +
" ^^^^^^^^\n" +
- "The label x is missing\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 15)\n" +
- " default -> null;\n" +
- " ^^^^\n" +
- "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" +
+ "Breaking out of switch expressions not permitted\n" +
"----------\n"
);
}
public void testBug548418_001b() {
- if (this.complianceLevel < ClassFileConstants.JDK13)
- return;
- Map options = getCompilerOptions();
- options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
- options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ if (this.complianceLevel < ClassFileConstants.JDK14) return;
runNegativeTestWithLibs(
new String[] {
"X.java",
@@ -10724,7 +10697,6 @@
" }\n"+
"}\n"
},
- options,
"----------\n" +
"1. ERROR in X.java (at line 12)\n" +
" x = null;\n" +
@@ -10739,15 +10711,7 @@
);
}
public void testBug548418_002a() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
- return;
- Map options = getCompilerOptions();
- options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
- options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ if (this.complianceLevel < ClassFileConstants.JDK14) return;
runNegativeTestWithLibs(
new String[] {
"X.java",
@@ -10767,7 +10731,6 @@
" }\n" +
"}\n"
},
- options,
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
" break \"hello\";\n" +
@@ -10787,15 +10750,7 @@
);
}
public void testBug548418_002b() {
- if (this.complianceLevel != ClassFileConstants.JDK13)
- return;
- Map options = getCompilerOptions();
- options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
- options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ if (this.complianceLevel < ClassFileConstants.JDK14) return;
runNegativeTestWithLibs(
new String[] {
"X.java",
@@ -10815,7 +10770,6 @@
" }\n" +
"}\n"
},
- options,
"----------\n" +
"1. ERROR in X.java (at line 13)\n" +
" Zork();\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index fa024bc..5003fbd 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -71,7 +71,7 @@
// Only the highest compliance level is run; add the VM argument
// -Dcompliance=1.4 (for example) to lower it if needed
static {
-// TESTS_NAMES = new String[] { "testBug406160a" };
+// TESTS_NAMES = new String[] { "testBug542707_1" };
// TESTS_NAMES = new String[] { "testBug384380" };
// TESTS_NAMES = new String[] { "testBug384380_b" };
// TESTS_NAMES = new String[] { "testBug321926a2" };
@@ -18283,7 +18283,7 @@
runner.runNegativeTest();
}
public void testBug542707_1() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // switch expression
+ if (!checkPreviewAllowed()) return; // switch expression
Runner runner = new Runner();
runner.customOptions = new HashMap<>();
runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index ab82756..614ed13 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -17807,7 +17807,7 @@
);
}
public void testBug542707_1() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // switch expression
+ if (!checkPreviewAllowed()) return; // switch expression
// switch expression has a functional type with interesting type inference and various null issues:
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java
new file mode 100644
index 0000000..e741985
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java
@@ -0,0 +1,1890 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class PatternMatching14Test extends AbstractRegressionTest {
+
+ private static final JavacTestOptions JAVAC_OPTIONS = new JavacTestOptions("-source 14 --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 PatternMatching14Test.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_14);
+ }
+ public PatternMatching14Test(String testName){
+ super(testName);
+ }
+ // 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_14);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews,
+ preview ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ return defaultOptions;
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
+ 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(false);
+ runNegativeTest(
+ new String[] {
+ "X1.java",
+ "public class X1 {\n" +
+ " public void foo(Object obj) {\n" +
+ " if (obj instanceof String s) {\n" +
+ " }\n " +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X1.java (at line 3)\n" +
+ " if (obj instanceof String s) {\n" +
+ " ^^^^^^^^\n" +
+ "Instanceof Pattern is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n",
+ /* omit one arg to directly call super method without JAVA_OPTIONS */
+ null,
+ true,
+ options);
+ }
+ public void test002() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X2 {\n" +
+ " public void foo(Integer obj) {\n" +
+ " if (obj instanceof String s) {\n" +
+ " }\n " +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X2.java (at line 4)\n" +
+ " if (obj instanceof String s) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Incompatible conditional operand types Integer and String\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test003() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X3.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X3 {\n" +
+ " public void foo(Number num) {\n" +
+ " if (num instanceof Integer s) {\n" +
+ " } else if (num instanceof String) {\n" +
+ " }\n " +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X3.java (at line 5)\n" +
+ " } else if (num instanceof String) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Incompatible conditional operand types Number and String\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test003a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X3.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X3 {\n" +
+ " public void foo(Number num) {\n" +
+ " if (num instanceof int) {\n" +
+ " }\n " +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X3.java (at line 4)\n" +
+ " if (num instanceof int) {\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Incompatible conditional operand types Number and int\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test004() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X4.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X4 {\n" +
+ " public void foo(Object obj) {\n" +
+ " String s = null;\n" +
+ " if (obj instanceof Integer s) {\n" +
+ " } else if (obj instanceof String) {\n" +
+ " }\n " +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X4.java (at line 5)\n" +
+ " if (obj instanceof Integer s) {\n" +
+ " ^\n" +
+ "Duplicate local variable s\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test005() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X5.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X5 {\n" +
+ "@SuppressWarnings(\"preview\")\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "100",
+ options);
+ }
+ public void test006() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X6.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X6 {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(s);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "abcd",
+ options);
+ }
+ public void test006a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X6a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X6a {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj != null) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(i);\n" +
+ " }\n " +
+ " }\n " +
+ " System.out.print(i);\n" +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X6a.java (at line 8)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X6a.java (at line 11)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test006b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X6b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X6b {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj != null) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(i);\n" +
+ " }\n " +
+ " }\n " +
+ " System.out.print(s);\n" +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X6b.java (at line 8)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X6b.java (at line 11)\n" +
+ " System.out.print(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test006c() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X6c.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X6c {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(i);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X6c.java (at line 7)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test006d() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X6d.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X6d {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else {\n" +
+ " System.out.print(i);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X6d.java (at line 7)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test007() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X7.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X7 {\n" +
+ " public static void foo(Object obj) {\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " System.out.print(i);\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " System.out.print(i);\n" +
+ " }\n " +
+ " }\n" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X7.java (at line 7)\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ "The pattern variable i is not in scope in this location\n" +
+ "----------\n",
+ "X7.java:4: warning: [preview] pattern matching in instanceof is a preview feature and may be removed in a future release.\n" +
+ " if (obj instanceof Integer i) {\n" +
+ " ^\n" +
+ "X7.java:6: warning: [preview] pattern matching in instanceof is a preview feature and may be removed in a future release.\n" +
+ " } else if (obj instanceof String s) {\n" +
+ " ^\n" +
+ "X7.java:7: error: cannot find symbol\n" +
+ " System.out.print(i);\n" +
+ " ^\n" +
+ " symbol: variable i\n" +
+ " location: class X7\n" +
+ "1 error\n" +
+ "2 warnings",
+ null,
+ true,
+ options);
+ }
+ public void test008() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X8.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X8 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = null;\n" +
+ " if (b != c) {\n" +
+ " if ((b instanceof String s) && (s.length() != 0))\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " else \n" +
+ " System.out.println(\"b:\" + b);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "b:100\n" +
+ "s:abcd",
+ options);
+ }
+ public void test009() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X9.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X9 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = null;\n" +
+ " if (b != c) {\n" +
+ " if ((b instanceof String s) && (s.length() != 0))\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " else if ((b instanceof Integer i2))\n" +
+ " System.out.println(\"i2:\" + i2);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "i2:100\n" +
+ "s:abcd",
+ options);
+ }
+ public void test010() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X10.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X10 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = null;\n" +
+ " if (b != c) {\n" +
+ " if (b != null && (b instanceof String s))\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " else " +
+ " System.out.println(\"b:\" + b);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "b:100\n" +
+ "s:abcd",
+ options);
+ }
+ public void test011() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X11.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X11 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = null;\n" +
+ " if (b == null && (b instanceof String s)) {\n" +
+ " } else {" +
+ " }\n" +
+ " System.out.println(s);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X11.java (at line 7)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test012() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X12.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X12 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = new Object();\n" +
+ " if (b != c) {\n" +
+ " if (b == null && (b instanceof String s)) {\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " } else {\n" +
+ " System.out.println(\"b:\" + b);\n" +
+ " }\n" +
+ " s = null;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X12.java (at line 11)\n" +
+ " s = null;\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test013() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X13.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X13 {\n" +
+ " public static void foo(Object b) {\n" +
+ " Object c = null;\n" +
+ " if (b != c) {\n" +
+ " if (b == null && (b instanceof String s))\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " else " +
+ " System.out.println(\"b:\" + b);\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(100);\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. WARNING in X13.java (at line 7)\n" +
+ " System.out.println(\"s:\" + s);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "2. ERROR in X13.java (at line 9)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test014() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X14.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14 {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(o instanceof String s)) {\n" +
+ " System.out.print(\"then:\" + s);\n" +
+ " } else {\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X14.java (at line 5)\n" +
+ " System.out.print(\"then:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test014a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X14a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14a {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(o instanceof String s)) {\n" +
+ " System.out.print(\"then:\" + s);\n" +
+ " } else {\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X14a.java (at line 5)\n" +
+ " System.out.print(\"then:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test014b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X14b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14b {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!!(o instanceof String s)) {\n" +
+ " System.out.print(\"then:\" + s);\n" +
+ " } else {\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X14b.java (at line 7)\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test014c() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X14c.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14c {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (o == null) {\n" +
+ " System.out.print(\"null\");\n" +
+ " } else if(!(o instanceof String s)) {\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X14c.java (at line 7)\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test014d() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X14d.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14d {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (o == null) {\n" +
+ " System.out.print(\"null\");\n" +
+ " } else if(!!(o instanceof String s)) {\n" +
+ " System.out.print(\"else:\" + s);\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "else:abcd",
+ options);
+ }
+ public void test014e() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X14a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X14a {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(!(o instanceof String s))) {\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " } else {\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "s:abcd",
+ options);
+ }
+ /*
+ * Test that when pattern tests for false and if doesn't complete
+ * normally, then the variable is available beyond the if statement
+ */
+ public void test015() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X15.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X15 {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(o instanceof String s)) {\n" +
+ " throw new IllegalArgumentException();\n" +
+ " } else {\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " }\n" +
+ " System.out.print(s);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "s:abcdabcd",
+ options);
+ }
+ /*
+ * Test that when pattern tests for false and if doesn't complete
+ * normally, then the variable is available beyond the if statement
+ */
+ public void test015a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X15a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X15a {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(o instanceof String s)) {\n" +
+ " throw new IllegalArgumentException();\n" +
+ " }\n" +
+ " System.out.print(s);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "abcd",
+ options);
+ }
+ /*
+ * Test that when pattern tests for false and if completes
+ * normally, then the variable is not available beyond the if statement
+ */
+ public void test015b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X15b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X15b {\n" +
+ " public static void foo(Object o) {\n" +
+ " if (!(o instanceof String s)) {\n" +
+ " //throw new IllegalArgumentException();\n" +
+ " } else {\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " }\n" +
+ " System.out.print(s);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(\"abcd\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X15b.java (at line 9)\n" +
+ " System.out.print(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test016() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X16.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X16 {\n" +
+ " public static void foo(Object o) {\n" +
+ " boolean b = (o instanceof String[] s && s.length == 1);\n" +
+ " System.out.print(b);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(new String[]{\"one\"});\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true",
+ options);
+ }
+ public void test017() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X17.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X17 {\n" +
+ " public static void foo(Object o) {\n" +
+ " boolean b = (o instanceof String[] s && s.length == 1);\n" +
+ " System.out.print(s[0]);\n" +
+ " }" +
+ " public static void main(String[] obj) {\n" +
+ " foo(new String[]{\"one\"});\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X17.java (at line 5)\n" +
+ " System.out.print(s[0]);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ /* Test that the scopes of pattern variable in a block doesn't affect
+ * another outside but declared after the block
+ */
+ public void test018() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X18.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X18 {\n" +
+ " public static void main(String[] obj) {\n" +
+ " boolean a = true;\n" +
+ " {\n" +
+ " boolean b = (obj instanceof String[] s && s.length == 0);\n" +
+ " System.out.print(b + \",\");\n" +
+ " }\n" +
+ " boolean b = a ? false : (obj instanceof String[] s && s.length == 0);\n" +
+ " System.out.print(b);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true,false",
+ options);
+ }
+ /* Test that the scopes of pattern variable in a block doesn't affect
+ * another outside but declared before the block
+ */
+ public void test019() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X19.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X19 {\n" +
+ " public static void main(String[] obj) {\n" +
+ " boolean a = true;\n" +
+ " boolean b = a ? false : (obj instanceof String[] s && s.length == 0);\n" +
+ " System.out.print(b + \",\");\n" +
+ " {\n" +
+ " b = (obj instanceof String[] s && s.length == 0);\n" +
+ " System.out.print(b);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "false,true",
+ options);
+ }
+ /* Test that we still detect duplicate pattern variable declarations
+ */
+ public void test019b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X19b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X19b {\n" +
+ " public static void main(String[] obj) {\n" +
+ " boolean a = true;\n" +
+ " if (obj instanceof String[] s && s.length == 0) {\n" +
+ " boolean b = (obj instanceof String[] s && s.length == 0);\n" +
+ " System.out.print(b);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X19b.java (at line 6)\n" +
+ " boolean b = (obj instanceof String[] s && s.length == 0);\n" +
+ " ^\n" +
+ "Duplicate local variable s\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ /* Test that we allow consequent pattern expressions in the same statement
+ */
+ public void test020() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X20.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X20 {\n" +
+ " public static void main(String[] o) {\n" +
+ " boolean b = (o instanceof String[] s) && s instanceof String[] s2;\n" +
+ " System.out.print(b);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true",
+ options);
+ }
+ /* Test that we allow consequent pattern expressions in the same statement
+ */
+ public void test021() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X21.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X21 {\n" +
+ " public static void main(String[] o) {\n" +
+ " boolean b = (o instanceof String[] s) && s instanceof String[] s2;\n" +
+ " System.out.print(s);\n" +
+ " System.out.print(s2);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X21.java (at line 5)\n" +
+ " System.out.print(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X21.java (at line 6)\n" +
+ " System.out.print(s2);\n" +
+ " ^^\n" +
+ "The pattern variable s2 is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ /* Test that we allow pattern expressions in a while statement
+ */
+ public void test022() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X22.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X22 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " while ((o instanceof String s) && s.length() > 0) {\n" +
+ " o = s.substring(0, s.length() - 1);\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one\non\no",
+ options);
+ }
+ public void test022a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X22a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X22a {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " do {\n" +
+ " o = s.substring(0, s.length() - 1);\n" +
+ " System.out.println(s);\n" +
+ " } while ((o instanceof String s) && s.length() > 0);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X22a.java (at line 8)\n" +
+ " o = s.substring(0, s.length() - 1);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X22a.java (at line 8)\n" +
+ " o = s.substring(0, s.length() - 1);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "3. ERROR in X22a.java (at line 9)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void test022b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X22b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X22b {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " do {\n" +
+ " // nothing\n" +
+ " } while ((o instanceof String s));\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X22b.java (at line 10)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void test022c() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X22c.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X22c {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " do {\n" +
+ " // nothing\n" +
+ " } while (!(o instanceof String s));\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one",
+ options);
+ }
+ /* Test pattern expressions in a while statement with break
+ */
+ public void test023() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X23.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X23 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " while (!(o instanceof String s) && s.length() > 0) {\n" +
+ " System.out.println(s);\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X23.java (at line 7)\n" +
+ " while (!(o instanceof String s) && s.length() > 0) {\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X23.java (at line 8)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test023a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X23a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X23a {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " do {\n" +
+ " System.out.println(s);\n" +
+ " break;\n" +
+ " } while (!(o instanceof String s) && s.length() > 0);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X23a.java (at line 8)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X23a.java (at line 10)\n" +
+ " } while (!(o instanceof String s) && s.length() > 0);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ /* Test pattern expressions in a while statement with no break
+ */
+ public void test023b() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X23b.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X23b {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " while (!(o instanceof String s) && s.length() > 0) {\n" +
+ " System.out.println(s);\n" +
+ " //break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X23b.java (at line 7)\n" +
+ " while (!(o instanceof String s) && s.length() > 0) {\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X23b.java (at line 8)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ // Same as above but with do while
+ public void test023c() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X23c.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X23c {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " do {\n" +
+ " System.out.println(s);\n" +
+ " //break;\n" +
+ " }while (!(o instanceof String s) && s.length() > 0);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X23c.java (at line 8)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X23c.java (at line 10)\n" +
+ " }while (!(o instanceof String s) && s.length() > 0);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test024a() {
+ Map<String, String> options = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X24a.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X24a {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object o) {\n" +
+ " while (!(o instanceof String s)) {\n" +
+ " throw new IllegalArgumentException();\n" +
+ " }\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one",
+ options);
+ }
+ /*
+ * It's not a problem to define the same var in two operands of a binary expression,
+ * but then it is not in scope below.
+ */
+ public void test025() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X25.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X25 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\", \"two\");\n" +
+ " }\n" +
+ " public static void foo(Object o, Object p) {\n" +
+ " if ((o instanceof String s) != p instanceof String s) {\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X25.java (at line 8)\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ /*
+ * It's not a problem to define the same var in two operands of a binary expression,
+ * but then it is not in scope below.
+ */
+ public void test026() {
+ Map<String, String> options = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X26.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X26 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\", \"two\");\n" +
+ " }\n" +
+ " public static void foo(Object o, Object p) {\n" +
+ " if ((o instanceof String s) == p instanceof String s) {\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X26.java (at line 8)\n" +
+ " System.out.print(\"s:\" + s);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ options);
+ }
+ public void test027() {
+ runConformTest(
+ new String[] {
+ "X27.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X27 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " for(int i = 0; (obj instanceof String[] s && s.length > 0 && i < s.length); i++) {\n" +
+ " System.out.println(s[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "",
+ getCompilerOptions(true));
+ }
+ public void test028() {
+ runConformTest(
+ new String[] {
+ "X28.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X28 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(new String[] {\"one\", \"two\"});\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " for(int i = 0; (obj instanceof String[] s && s.length > 0 && i < s.length); i++) {\n" +
+ " System.out.println(s[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one\ntwo",
+ getCompilerOptions(true));
+ }
+ public void test029() {
+ runConformTest(
+ new String[] {
+ "X29.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X29 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(new String[] {\"one\", \"two\"});\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " for(int i = 0; (obj instanceof String[] s) && s.length > 0 && i < s.length; i = (s != null ? i + 1 : i)) {\n" +
+ " System.out.println(s[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one\ntwo",
+ getCompilerOptions(true));
+ }
+ /*
+ * Test that pattern variables are accepted in initialization of a for statement,
+ * but unavailable in the body if uncertain which if instanceof check was true
+ */
+ public void test030() {
+ runNegativeTest(
+ new String[] {
+ "X30.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X30 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " for(int i = 0, length = (obj instanceof String s) ? s.length() : 0; i < length; i++) {\n" +
+ " System.out.print(s.charAt(i));\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X30.java (at line 8)\n" +
+ " System.out.print(s.charAt(i));\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test031() {
+ runNegativeTest(
+ new String[] {
+ "X31.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X31 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" +
+ " System.out.println(s[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X31.java (at line 7)\n" +
+ " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X31.java (at line 7)\n" +
+ " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "3. ERROR in X31.java (at line 8)\n" +
+ " System.out.println(s[i]);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test032() {
+ runConformTest(
+ new String[] {
+ "X32.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X32 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " String res = null;\n" +
+ " int i = 0;\n" +
+ " switch(i) {\n" +
+ " case 0:\n" +
+ " res = (obj instanceof String s) ? s : null;\n" +
+ " default:\n" +
+ " break;\n" +
+ " }\n" +
+ " System.out.println(res);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one",
+ getCompilerOptions(true));
+ }
+ public void test033() {
+ runNegativeTest(
+ new String[] {
+ "X33.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X33 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " String res = null;\n" +
+ " int i = 0;\n" +
+ " switch(i) {\n" +
+ " case 0:\n" +
+ " res = (obj instanceof String s) ? s : null;\n" +
+ " res = s.substring(1);\n" +
+ " default:\n" +
+ " break;\n" +
+ " }\n" +
+ " System.out.println(res);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X33.java (at line 12)\n" +
+ " res = s.substring(1);\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test034() {
+ runNegativeTest(
+ new String[] {
+ "X34.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X34 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " int i = 0;\n" +
+ " String result = switch(i) {\n" +
+ " case 0 -> {\n" +
+ " result = (obj instanceof String s) ? s : null;\n" +
+ " yield result;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " yield result;\n" +
+ " }\n" +
+ " };\n" +
+ " System.out.println(result);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X34.java (at line 14)\n" +
+ " yield result;\n" +
+ " ^^^^^^\n" +
+ "The local variable result may not have been initialized\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test035() {
+ runNegativeTest(
+ new String[] {
+ "X35.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X35 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " int i = 0;\n" +
+ " String result = switch(i) {\n" +
+ " case 0 -> {\n" +
+ " result = (obj instanceof String s) ? s : null;\n" +
+ " yield s;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " yield s;\n" +
+ " }\n" +
+ " };\n" +
+ " System.out.println(result);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X35.java (at line 11)\n" +
+ " yield s;\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n" +
+ "2. ERROR in X35.java (at line 14)\n" +
+ " yield s;\n" +
+ " ^\n" +
+ "The pattern variable s is not in scope in this location\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test036() {
+ runConformTest(
+ new String[] {
+ "X36.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X36 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(\"one\");\n" +
+ " }\n" +
+ " public static void foo(Object obj) {\n" +
+ " int i = 0;\n" +
+ " String result = switch(i) {\n" +
+ " default -> {\n" +
+ " result = (obj instanceof String s) ? s : null;\n" +
+ " yield result;\n" +
+ " }\n" +
+ " };\n" +
+ " System.out.println(result);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one",
+ getCompilerOptions(true));
+ }
+ public void test037() {
+ runNegativeTest(
+ new String[] {
+ "X37.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X37 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(new String[] {\"abcd\"});\n" +
+ " }\n" +
+ " public static void foo(Object[] obj) {\n" +
+ " for(int i = 0; (obj[i] instanceof String s) && s.length() > 0 ; i++) {\n" +
+ " System.out.println(s[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X37.java (at line 8)\n" +
+ " System.out.println(s[i]);\n" +
+ " ^^^^\n" +
+ "The type of the expression must be an array type but it resolved to String\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void test038() {
+ runNegativeTest(
+ new String[] {
+ "X38.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X38 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(new String[] {\"abcd\"});\n" +
+ " }\n" +
+ " public static void foo(Object[] obj) {\n" +
+ " for(int i = 0; (obj[i] instanceof String s) && s.length() > 0 ; i++) {\n" +
+ " throw new IllegalArgumentException();\n" +
+ " }\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X38.java (at line 10)\n" +
+ " System.out.println(s);\n" +
+ " ^\n" +
+ "s cannot be resolved to a variable\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ /*
+ * Failing with VerifyError
+ */
+ public void _test039() {
+ runConformTest(
+ new String[] {
+ "X39.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X39 {\n" +
+ " public static void main(String[] o) {\n" +
+ " foo(new String[] {\"one\"});;\n" +
+ " }\n" +
+ " public static void foo(Object[] obj) {\n" +
+ " for(int i = 0; i < obj.length && (obj[i] instanceof String s) && i < s.length(); i++) {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "one",
+ getCompilerOptions(true));
+ }
+ public void test040() {
+ runConformTest(
+ new String[] {
+ "X40.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X40 {\n" +
+ " String a;\n" +
+ " Object o1 = \"x\";\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(new X40().foo());\n" +
+ " }\n" +
+ " public String foo() {\n" +
+ " String res = \"\";\n" +
+ " Object o2 = \"x\";\n" +
+ " if (o1 instanceof String s) { \n" +
+ " res = \"then_\" + s;\n" +
+ " } else {\n" +
+ " res = \"else_\";\n" +
+ " }\n" +
+ " return res;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "then_x",
+ getCompilerOptions(true));
+ }
+ public void test041() {
+ runConformTest(
+ new String[] {
+ "X41.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X41 {\n" +
+ " String a;\n" +
+ " Object o1 = \"x\";\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(new X41().foo());\n" +
+ " }\n" +
+ " public String foo() {\n" +
+ " String res = \"\";\n" +
+ " Object o2 = \"x\";\n" +
+ " if ( !(o1 instanceof String s) || !o1.equals(s) ) { \n" +
+ " res = \"then_\";\n" +
+ " } else {\n" +
+ " res = \"else_\" + s;\n" +
+ " }\n" +
+ " return res;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "else_x",
+ getCompilerOptions(true));
+ }
+ public void test042() {
+ runConformTest(
+ new String[] {
+ "X42.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X42 {\n" +
+ " String a;\n" +
+ " Object o1 = \"x\";\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(new X42().foo());\n" +
+ " }\n" +
+ " public String foo() {\n" +
+ " String res = \"\";\n" +
+ " Object o2 = o1;\n" +
+ " if ( !(o1 instanceof String s) || !o1.equals(s) ) { \n" +
+ " res = \"then_\";\n" +
+ " } else {\n" +
+ " res = \"else_\" + s;\n" +
+ " }\n" +
+ " return res;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "else_x",
+ getCompilerOptions(true));
+ }
+ public void _test043() {
+ runConformTest(
+ new String[] {
+ "X43.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X43 {\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(new X43().foo(\"foo\", \"test\"));\n" +
+ " }\n" +
+ " public boolean foo(Object obj, String s) {\n" +
+ " class Inner {\n" +
+ " public boolean foo(Object obj) {\n" +
+ " if (obj instanceof String s) {\n" +
+ " // x is shadowed now\n" +
+ " if (!\"foo\".equals(s))\n" +
+ " return false;\n" +
+ " }\n" +
+ " // x is not shadowed\n" +
+ " return \"test\".equals(s);\n" +
+ " }\n" +
+ " }\n" +
+ " return new Inner().foo(obj);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "else_x",
+ getCompilerOptions(true));
+ }
+ public void test044() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X44.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "class Inner<T> {\n" +
+ " public boolean foo(Object obj) {\n" +
+ " if (obj instanceof Inner<?> p) {\n" +
+ " return true;\n" +
+ " }\n" +
+ " return false;\n" +
+ " }\n" +
+ "} \n" +
+ "public class X44 {\n" +
+ " public static void main(String argv[]) {\n" +
+ " Inner<String> param = new Inner<>();\n" +
+ " System.out.println(new Inner<String>().foo(param));\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true",
+ compilerOptions);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old);
+ }
+ public void test045() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X45.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X45 {\n" +
+ " String s = \"test\";\n" +
+ " boolean result = s instanceof String s1;\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(\"true\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true",
+ compilerOptions);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old);
+ }
+ public void test046() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X46.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X46 {\n" +
+ " String s = \"test\";\n" +
+ " boolean result = (s instanceof String s1 && s1 != null);\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(\"true\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "true",
+ compilerOptions);
+ compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old);
+ }
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..8714d6b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -0,0 +1,2376 @@
+/*******************************************************************************
+ * Copyright (c) 2019, 2020 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.jdt.core.ToolFactory;
+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.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class RecordsRestrictedClassTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] { "testBug560798_002" };
+ }
+
+ public static Class<?> testClass() {
+ return RecordsRestrictedClassTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_14);
+ }
+ public RecordsRestrictedClassTest(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_14); // FIXME
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return defaultOptions;
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput) {
+ runConformTest(testFiles, expectedOutput, getCompilerOptions());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
+ Runner runner = new Runner();
+ runner.testFiles = testFiles;
+ runner.expectedOutputString = expectedOutput;
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.customOptions = customOptions;
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("14");
+ runner.runConformTest();
+ }
+ @Override
+ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("14"));
+ }
+ 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("14") :
+ JavacTestOptions.forReleaseWithPreview("14", javacAdditionalTestOptions);
+ runner.runWarningTest();
+ }
+
+ private static void verifyClassFile(String expectedOutput, String classFileName, int mode)
+ throws IOException, ClassFormatException {
+ File f = new File(OUTPUT_DIR + File.separator + classFileName);
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String result = disassembler.disassemble(classFileBytes, "\n", mode);
+ int index = result.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(result, 3));
+ System.out.println("...");
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, result);
+ }
+ }
+
+ public void testBug550750_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int x, int y){\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "abstract record Point(int x, int y){\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " abstract record Point(int x, int y){\n" +
+ " ^^^^^\n" +
+ "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" +
+ "----------\n");
+ }
+ /* A record declaration is implicitly final. It is permitted for the declaration of
+ * a record type to redundantly specify the final modifier. */
+ public void testBug550750_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "final record Point(int x, int y){\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "final final record Point(int x, int y){\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " final final record Point(int x, int y){\n" +
+ " ^^^^^\n" +
+ "Duplicate modifier for the type Point\n" +
+ "----------\n");
+ }
+ public void testBug550750_005() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "final record Point(int x, int y){\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_006() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public public record X(int x, int y){\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " public public record X(int x, int y){\n" +
+ " ^\n" +
+ "Duplicate modifier for the type X\n" +
+ "----------\n");
+ }
+ public void testBug550750_007() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "final record Point(int x, int y){\n"+
+ " public void foo() {}\n"+
+ "}\n"+
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_008() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "final record Point(int x, int y){\n"+
+ " public Point {}\n"+
+ "}\n"+
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_009() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "final record Point(int x, int y){\n"+
+ " public Point {}\n"+
+ " public void foo() {}\n"+
+ "}\n"+
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}"
+ },
+ "0");
+ }
+ /* nested record implicitly static*/
+ public void testBug550750_010() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ " record Point(int x, int y){\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ /* nested record explicitly static*/
+ public void testBug550750_011() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ " static record Point(int x, int y){\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_012() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int ... x){\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_013() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "record Point(@MyAnnotation int myInt, char myChar) {}\n"+
+ " @Target({ElementType.FIELD, ElementType.TYPE})\n"+
+ " @interface MyAnnotation {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_014() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) {\n"+
+ " public int myInt(){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_015() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public int myInt(){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug550750_016() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug550750_017() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point(int myInt, char myChar){\n"+
+ " this.myInt = myInt;\n" +
+ " this.myChar = myChar;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug550750_018() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point(int myInt, char myChar){\n"+
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point(int myInt, char myChar){\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myChar may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " public Point(int myInt, char myChar){\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myInt may not have been initialized\n" +
+ "----------\n");
+ }
+ public void testBug550750_019() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " private Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myChar = myChar;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " private Point {\n" +
+ " ^^^^^\n" +
+ "The canonical constructor Point of a record declaration must be declared public.\n" +
+ "----------\n");
+ }
+ public void testBug550750_020() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " protected Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myChar = myChar;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " protected Point {\n" +
+ " ^^^^^\n" +
+ "The canonical constructor Point of a record declaration must be declared public.\n" +
+ "----------\n");
+ }
+ public void testBug550750_021() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myChar = myChar;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug550750_022() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myChar = myChar;\n" +
+ " return;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " return;\n" +
+ " ^^^^^^^\n" +
+ "The body of a compact constructor must not contain a return statement\n" +
+ "----------\n");
+ }
+ public void testBug550750_023() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int finalize) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int myInt, int finalize) implements I {\n" +
+ " ^^^^^^^^\n" +
+ "Illegal component name finalize in record Point;\n" +
+ "----------\n");
+ }
+ public void testBug550750_024() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int finalize, int myZ) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int myInt, int finalize, int myZ) implements I {\n" +
+ " ^^^^^^^^\n" +
+ "Illegal component name finalize in record Point;\n" +
+ "----------\n");
+ }
+ public void testBug550750_025() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ, int myZ) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int myInt, int myZ, int myZ) implements I {\n" +
+ " ^^^\n" +
+ "Duplicate component myZ in record\n" +
+ "----------\n");
+ }
+ public void testBug550750_026() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n" +
+ " ^^^^^\n" +
+ "Duplicate component myInt in record\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n" +
+ " ^^^^^\n" +
+ "Duplicate component myInt in record\n" +
+ "----------\n");
+ }
+ public void testBug550750_027() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " static final int z;\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " static final int z;\n" +
+ " ^\n" +
+ "The blank final field z may not have been initialized\n" +
+ "----------\n");
+ }
+ public void testBug550750_028() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " int z;\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " int z;\n" +
+ " ^\n" +
+ "User declared non-static fields z are not permitted in a record\n" +
+ "----------\n");
+ }
+ public void testBug550750_029() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " this.myZ = myZ;\n" +
+ " }\n"+
+ " public native void foo();\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " public native void foo();\n" +
+ " ^^^^^\n" +
+ "Illegal modifier native for method foo; native methods are not allowed in record\n" +
+ "----------\n");
+ }
+ public void testBug550750_030() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " {\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " {\n" +
+ " System.out.println(0);\n" +
+ " }\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Instance Initializer is not allowed in a record declaration\n" +
+ "----------\n");
+ }
+ public void testBug550750_031() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " static {\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug550750_032() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class record {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " class record {\n" +
+ " ^^^^^^\n" +
+ "Record is a restricted identifier and hence not a valid type name\n" +
+ "----------\n");
+ }
+ public void testBug550750_033() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X<record> {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " class X<record> {\n" +
+ " ^^^^^^\n" +
+ "Record is a restricted identifier and hence not a valid type name\n" +
+ "----------\n");
+ }
+ public void testBug550750_034() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ " public <record> void foo(record args){}\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " public <record> void foo(record args){}\n" +
+ " ^^^^^^\n" +
+ "Record is a restricted identifier and hence not a valid type name\n" +
+ "----------\n");
+ }
+ public void testBug550750_035() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ " public void foo(record args){}\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " public void foo(record args){}\n" +
+ " ^^^^^^\n" +
+ "record cannot be resolved to a type\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " public void foo(record args){}\n" +
+ " ^^^^^^\n" +
+ "Record is a restricted identifier and hence not a valid type name\n" +
+ "----------\n");
+ }
+ public void testBug550750_036() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " I lambda = (record r) -> {};\n"+
+ " }\n"+
+ "}\n" +
+ "interface I {\n" +
+ " public void apply(int i);\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " I lambda = (record r) -> {};\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "This lambda expression refers to the missing type record\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " I lambda = (record r) -> {};\n" +
+ " ^^^^^^\n" +
+ "record cannot be resolved to a type\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 4)\n" +
+ " I lambda = (record r) -> {};\n" +
+ " ^^^^^^\n" +
+ "Record is a restricted identifier and hence not a valid type name\n" +
+ "----------\n");
+ }
+ public void testBug550750_037() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(){\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_038() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(){\n"+
+ " public Point {}\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_039() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(){\n"+
+ " public Point() {}\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550750_040() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(){\n"+
+ " private int f;\n"+
+ " public Point() {}\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " private int f;\n" +
+ " ^\n" +
+ "User declared non-static fields f are not permitted in a record\n" +
+ "----------\n");
+ }
+ public void testBug550750_041() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(){\n"+
+ " static int f;\n"+
+ " public Point() {}\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug553152_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " public char myInt() {;\n" +
+ " return 'c';\n" +
+ " }\n"+
+ " public int getmyInt() {;\n" +
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public char myInt() {;\n" +
+ " ^^^^\n" +
+ "Illegal return type of accessor; should be the same as the declared type int of the record component\n" +
+ "----------\n");
+ }
+ public void testBug553152_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public java.lang.Integer myInt() {;\n" +
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug553152_003() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " public <T> int myInt() {;\n" +
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public <T> int myInt() {;\n" +
+ " ^^^^^^^\n" +
+ "The accessor method must not be generic\n" +
+ "----------\n");
+ }
+ public void testBug553152_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " private int myInt() {;\n" +
+ " return this.myInt;\n" +
+ " }\n"+
+ " /* package */ int myZ() {;\n" +
+ " return this.myZ;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " private int myInt() {;\n" +
+ " ^^^^^^^\n" +
+ "The accessor method must be declared public\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " /* package */ int myZ() {;\n" +
+ " ^^^^^\n" +
+ "The accessor method must be declared public\n" +
+ "----------\n");
+ }
+ public void testBug553152_005() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " public int myInt() throws Exception {;\n" +
+ " return this.myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public int myInt() throws Exception {;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Throws clause not allowed for explicitly declared accessor method\n" +
+ "----------\n");
+ }
+ public void testBug553152_006() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug553152_007() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point(Integer myInt, int myZ) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myZ may not have been initialized\n" +
+ "----------\n");
+ }
+ public void testBug553152_008() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point {\n" +
+ " ^^^^^\n" +
+ "Duplicate method Point(Integer, int) in type Point\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " public Point(Integer myInt, int myZ) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate method Point(Integer, int) in type Point\n" +
+ "----------\n");
+ }
+ public void testBug553152_009() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " Point(Integer myInt, int myZ) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The canonical constructor Point of a record declaration must be declared public.\n" +
+ "----------\n");
+ }
+ public void testBug553152_010() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public <T> Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public <T> Point(Integer myInt, int myZ) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Canonical constructor Point of a record declaration should not be generic\n" +
+ "----------\n");
+ }
+ public void testBug553152_011() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) throws Exception {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point(Integer myInt, int myZ) throws Exception {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Throws clause not allowed for canonical constructor Point\n" +
+ "----------\n");
+ }
+ public void testBug553152_012() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " return;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " return;\n" +
+ " ^^^^^^^\n" +
+ "The body of a compact constructor must not contain a return statement\n" +
+ "----------\n");
+ }
+ public void testBug553152_013() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " I i = () -> { return;};\n" +
+ " Zork();\n" +
+ " }\n"+
+ " public void apply() {}\n" +
+ "}\n" +
+ "interface I { void apply();}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type Point\n" +
+ "----------\n");
+ }
+ public void testBug553152_014() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " super();\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " super();\n" +
+ " ^^^^^^^^\n" +
+ "The body of a canonical constructor must not contain an explicit constructor call\n" +
+ "----------\n");
+ }
+ public void testBug553152_015() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point(Integer myInt, int myZ) {\n" +
+ " this.Point(0);\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ " public Point(Integer myInt) {}\n" +
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " this.Point(0);\n" +
+ " ^^^^^\n" +
+ "The method Point(int) is undefined for the type Point\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 12)\n" +
+ " public Point(Integer myInt) {}\n" +
+ " ^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myInt may not have been initialized\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 12)\n" +
+ " public Point(Integer myInt) {}\n" +
+ " ^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myZ may not have been initialized\n" +
+ "----------\n");
+ }
+ public void testBug553152_016() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(Integer myInt, int myZ) implements I {\n"+
+ " public Point {\n" +
+ " super();\n" +
+ " this.myInt = 0;\n" +
+ " this.myZ = 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " super();\n" +
+ " ^^^^^^^^\n" +
+ "The body of a compact constructor must not contain an explicit constructor call\n" +
+ "----------\n");
+ }
+ public void testBug553152_017() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public class Inner {\n"+
+ " record Point(int myInt, char myChar) {}\n"+
+ " }\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " record Point(int myInt, char myChar) {}\n" +
+ " ^^^^^\n" +
+ "Nested Record is (implicitly) static and hence enclosing type should be static\n" +
+ "----------\n");
+ }
+ public void _testBug553152_018() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) {}\n"+
+ " @Target({ElementType.FIELD, ElementType.TYPE})\n"+
+ " @interface MyAnnotation {}\n"
+ },
+ "0");
+ }
+ public void testBug553152_019() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, int myZ) implements I {\n"+
+ " public static int myInt() {;\n" +
+ " return 0;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public static int myInt() {;\n" +
+ " ^^^^^^^\n" +
+ "The accessor method must not be static\n" +
+ "----------\n");
+ }
+public void testBug553153_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+ }
+ public void testBug553153_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " if (this.myInt > 0) // conditional assignment\n" +
+ " this.myChar = myChar;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point {\n" +
+ " ^^^^^\n" +
+ "The blank final field myChar may not have been initialized\n" +
+ "----------\n");
+}
+public void testBug553153_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " static int f;\n"+
+ " public Point {\n"+
+ " this.myInt = myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "0");
+}
+public void testBug553153_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"+
+ "record Point(int myInt, char myChar) implements I {\n"+
+ " public Point(int myInt, char myChar) {\n"+
+ " this.myInt = myInt;\n" +
+ " }\n"+
+ "}\n" +
+ "interface I {}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public Point(int myInt, char myChar) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The blank final field myChar may not have been initialized\n" +
+ "----------\n");
+}
+public void testBug558069_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "private record Point(){\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " private record Point(){\n" +
+ " ^^^^^\n" +
+ "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" +
+ "----------\n");
+}
+public void testBug558069_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "private record Point(){\n"+
+ "}\n" +
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558069_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "private record Point(int myInt){\n"+
+ "}\n" +
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558343_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "private record Point(int myInt){\n"+
+ " @Override\n"+
+ " public boolean equals(Object obj){\n"+
+ " return false;\n" +
+ " }\n"+
+ "}\n" +
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558343_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "private record Point(int myInt){\n"+
+ " @Override\n"+
+ " public int hashCode(){\n"+
+ " return java.util.Arrays.hashCode(new int[]{Integer.valueOf(this.myInt).hashCode()});\n" +
+ " }\n"+
+ "}\n" +
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558343_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n" +
+ "record Point(int myInt){\n"+
+ " @Override\n"+
+ " public String toString(){\n"+
+ " return \"Point@1\";\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558343_004() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(new Point(0).myInt());\n" +
+ " }\n"+
+ "}\n" +
+ "record Point(int myInt){\n"+
+ " @Override\n"+
+ " public String toString(){\n"+
+ " return \"Point@1\";\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558494_001() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(new Point(0).heyPinkCity());\n" +
+ " }\n"+
+ "}\n" +
+ "record Point(int heyPinkCity){\n"+
+ " @Override\n"+
+ " public String toString(){\n"+
+ " return \"Point@1\";\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ String expectedOutput = "Record: #Record\n" +
+ "Components:\n" +
+ " \n" +
+ "// Component descriptor #6 I\n" +
+ "int heyPinkCity;\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug558494_002() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(new Point().toString());\n" +
+ " }\n"+
+ "}\n" +
+ "record Point(){\n"+
+ " @Override\n"+
+ " public String toString(){\n"+
+ " return \"Point@1\";\n" +
+ " }\n"+
+ "}\n"
+ },
+ "Point@1");
+ String expectedOutput = "Record: #Record\n" +
+ "Components:\n" +
+ " \n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug558494_003() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "record Forts(String...wonders){\n"+
+ "}\n"+
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " Forts p = new Forts(new String[] {\"Amber\", \"Nahargarh\", \"Jaigarh\"});\n"+
+ " if (!p.toString().startsWith(\"Forts[wonders=[Ljava.lang.String;@\"))\n"+
+ " System.out.println(\"Error\");\n"+
+ " }\n"+
+ "}\n"
+ },
+ "");
+ String expectedOutput = "Record: #Record\n" +
+ "Components:\n" +
+ " \n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug558494_004() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "record Forts(int x, String[] wonders){\n"+
+ "}\n"+
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " Forts p = new Forts(3, new String[] {\"Amber\", \"Nahargarh\", \"Jaigarh\"});\n"+
+ " if (!p.toString().startsWith(\"Forts[x=3, wonders=[Ljava.lang.String;@\"))\n"+
+ " System.out.println(\"Error\");\n"+
+ " }\n"+
+ "}\n"
+ },
+ "");
+ String expectedOutput =
+ "Record: #Record\n" +
+ "Components:\n" +
+ " \n" +
+ "// Component descriptor #6 I\n" +
+ "int x;\n" +
+ "// Component descriptor #8 [Ljava/lang/String;\n" +
+ "java.lang.String[] wonders;\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug558764_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "record Point(@MyAnnotation int myInt, char myChar) {}\n"+
+ " @Target({ElementType.FIELD})\n"+
+ " @interface MyAnnotation {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558764_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "record Point(@MyAnnotation int myInt, char myChar) {}\n"+
+ " @Target({ElementType.TYPE})\n"+
+ " @interface MyAnnotation {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " record Point(@MyAnnotation int myInt, char myChar) {}\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The annotation @MyAnnotation is disallowed for this location\n" +
+ "----------\n");
+}
+public void testBug558764_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "record Point(@MyAnnotation int myInt, char myChar) {}\n"+
+ " @Target({ElementType.RECORD_COMPONENT})\n"+
+ " @interface MyAnnotation {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug558764_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "record Point(@MyAnnotation int myInt, char myChar) {}\n"+
+ " @Target({ElementType.RECORD_COMPONENT})\n"+
+ " @interface MyAnnotation {}\n" +
+ "class X {\n"+
+ " public @MyAnnotation String f = \"hello\";\n" +
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " public @MyAnnotation String f = \"hello\";\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The annotation @MyAnnotation is disallowed for this location\n" +
+ "----------\n");
+}
+public void testBug553567_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X extends Record{\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " class X extends Record{\n" +
+ " ^^^^^^\n" +
+ "The type X may not subclass Record explicitly\n" +
+ "----------\n");
+}
+public void testBug553567_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n" +
+ "class Record {\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug559281_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record X(void k) {}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " record X(void k) {}\n" +
+ " ^\n" +
+ "void is an invalid type for the component k of a record\n" +
+ "----------\n");
+}
+public void testBug559281_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record X(int clone, int wait) {}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " record X(int clone, int wait) {}\n" +
+ " ^^^^^\n" +
+ "Illegal component name clone in record X;\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 1)\n" +
+ " record X(int clone, int wait) {}\n" +
+ " ^^^^\n" +
+ "Illegal component name wait in record X;\n" +
+ "----------\n");
+}
+public void testBug559448_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int x, int... y){\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug559448_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int... x, int y){\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int... x, int y){\n" +
+ " ^\n" +
+ "The variable argument type int of the record Point must be the last parameter\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " record Point(int... x, int y){\n" +
+ " ^\n" +
+ "The variable argument type int of the method Point must be the last parameter\n" +
+ "----------\n");
+}
+public void testBug559448_003() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point(int... x, int... y){\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record Point(int... x, int... y){\n" +
+ " ^\n" +
+ "The variable argument type int of the record Point must be the last parameter\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " record Point(int... x, int... y){\n" +
+ " ^\n" +
+ "The variable argument type int of the method Point must be the last parameter\n" +
+ "----------\n");
+}
+public void testBug559574_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record X(int x, int XX3) {\n"+
+ " public XX3 {}\n"+
+ " public XX3(int x, int y, int z) {\n"+
+ " this.x = x;\n"+
+ " this.y = y;\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public XX3 {}\n" +
+ " ^^^\n" +
+ "Return type for the method is missing\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 3)\n" +
+ " public XX3(int x, int y, int z) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Return type for the method is missing\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 3)\n" +
+ " public XX3(int x, int y, int z) {\n" +
+ " ^\n" +
+ "The parameter x is hiding a field from type X\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 5)\n" +
+ " this.y = y;\n" +
+ " ^\n" +
+ "y cannot be resolved or is not a field\n" +
+ "----------\n");
+}
+public void testBug559992_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record R() {\n"+
+ " public R throws Exception {\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public R throws Exception {\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Throws clause not allowed for canonical constructor R\n" +
+ "----------\n");
+}
+public void testBug559992_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record R() {\n"+
+ " public R() throws Exception {\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public R() throws Exception {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^\n" +
+ "Throws clause not allowed for canonical constructor R\n" +
+ "----------\n");
+}
+public void testBug560256_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "final protected record Point(int x, int y){\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " final protected record Point(int x, int y){\n" +
+ " ^^^^^\n" +
+ "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" +
+ "----------\n");
+}
+public void testBug560256_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "native record Point(int x, int y){\n"+
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " native record Point(int x, int y){\n" +
+ " ^^^^^\n" +
+ "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" +
+ "----------\n");
+}
+public void testBug560256_003() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " class Inner {\n"+
+ " record Point(int x, int y){}\n"+
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " record Point(int x, int y){}\n" +
+ " ^^^^^\n" +
+ "Nested Record is (implicitly) static and hence enclosing type should be static\n" +
+ "----------\n");
+}
+public void testBug560256_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static class Inner {\n"+
+ " native record Point(int x, int y){}\n"+
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " native record Point(int x, int y){}\n" +
+ " ^^^^^\n" +
+ "Illegal modifier for the record Point; only public, private, protected, static, final and strictfp are permitted\n" +
+ "----------\n");
+}
+public void testBug560531_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record Point<T>(T t){\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug560531_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"+
+ "record R <T extends Integer, S extends String> (int x, T t, S s){\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug560569_001() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "interface Rentable { int year(); }\n"+
+ "record Car(String model, int year) implements Rentable {\n"+
+ " public Car {\n"+
+ " }\n"+
+ " public String toString() {\n"+
+ " return model + \" \" + year;\n"+
+ " }\n"+
+ "}\n"+
+ "record Camel(int year) implements Rentable { }\n"+
+ "\n"+
+ "class X {\n"+
+ " String model;\n"+
+ " int year;\n"+
+ " public String toString() {\n"+
+ " return model + \" \" + year;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " Car car = new Car(\"Maruti\", 2000);\n"+
+ " System.out.println(car.hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+ String expectedOutput =
+ "Bootstrap methods:\n" +
+ " 0 : # 68 invokestatic java/lang/runtime/ObjectMethods.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/TypeDescriptor;Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/invoke/MethodHandle;)Ljava/lang/Object;\n" +
+ " Method arguments:\n" +
+ " #1 Car\n" +
+ " #69 model;year\n" +
+ " #71 REF_getField model:Ljava/lang/String;\n" +
+ " #72 REF_getField year:I\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Car.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug560496_001() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "record R () {} \n"+
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R().hashCode());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ String expectedOutput =
+ "public final int hashCode();\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug560496_002() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "strictfp record R () {} \n"+
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R().hashCode());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ String expectedOutput =
+ "public final strictfp int hashCode();\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug560797_001() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "strictfp record R (int x, int y) {} \n"+
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+ String expectedOutput =
+ "public strictfp int x();\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug560797_002() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "strictfp record R (int x, int y) { \n"+
+ "public int x() { return this.x;}\n"+
+ "}\n"+
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+ String expectedOutput =
+ "public strictfp int x();\n";
+ RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void testBug560798_001() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "@Target({ElementType.PARAMETER})\n"+
+ "@interface MyAnnot {}\n"+
+ "record R(@MyAnnot() int i, int j) {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+}
+public void testBug560798_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "@Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE,\n" +
+ " ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE, ElementType.TYPE_PARAMETER})\n"+
+ "@interface MyAnnot {}\n"+
+ "record R(@MyAnnot() int i, int j) {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record R(@MyAnnot() int i, int j) {}\n" +
+ " ^^^^^^^^\n" +
+ "The annotation @MyAnnot is disallowed for this location\n" +
+ "----------\n");
+}
+public void testBug560798_003() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "@Target({ElementType.METHOD})\n"+
+ "@interface MyAnnot {}\n"+
+ "record R(@MyAnnot() int i, int j) {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+}
+public void testBug560798_004() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "@Target({ElementType.RECORD_COMPONENT})\n"+
+ "@interface MyAnnot {}\n"+
+ "record R(@MyAnnot() int i, int j) {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+}
+public void testBug560798_005() throws Exception {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n"+
+ "import java.lang.annotation.ElementType;\n"+
+ "@Target({ElementType.TYPE_USE})\n"+
+ "@interface MyAnnot {}\n"+
+ "record R(@MyAnnot() int i, int j) {}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new R(100, 200).hashCode() != 0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "true");
+}
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public void testBug560770_001() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "record R() {}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " record R() {}\n" +
+ " ^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n",
+ null,
+ true,
+ options
+ );
+}
+public void testBug560893_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "interface I{\n"+
+ "record R(int x, int y) {}\n"+
+ "}\n" +
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug560893_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " record R(int x, int y) {}\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+}
+public void testBug560893_003() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " record R(int x, int y) {}\n"+
+ " R r = new R(100,200);\n"+
+ " System.out.println(r.x());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "100");
+}
+public void testBug560893_004() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " record R(int x, int y) {\n"+
+ " static int i;\n"+
+ " }\n"+
+ " R r = new R(100,200);\n"+
+ " System.out.println(r.x());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "100");
+}
+public void testBug560893_005() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " record R(int x, int y) {\n"+
+ " static int i;\n"+
+ " public void ff() {\n"+
+ " int jj;\n"+
+ " }\n"+
+ " static int ii;\n"+
+ " }\n"+
+ " R r = new R(100,200);\n"+
+ " System.out.println(r.x());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "100");
+}
+public void testBug560893_006() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " static record R(int x, int y) {}\n"+
+ " R r = new R(100,200);\n"+
+ " System.out.println(r.x());\n"+
+ " }\n"+
+ "}\n"
+ },
+ "100");
+}
+public void testBug560893_007() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " static int si;\n"+
+ " int nsi;\n"+
+ "\n"+
+ " void m() {\n"+
+ " int li;\n"+
+ "\n"+
+ " record R(int r) {\n"+
+ " void print() {\n"+
+ " System.out.println(li); // error, local variable\n"+
+ " System.out.println(nsi); // error, non-static member\n"+
+ " System.out.println(si); // ok, static member of enclosing class\n"+
+ " }\n"+
+ " }\n"+
+ " R r = new R(10);\n"+
+ " }\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " System.out.println(li); // error, local variable\n" +
+ " ^^\n" +
+ "Cannot make a static reference to the non-static variable li from a local record\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " System.out.println(nsi); // error, non-static member\n" +
+ " ^^^\n" +
+ "Cannot make a static reference to the non-static field nsi\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/RepeatableAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java
index d31d6f7..2fe3168 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2016 Jesper S Moller and others.
+ * Copyright (c) 2013, 2020 Jesper S Moller and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -38,9 +38,27 @@
// TESTS_NUMBERS = new int[] { 297 };
// TESTS_RANGE = new int[] { 294, -1 };
}
-
+ boolean isJRE14 = false;
public RepeatableAnnotationTest(String name) {
super(name);
+ String javaVersion = System.getProperty("java.version");
+ int index = javaVersion.indexOf('.');
+ if (index != -1) {
+ javaVersion = javaVersion.substring(0, index);
+ } else {
+ index = javaVersion.indexOf('-');
+ if (index != -1)
+ javaVersion = javaVersion.substring(0, index);
+ }
+ this.isJRE14 = Integer.parseInt(javaVersion) >= 14;
+ }
+ private String normalizeAnnotationString(String s) {
+ if (!this.isJRE14) return s;
+ if (s.indexOf("value=") != -1) {
+ s = s.replace("value=[", "{");
+ s = s.replace("value=", "");
+ }
+ return s;
}
public static Test suite() {
@@ -875,7 +893,7 @@
" }\n" +
"}"
},
- "@Attr(value=1) @Attr(value=2)");
+ normalizeAnnotationString("@Attr(value=1) @Attr(value=2)"));
}
// 412149: [1.8][compiler] Emit repeated annotations into the designated container
@@ -917,10 +935,10 @@
" }\n" +
"}"
},
- "Y1: @Attr(value=1)\n" +
+ normalizeAnnotationString("Y1: @Attr(value=1)\n" +
"Y2: null\n" +
"Y1: null\n" +
- "Y2: @AttrContainer(value=[@Attr(value=1), @Attr(value=2)])");
+ "Y2: @AttrContainer(value=[@Attr(value=1), @Attr(value=2)])"));
}
// 412149: [1.8][compiler] Emit repeated annotations into the designated container
@@ -1040,7 +1058,8 @@
" }\n" +
"}"
},
- "@Attr(value=1) @Attr(value=2) @Attr(value=3) @Attr(value=4) @Attr(value=5) @Attr(value=6)");
+ normalizeAnnotationString(
+ "@Attr(value=1) @Attr(value=2) @Attr(value=3) @Attr(value=4) @Attr(value=5) @Attr(value=6)"));
}
// Test that repeated annotations show up type parameters properly.
public void testTypeParameters() {
@@ -1116,7 +1135,7 @@
"}\n"
},
- "K.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" +
+ normalizeAnnotationString("K.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" +
"K.getAnnotation(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" +
"K.getAnnotationByType(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" +
"java.lang.Object.getAnnotationByType(T.class): @T(value=3) @T(value=4) \n" +
@@ -1124,7 +1143,7 @@
"java.lang.Object.getAnnotationByType(TC.class): @TC(value=[@T(value=3), @T(value=4)]) \n" +
"java.lang.Comparable<?>.getAnnotationByType(T.class): @T(value=5) @T(value=6) \n" +
"java.lang.Comparable<?>.getAnnotation(TC.class): @TC(value=[@T(value=5), @T(value=6)]) \n" +
- "java.lang.Comparable<?>.getAnnotationByType(TC.class): @TC(value=[@T(value=5), @T(value=6)])",
+ "java.lang.Comparable<?>.getAnnotationByType(TC.class): @TC(value=[@T(value=5), @T(value=6)])"),
null,
true,
new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution.
@@ -1262,7 +1281,7 @@
"}\n"
},
- "Class: X.class.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" +
+ normalizeAnnotationString("Class: X.class.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" +
"Class: X.class.getAnnotation(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" +
"Class: X.class.getAnnotationByType(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" +
"Type Parameter: K.getAnnotationByType(T.class): @T(value=3) @T(value=4) \n" +
@@ -1315,7 +1334,7 @@
"Exception type: .getAnnotationByType(TC.class): @TC(value=[@T(value=33), @T(value=34)]) \n" +
"Constructor: .getAnnotationByType(T.class): @T(value=35) @T(value=36) \n" +
"Constructor: .getAnnotation(TC.class): @TC(value=[@T(value=35), @T(value=36)]) \n" +
- "Constructor: .getAnnotationByType(TC.class): @TC(value=[@T(value=35), @T(value=36)])",
+ "Constructor: .getAnnotationByType(TC.class): @TC(value=[@T(value=35), @T(value=36)])"),
null,
true,
new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution.
@@ -1428,29 +1447,15 @@
" ^^\n" +
"The type TC is deprecated\n" +
"----------\n" +
- "2. ERROR in T.java (at line 5)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "3. WARNING in T.java (at line 5)\n" +
+ "2. WARNING in T.java (at line 5)\n" +
" interface I<@T(1) @T(2) K> {\n" +
" ^^\n" +
"The type TC is deprecated\n" +
- "----------\n" +
- "4. ERROR in T.java (at line 5)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "5. ERROR in T.java (at line 5)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
"----------\n");
}
public void testDeprecation2() { // verify that deprecation warning does not show up when the deprecated element is used in the same file defining it.
- this.runNegativeTest(
+ // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435
+ this.runConformTest(
new String[] {
"T.java",
"@Deprecated\n" +
@@ -1464,22 +1469,7 @@
"interface I<@T(1) @T(2) K> {\n" +
"}\n"
},
- "----------\n" +
- "1. ERROR in T.java (at line 9)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "2. ERROR in T.java (at line 9)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n" +
- "3. ERROR in T.java (at line 9)\n" +
- " interface I<@T(1) @T(2) K> {\n" +
- " ^^\n" +
- "Annotation types that do not specify explicit target element types cannot be applied here\n" +
- "----------\n");
+ "");
}
// 419209: [1.8] Repeating container annotations should be rejected in the presence of annotation it contains
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
index d28869f..63d5e69 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
@@ -5564,7 +5564,7 @@
runner.runConformTest();
}
public void testBug542707_001() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // uses switch expression
+ if (!checkPreviewAllowed()) return; // uses switch expression
Map options = getCompilerOptions();
options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
@@ -5616,7 +5616,7 @@
options);
}
public void testBug542707_002() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // uses switch expression
+ if (this.complianceLevel < ClassFileConstants.JDK14) return; // uses switch expression
Map options = getCompilerOptions();
options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
@@ -5674,7 +5674,7 @@
options);
}
public void testBug542707_003() {
- if (this.complianceLevel < ClassFileConstants.JDK13) return; // uses switch expression
+ if (!checkPreviewAllowed()) return; // uses switch expression
Map options = getCompilerOptions();
options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR);
@@ -6454,4 +6454,97 @@
"----------\n",
options);
}
+public void testBug560610() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses enum
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING);
+ runConformTest(
+ new String[] {
+ "A.java",
+ "import java.util.EnumSet;\n" +
+ "public abstract class A<T> extends B<T> implements C<D> {\n" +
+ " void m(EnumSet<EN> en) {}\n" + // unResolvedMethods() when a is seen as a PTB causes bogus resolving of this method
+ "}\n",
+ "B.java",
+ "public abstract class B<U> implements AutoCloseable {}\n", // this causes A to be seen as a resource requiring closer inspection
+ "C.java",
+ "public interface C<T> {}\n", // just so we can read D as a type argument during hierarchy connecting for A
+ "D.java",
+ "public abstract class D extends A<String> {}\n", // extends A causes searching A for a close method, A seen as a PTB
+ "EN.java",
+ "public enum EN {\n" + // when we find this via ahead-of-time resolveTypesFor("m()") we don't yet have a superclass
+ " One, Two;\n" +
+ "}\n"
+ },
+ "",
+ options);
+}
+public void testBug560671() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses t-w-r
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.Scanner;\n" +
+ "public class X {\n" +
+ " void m(String source) {\n" +
+ " try (Scanner s = new Scanner(source).useDelimiter(\"foobar\")) {\n" +
+ " System.out.println(s.next());\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ options);
+}
+public void testBug560671b() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.Scanner;\n" +
+ "public class X {\n" +
+ " void m(String source) throws java.io.IOException {\n" +
+ " Scanner s = null;" +
+ " try {\n" +
+ " s = new Scanner(source).useDelimiter(\"foobar\");\n" +
+ " System.out.println(s.next());\n" +
+ " } finally {\n" +
+ " if (s != null) s.close();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ options);
+}
+public void testBug561259() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.io.*;\n" +
+ "public class X {\n" +
+ " protected String m(String charset) throws IOException\n" +
+ " {\n" +
+ " InputStream contents = new FileInputStream(\"/tmp/f\");\n" +
+ " BufferedReader reader = new BufferedReader(new InputStreamReader(contents, charset));\n" +
+ " CharArrayWriter writer = new CharArrayWriter();\n" +
+ " int c;\n" +
+ " while ((c = reader.read()) != -1)\n" +
+ " {\n" +
+ " writer.write(c);\n" +
+ " }\n" +
+ " contents.close();\n" +
+ " return writer.toString();\n" +
+ " }\n" +
+ "}\n"
+ },
+ options);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
index 32efd3c..2fb51c6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -78,7 +78,7 @@
"1. ERROR in X.java (at line 0)\n" +
" public class X {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.VERSION_12+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n");
}
public void testSwitchExpression_531714_002() {
@@ -115,7 +115,7 @@
"1. ERROR in X.java (at line 0)\n" +
" public class X {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.VERSION_12+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n");
}
public void _testBug531714_error_003() {
@@ -509,7 +509,7 @@
"1. ERROR in X.java (at line 0)\n" +
" public class X {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 11, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.VERSION_11+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n";
this.runNegativeTest(
testFiles,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java
index 74f08d4..52839b6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java
@@ -14,6 +14,7 @@
import java.util.Map;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -25,31 +26,31 @@
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "testBug550861_01" };
+// TESTS_NAMES = new String[] { "testBug552764" };
}
public static Class<?> testClass() {
return SwitchExpressionsYieldTest.class;
}
public static Test suite() {
- return buildMinimalComplianceTestSuite(testClass(), F_13);
+ return buildMinimalComplianceTestSuite(testClass(), F_14);
}
public SwitchExpressionsYieldTest(String testName){
super(testName);
}
// Enables the tests to run individually
- protected Map<String, String> getCompilerOptions() {
+ protected Map<String, String> _getCompilerOptions() {
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13); // FIXME
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
return defaultOptions;
}
protected void runConformTestWithJavac(String[] testFiles, String expectedOutput) {
- runConformTest(testFiles, expectedOutput, getCompilerOptions(), new String[] {"--enable-preview"});
+ runConformTest(testFiles, expectedOutput, _getCompilerOptions(), new String[] {"--enable-preview"}, new JavacTestOptions("-source 14 --enable-preview"));
}
@Override
@@ -65,12 +66,12 @@
runner.expectedOutputString = expectedOutput;
runner.vmArguments = new String[] {"--enable-preview"};
runner.customOptions = customOptions;
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("13");
+ runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(JavaCore.VERSION_14);
runner.runConformTest();
}
@Override
protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
- runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("13"));
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview(JavaCore.VERSION_14));
}
protected void runWarningTest(String[] testFiles, String expectedCompilerLog) {
runWarningTest(testFiles, expectedCompilerLog, null);
@@ -86,8 +87,8 @@
runner.expectedCompilerLog = expectedCompilerLog;
runner.customOptions = customOptions;
runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("13") :
- JavacTestOptions.forReleaseWithPreview("13", javacAdditionalTestOptions);
+ runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview(JavaCore.VERSION_14) :
+ JavacTestOptions.forReleaseWithPreview(JavaCore.VERSION_14, javacAdditionalTestOptions);
runner.runWarningTest();
}
public void testBug544073_000() {
@@ -127,7 +128,7 @@
" };\n" +
" return tw;\n" +
" }\n" +
- " public static void main(String... args) {\n" +
+ " public static void main(String[] args) {\n" +
" System.out.print(twice(3));\n" +
" }\n" +
"}\n"
@@ -321,7 +322,8 @@
},
"100");
}
- public void testBug544073_008() {
+ // switch expressions graduated from preview to standard and hence the following test not relevant anymore
+ public void _testBug544073_008() {
Map<String, String> disablePreviewOptions = getCompilerOptions();
disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
String[] testFiles = new String[] {
@@ -418,18 +420,18 @@
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" case 0 -> i * 0;\n" +
- " ^^^^^^\n" +
- "Case Labels with \'->\' is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ " ^^^^^\n" +
+ "Invalid expression as statement\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" case 1 -> 2;\n" +
- " ^^^^^^\n" +
- "Case Labels with \'->\' is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ " ^\n" +
+ "Invalid expression as statement\n" +
"----------\n" +
"3. ERROR in X.java (at line 6)\n" +
" default -> 3;\n" +
- " ^^^^^^^\n" +
- "Case Labels with \'->\' is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ " ^\n" +
+ "Invalid expression as statement\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -461,11 +463,6 @@
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" default -> 3;\n" +
- " ^^^^^^^\n" +
- "You are using a preview language feature that may or may not be supported in a future release\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 4)\n" +
- " default -> 3;\n" +
" ^\n" +
"Invalid expression as statement\n" +
"----------\n";
@@ -531,7 +528,7 @@
"1. ERROR in X.java (at line 0)\n" +
" public class X {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 11, preview can be enabled only at source level 13\n" +
+ "Preview features enabled at an invalid source release level "+CompilerOptions.VERSION_11+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2202,11 +2199,6 @@
"----------\n" +
"1. WARNING in X.java (at line 5)\n" +
" case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\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 \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
" ^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n";
@@ -2250,7 +2242,8 @@
},
message);
}
- public void testBug544073_073() {
+ // multi-constant case has graduated from preview to standard - this test is no longer relevant
+ public void _testBug544073_073() {
if (this.complianceLevel < ClassFileConstants.JDK1_8)
return;
Map<String, String> options = getCompilerOptions();
@@ -2545,10 +2538,10 @@
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 4)\n" +
+ "1. ERROR in X.java (at line 4)\n" +
" yield();\n" +
" ^^^^^^^\n" +
- "yield may be disallowed in future - qualify method calls to avoid this message\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" Zork();\n" +
@@ -2608,10 +2601,10 @@
" ^^^^^\n" +
"Syntax error on token \"yield\", AssignmentOperator expected after this token\n" +
"----------\n" +
- "2. WARNING in X.java (at line 7)\n" +
+ "2. ERROR in X.java (at line 7)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2661,20 +2654,20 @@
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" yield y;\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 7)\n" +
+ "3. ERROR in X.java (at line 7)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2724,20 +2717,20 @@
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" yield y = null;\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 7)\n" +
+ "3. ERROR in X.java (at line 7)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2784,10 +2777,10 @@
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "2. WARNING in X.java (at line 6)\n" +
+ "2. ERROR in X.java (at line 6)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2837,20 +2830,20 @@
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" new yield();\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 7)\n" +
+ "3. ERROR in X.java (at line 7)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -2900,20 +2893,20 @@
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 3)\n" +
+ "1. ERROR in X.java (at line 3)\n" +
" yield[] y;\n" +
" ^^^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" Zork();\n" +
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
"----------\n" +
- "3. WARNING in X.java (at line 7)\n" +
+ "3. ERROR in X.java (at line 7)\n" +
" class yield {\n" +
" ^^^^^\n" +
- "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -3543,6 +3536,274 @@
},
"0");
}
+ public void testBug552764_001() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " switch (i) {\n" +
+ " default -> 3;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " default -> 3;\n" +
+ " ^^^^^^^\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug552764_002() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " return switch (i) {\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return switch (i) {\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Switch Expressions are supported from Java 14 onwards only\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " default -> 3;\n" +
+ " ^^^^^^^\n" +
+ "Arrow in case statement supported from Java 14 onwards only\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug552764_003() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 2 : break;\n" +
+ " default : break;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1, 2 : break;\n" +
+ " ^^^^^^^^^\n" +
+ "Multi-constant case labels supported from Java 14 onwards only\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug558067_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(int i, int e) {\n"+
+ " LABEL: while (i == 0) {\n"+
+ " i = switch (e) {\n"+
+ " case 0 : {\n"+
+ " for (;;) {\n"+
+ " break LABEL; // NO error flagged\n"+
+ " }\n"+
+ " yield 1;\n"+
+ " }\n"+
+ " default : yield 2;\n"+
+ " };\n"+
+ " }\n"+
+ " return i;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " new X().foo(0, 1);\n"+
+ " }\n"+
+ "}\n"
+ }, "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " break LABEL; // NO error flagged\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Breaking out of switch expressions not permitted\n" +
+ "----------\n");
+ }
+ public void testBug558067_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(int i, int e) {\n"+
+ " TOP:System.out.println(\"hello\");\n"+
+ " int x = switch(i) {\n"+
+ " case 0:\n"+
+ " LABEL: while (i == 0) {\n"+
+ " i = switch (e) {\n"+
+ " case 0 : {\n"+
+ " for (;;) {\n"+
+ " break LABEL;\n"+
+ " }\n"+
+ " yield 1;\n"+
+ " }\n"+
+ " default : yield 2;\n"+
+ " };\n"+
+ " }\n"+
+ " case 2: for(;;) break TOP;\n"+
+ " default: yield 0;\n"+
+ " };\n"+
+ " return i;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " new X().foo(0, 1);\n"+
+ " }\n"+
+ "} \n"
+ }, "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " break LABEL;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Breaking out of switch expressions not permitted\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 17)\n" +
+ " case 2: for(;;) break TOP;\n" +
+ " ^^^^^^^^^^\n" +
+ "Breaking out of switch expressions not permitted\n" +
+ "----------\n");
+ }
+ public void testBug558067_003() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(int i, int e) {\n"+
+ " LABEL: while (i == 0) {\n"+
+ " i = switch (e) {\n"+
+ " case 0 : {\n"+
+ " for (;;) {\n"+
+ " continue LABEL;\n"+
+ " }\n"+
+ " yield 1;\n"+
+ " }\n"+
+ " default : yield 2;\n"+
+ " };\n"+
+ " }\n"+
+ " return i;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " new X().foo(0, 1);\n"+
+ " }\n"+
+ "}\n"
+ }, "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " continue LABEL;\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Continue out of switch expressions not permitted\n" +
+ "----------\n");
+ }
+ public void testBug558067_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(int i, int e) {\n"+
+ " LABEL: while (i == 0) {\n"+
+ " i = switch (e) {\n"+
+ " case 0 : {\n"+
+ " switch(e) {\n"+
+ " case 0 : {\n"+
+ " break LABEL;\n"+
+ " }\n"+
+ " }\n"+
+ " yield 1;\n"+
+ " }\n"+
+ " default : yield 2;\n"+
+ " };\n"+
+ " }\n"+
+ " return i;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " new X().foo(0, 1);\n"+
+ " }\n"+
+ "}\n"
+ }, "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " break LABEL;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Breaking out of switch expressions not permitted\n" +
+ "----------\n");
+ }
+ public void testBug558067_005() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public int foo(int i, int e) {\n"+
+ " LABEL: while (i == 0) {\n"+
+ " i = switch (e) {\n"+
+ " case 0 : {\n"+
+ " switch(e) {\n"+
+ " case 0 : {\n"+
+ " continue LABEL;\n"+
+ " }\n"+
+ " }\n"+
+ " yield 1;\n"+
+ " }\n"+
+ " default : yield 2;\n"+
+ " };\n"+
+ " }\n"+
+ " return i;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " new X().foo(0, 1);\n"+
+ " }\n"+
+ "}\n"
+ }, "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " continue LABEL;\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Continue out of switch expressions not permitted\n" +
+ "----------\n");
+ }
public void testConversion1() {
runConformTestWithJavac(
new String[] {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index cfe6b0d..de9009b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
@@ -3114,7 +3114,7 @@
"1. ERROR in X.java (at line 5)\n" +
" case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "Multi-constant case labels supported from Java 14 onwards only\n" +
"----------\n";
this.runNegativeTest(new String[] {
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 a8957c7..17742ec 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -191,9 +191,14 @@
// add 13 specific test here (check duplicates)
ArrayList since_13 = new ArrayList();
- since_13.add(SwitchExpressionsYieldTest.class);
since_13.add(Unicode12_1Test.class);
+ // add 14 specific test here (check duplicates)
+ ArrayList since_14 = new ArrayList();
+ since_14.add(SwitchExpressionsYieldTest.class);
+ since_14.add(RecordsRestrictedClassTest.class);
+ since_14.add(PatternMatching14Test.class);
+
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
all.addTest(new TestSuite(StandAloneASTParserTest.class));
@@ -320,6 +325,22 @@
TestCase.resetForgottenFilters(tests_13);
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13), tests_13));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_14) != 0) {
+ ArrayList tests_14 = (ArrayList)standardTests.clone();
+ tests_14.addAll(since_1_4);
+ tests_14.addAll(since_1_5);
+ tests_14.addAll(since_1_6);
+ tests_14.addAll(since_1_7);
+ tests_14.addAll(since_1_8);
+ tests_14.addAll(since_9);
+ tests_14.addAll(since_10);
+ tests_14.addAll(since_11);
+ tests_14.addAll(since_12);
+ tests_14.addAll(since_13);
+ tests_14.addAll(since_14);
+ TestCase.resetForgottenFilters(tests_14);
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14), tests_14));
+ }
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/TextBlockTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java
new file mode 100644
index 0000000..32906fb
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java
@@ -0,0 +1,1340 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+/**
+ * This is almost a copy of the one in org.eclipse.jdt.tests.latestBREE.
+ * The other one also includes tests that are coded using the latest language
+ * features and API. However, the bundle is not yet setup to run with the build
+ * hence this is a temporary arrangement to keep the tests being run. The recommended
+ * strategy is to keep this one updated and when the time comes, move this over
+ * to the other bundle after synch-up of tests from both.
+ * @author jay
+ *
+ */
+public class TextBlockTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_NAMES = new String[] { "testCompliances_14" };
+ }
+
+ public static Class<?> testClass() {
+ return TextBlockTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_14);
+ }
+ public TextBlockTest(String testName){
+ super(testName);
+ }
+ protected Map<String, String> getCompilerOptions() {
+ return getCompilerOptions(true);
+ }
+ // Enables the tests to run individually
+ protected Map<String, String> getCompilerOptions(boolean previewFlag) {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, previewFlag ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return defaultOptions;
+ }
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments) {
+ runConformTest(testFiles, expectedOutput, customOptions, vmArguments, new JavacTestOptions("-source 14 --enable-preview"));
+ }
+ public void test001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\"\"\";\n" +
+ " ^^\n" +
+ "Syntax error on token \"\"\"\", invalid AssignmentOperator\n" +
+ "----------\n");
+ }
+ public void test002() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\" \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\" \"\"\";\n" +
+ " ^^^\n" +
+ "Syntax error on token \"\" \"\", invalid AssignmentOperator\n" +
+ "----------\n");
+ }
+ public void test003() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "\";\n" +
+ " ^^^^^\n" +
+ "Text block is not properly closed with the delimiter\n" +
+ "----------\n");
+ }
+ public void test003a() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "\n" +
+ " ^^^^\n" +
+ "Text block is not properly closed with the delimiter\n" +
+ "----------\n");
+ }
+ /*
+ * negative - unescaped '\' in a text block
+ */
+ public void test004() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\def" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\def\"\"\";\n" +
+ " ^^^^^^^^^\n" +
+ "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" +
+ "----------\n");
+ }
+ /* empty text block */
+ public void test005() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - escaped '\'
+ */
+ public void test006() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "abc\\\\def" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "abc\\def",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Positive - Multi line text block with varying indentation
+ * and \n
+ */
+ public void test007() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\n" +
+ " \n" +
+ " line 3\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "line 1\n" + // test framework trims the leading whitespace
+ " line 2\n" +
+ "\n" +
+ "line 3",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Positive - Multi line text block with varying indentation
+ * and \n and \r
+ */
+ public void test008() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\r" +
+ " \r" +
+ " line 3\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "line 1\n" +
+ " line 2\n" +
+ "\n" +
+ "line 3", // the trailing whitespace is trimmed by the test framework
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Positive - Multi line text block with varying indentation
+ * and \n and \r
+ */
+ public void test008a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\r" +
+ " \r" +
+ " line 3\n\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(\"<\");\n" +
+ " System.out.print(textb);\n" +
+ " System.out.print(\">\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "< line 1\n" +
+ " line 2\n" +
+ "\n" +
+ " line 3\n" +
+ ">", // the trailing whitespace is trimmed by the test framework
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using unescaped '"' in text block
+ */
+ public void test009() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc-def" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc-def",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using escaped '"' in text block
+ */
+ public void test010() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc-def\\\"\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc-def\"",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using escaped \ and escaped " in text block
+ */
+ public void test011() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"abc\\\"\"\"def\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"abc\"\"\"def",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using Unicode in text block
+ * and compare with an equal String literal
+ */
+ public void test012() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\\u0ba4\\u0bae\\u0bbf\\u0bb4\"\"\";\n" +
+ " public static String str = \"\\u0ba4\\u0bae\\u0bbf\\u0bb4\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(str.equals(textb));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "true",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - bigger piece of code as text block
+ */
+ public void test013() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "static String code = \"\"\"\n" +
+ " public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ " }\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(code);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - concatenation of string with text block
+ */
+ public void test014() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String code = \"public void print(Object o) {\\n\" +\n" +
+ " \"\"\"\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ " }\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(code);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "public void print(Object o) {\n" +
+ " System.out.println(Objects.toString(o));\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - freely using quotes
+ */
+ public void test015() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String story = \"\"\"\n" +
+ " \"When I use a word,\" Humpty Dumpty said,\n" +
+ " in rather a scornful tone, \"it means just what I\n" +
+ " choose it to mean - neither more nor less.\"\n" +
+ " \"The question is,\" said Alice, \"whether you\n" +
+ " can make words mean so many different things.\"\n" +
+ " \"The question is,\" said Humpty Dumpty,\n" +
+ " \"which is to be master - that's all.\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(story);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "\"When I use a word,\" Humpty Dumpty said,\n" +
+ "in rather a scornful tone, \"it means just what I\n" +
+ "choose it to mean - neither more nor less.\"\n" +
+ "\"The question is,\" said Alice, \"whether you\n" +
+ "can make words mean so many different things.\"\n" +
+ "\"The question is,\" said Humpty Dumpty,\n" +
+ "\"which is to be master - that's all.",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation
+ */
+ public void test016() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation with empty lines
+ */
+ public void test016a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\r\\n" +
+ " <body>\\r\\n" +
+ " <p>Hello, world</p>\\r\\n" +
+ " </body>\\r\\n" +
+ " </html>\\r\\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation with \r as terminator
+ */
+ public void test016c() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - html code with indentation and trailing whitespace
+ */
+ public void test017() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html> \n" +
+ " <body> \n" +
+ " <p>Hello, world</p> \n" +
+ " </body> \n" +
+ " </html> \n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using octal escape char for trailing whitespace
+ */
+ public void test018() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static String html = \"\"\"\n" +
+ " <html>\\040\\040\n" +
+ " <body>\\040\\040\n" +
+ " <p>Hello, world</p>\\040\\040\\040\n" +
+ " </body>\\040\\040\n" +
+ " </html>\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html> \n" +
+ " <body> \n" +
+ " <p>Hello, world</p> \n" +
+ " </body> \n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using text block as a method argument
+ */
+ public void test019() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"\"\"\n" +
+ " <html>\\n" +
+ " <body>\\n" +
+ " <p>Hello, world</p>\\n" +
+ " </body>\\n" +
+ " </html>\\n" +
+ " \"\"\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - using variable assigned with text block as a method argument
+ */
+ public void test020() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " System.out.println(html);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * positive - assigning strings and text blocks interchangeably.
+ */
+ public void test021() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String html = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " String s = html;\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "<html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ "</html>",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void test024() {
+ runConformTest(
+ new String[] {
+ "Main.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " runConformTest(\n" +
+ " new String[] {\n" +
+ " \"XYZ.java\",\n" +
+ " \"\"\"\n" +
+ " public class XYZ {\n" +
+ " public static String textb = \\\"\"\"\n" +
+ " abc\\\\\\\"\"\"def\" \n" +
+ " \\\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ " }\"\"\"" +
+ " }, \n" +
+ " \"\",\n" +
+ " null,\n" +
+ " new String[] {\"--enable-preview\"});\n" +
+ " }\n" +
+ " private static void runConformTest(String[] strings, String text, Object object, String[] strings2) {\n" +
+ " System.out.println(strings[1]);\n" +
+ " }\n" +
+ "}"
+ },
+ "public class XYZ {\n" +
+ " public static String textb = \"\"\"\n" +
+ " abc\\\"\"\"def\"\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void test025() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " abc\\def\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ " }"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ " abc\\def\"\"\";\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" +
+ "----------\n",
+ null,
+ true,
+ getCompilerOptions());
+ }
+
+ public void test027() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main (String[] args) {\n" +
+ " String xyz = \n" +
+ " \"\"\"\n" +
+ " public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " int arg1 = 0;\n" +
+ " pointer: foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break p;}\\n\"\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ " }\\n\"\"\"; \n" +
+ " System.out.println(xyz);\n" +
+ " }\n" +
+ "}"
+ },
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " int arg1 = 0;\n" +
+ " pointer: foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break p;}\n" +
+ "\"\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ " }",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // An empty text block
+ public void test028() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main (String[] args) {\n" +
+ " String xyz = \n" +
+ " \"\"\"\n" +
+ " \\n\"\"\"; \n" +
+ " System.out.println(xyz);\n" +
+ " }\n" +
+ "}"
+ },
+ "",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // An empty text block
+ public void test029() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ " public static String str = \"\"\"\n" +
+ " Hello Guru \n" +
+ " \n" +
+ " \"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.println(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "Hello Guru", // output comparison tool strips off all trailing whitespace
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug550356() {
+ Map<String, String> options = getCompilerOptions(false);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " ^^^^^^^\n" +
+ "Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+ }
+ public void testBug551948_1() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String text = \"\"\"\n" +
+ " Lorem ipsum dolor sit amet, consectetur adipiscing \\\n" +
+ " elit, sed do eiusmod tempor incididunt ut labore \\\n" +
+ " et dolore magna aliqua.\\\n" +
+ " \"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(text);\n" +
+ " }\n" +
+ "}"
+ },
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", // output comparison tool strips off all trailing whitespace
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_2() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String noLastLF = \"\"\"\n" +
+ " abc\n" +
+ " def\\\n" +
+ " ghi\"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(noLastLF);\n" +
+ " }\n" +
+ "}"
+ },
+ "abc\n defghi",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_3() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String python = \"\"\"\n" +
+ " if x == True and \\\\\n" +
+ " y == False\n" +
+ " \"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(python);\n" +
+ " }\n" +
+ "}"
+ },
+ "if x == True and \\\n" +
+ " y == False",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_4() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String colors = \"\"\"\n" +
+ " red \\\n" +
+ " green \\\n" +
+ " blue \\\n" +
+ " orange\"\"\"; \n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(colors);\n" +
+ " }\n" +
+ "}"
+ },
+ "red green blue orange",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_5() {
+ runNegativeTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String colors = \"\"\"\n" +
+ " \\red \n" +
+ " \\green \n" +
+ " \\blue \n" +
+ " \\orange\"\"\"; \n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(colors);\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in Cls2.java (at line 3)\n" +
+ " static String colors = \"\"\"\n" +
+ " \\red \n" +
+ " \\green \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" +
+ "----------\n",
+ null,
+ true,
+ getCompilerOptions(true));
+ }
+ public void testBug551948_6() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String str = \"A\\sline\\swith\\sspaces\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "A line with spaces",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_7() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String colors = \"\"\"\n" +
+ " red \\s\n" +
+ " green\\s\n" +
+ " blue \\s\n" +
+ " \"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(colors);\n" +
+ " }\n" +
+ "}"
+ },
+ "red \ngreen \nblue", // trailing whitespaces are trimmed
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug551948_8() {
+ runConformTest(
+ new String[] {
+ "Cls2.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class Cls2 {\n" +
+ "static String s = \"\"\"\n" +
+ "aaa\n" +
+ "\n" +
+ "bbb\n" +
+ "\n" +
+ "\n" +
+ "ccc" +
+ "\"\"\";\n" +
+ " public static void main (String[] args) {\n" +
+ " System.out.print(s);\n" +
+ " }\n" +
+ "}"
+ },
+ "aaa\n\n" +
+ "bbb\n\n\n" +
+ "ccc",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_1() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\n" +
+ " aa\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"\" + LF + \"aa\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_2() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\\n" +
+ "\\n" +
+ "\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"\" + LF + LF + \"\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_3() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\n" +
+ "\"\"\";\n" +
+ " System.out.print(textBlock);\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"\" + '\\u0015' + LF + \"\";\n" +
+ " return textBlock.equals(str.stripIndent());\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_4() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "v\r" +
+ "\r" +
+ "vaa\"\"\";\n" +
+ " char[] cs = textBlock.toCharArray();\n" +
+ " for (char c : cs) {\n" +
+ " //System.out.print((int)c);\n" +
+ " //System.out.print(',');\n" +
+ " }\n" +
+ " //System.out.println();\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"v\" + LF + LF + '\\u0076' + \"aa\";\n" +
+ " return textBlock.equals(str.stripIndent());\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_5() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "aa\f" +
+ "\f" +
+ "\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"aa\" + LF + LF + \"\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "false",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_6() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\n" +
+ "\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"\" + '\\u0015' + LF + \"\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_7() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "aav\n" +
+ "\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"aa\" + '\\u0076' + LF + \"\";\n" +
+ " return textBlock.equals(str.stripIndent());\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_8() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\\\"some\\\"\\n \\\"string\\\" \\n \\\"here\\\"\\n\"\"\";\n" +
+ " System.out.print(textBlock.length());\n" +
+ " }\n" +
+ "}"
+ },
+ "26",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // Escaped """ with escaping at the first '"'
+ public void testCompliances_9() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "some string ends with \\\"\"\"\\n\"\"\";\n" +
+ " System.out.print(textBlock.length());\n" +
+ " }\n" +
+ "}"
+ },
+ "26",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // Escaped """ with escaping at the second '"'
+ public void testCompliances_10() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "some string ends with \"\\\"\"\\n\"\"\";\n" +
+ " System.out.print(textBlock.length());\n" +
+ " }\n" +
+ "}"
+ },
+ "26",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ // Escaped """ with escaping at the third '"'
+ public void testCompliances_11() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "some string ends with \"\"\\\"\\n\"\"\";\n" +
+ " System.out.print(textBlock.length());\n" +
+ " }\n" +
+ "}"
+ },
+ "26",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_12() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\n" +
+ "\r\n" +
+ " aa\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " char LF = (char) 0x000A;\n" +
+ " String str = \"\" + LF + \"aa\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_13() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textb = \"\"\"\n" +
+ "\\0\\1\\2\\3\\4\\5\\6\\7\\10\\11\\12\\13\\14\\15\\16\\17\\20\\21\\22\\23\\24\\25\\26\\27\\30\\31\\32\\33\\34\\35\\36\\37\\40\\41\\42\\43\\44\\45\\46\\47\\50\\51\\52\\53\\54\\55\\56\\57\\60\\61\\62\\63\\64\\65\\66\\67\\70\\71\\72\\73\\74\\75\\76\\77\\100\\101\\102\\103\\104\\105\\106\\107\\110\\111\\112\\113\\114\\115\\116\\117\\120\\121\\122\\123\\124\\125\\126\\127\\130\\131\\132\\133\\134\\135\\136\\137\\140\\141\\142\\143\\144\\145\\146\\147\\150\\151\\152\\153\\154\\155\\156\\157\\160\\161\\162\\163\\164\\165\\166\\167\\170\\171\\172\\173\\174\\175\\176\\177\\200\\201\\202\\203\\204\\205\\206\\207\\210\\211\\212\\213\\214\\215\\216\\217\\220\\221\\222\\223\\224\\225\\226\\227\\230\\231\\232\\233\\234\\235\\236\\237\\240\\241\\242\\243\\244\\245\\246\\247\\250\\251\\252\\253\\254\\255\\256\\257\\260\\261\\262\\263\\264\\265\\266\\267\\270\\271\\272\\273\\274\\275\\276\\277\\300\\301\\302\\303\\304\\305\\306\\307\\310\\311\\312\\313\\314\\315\\316\\317\\320\\321\\322\\323\\324\\325\\326\\327\\330\\331\\332\\333\\334\\335\\336\\337\\340\\341\\342\\343\\344\\345\\346\\347\\350\\351\\352\\353\\354\\355\\356\\357\\360\\361\\362\\363\\364\\365\\366\\367\\370\\371\\372\\373\\374\\375\\376\\377\"\"\";\n" +
+ " System.out.println(textb.length());\n" +
+ " for (int i=0; i<=0xFF; i++) {\n" +
+ " if (i != (int)textb.charAt(i)) {\n" +
+ " System.out.println(\"Error in octal escape :\" + i);\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "256",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testCompliances_14() {
+ runConformTest(
+ new String[] {
+ "C.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class C {\n" +
+ " public static void main(String argv[]) {\n" +
+ " String textBlock = \"\"\"\r\n" +
+ " This is a multi-line\n" +
+ " message that is super-\n" +
+ " exciting!\"\"\";\n" +
+ " System.out.print(compare(textBlock));\n" +
+ " }\n" +
+ " private static boolean compare(String textBlock) {\n" +
+ " String str = \"This is a multi-line\\n\" + \n" +
+ " \"message that is super-\\n\" + \n" +
+ " \"exciting!\";\n" +
+ " return textBlock.equals(str);\n" +
+ " }\n" +
+ "}"
+ },
+ "true",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
+ public void testBug553252() {
+ Map<String, String> defaultOptions = super.getCompilerOptions();
+ Map<String, String> copy = new HashMap<String, String>(defaultOptions);
+ copy.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
+ copy.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ copy.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
+ copy.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ copy.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ "\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(textb);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 0)\n" +
+ " public class X {\n" +
+ " ^\n" +
+ "Preview features enabled at an invalid source release level 13, preview can be enabled only at source level 14\n" +
+ "----------\n",
+ null,
+ true,
+ copy);
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java
index 2e55ecc..b960a1d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 IBM Corporation and others.
+ * Copyright (c) 2011, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -595,6 +595,16 @@
}
public void test015_classExtends_interfaces_reflection() throws Exception {
+ String javaVersion = System.getProperty("java.version");
+ int index = javaVersion.indexOf('.');
+ if (index != -1) {
+ javaVersion = javaVersion.substring(0, index);
+ } else {
+ index = javaVersion.indexOf('-');
+ if (index != -1)
+ javaVersion = javaVersion.substring(0, index);
+ }
+ int v = Integer.parseInt(javaVersion);
this.runConformTest(
new String[] {
"X.java",
@@ -639,7 +649,7 @@
" class java.lang.Object:no annotations\n" +
"Annotations on superinterfaces of X\n" +
" interface I:@A(id=Hello, World!) \n" +
- " interface J:@C(value=i)");
+ " interface J:@C(" + (v < 14 ? "value=" : "") + "i)");
}
public void test016_classExtends() throws Exception {
@@ -4222,6 +4232,71 @@
"}";
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
}
+
+ // as of https://bugs.openjdk.java.net/browse/JDK-8231435 no-@Target annotations are legal also in TYPE_USE/TYPE_PARAMETER position
+ public void test083_multiuseAnnotations() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "@interface Annot {\n" +
+ " int value() default 0;\n" +
+ "}\n" +
+ "public class X<@Annot(1) T> {\n" +
+ " java.lang. @Annot(2)String f;\n" +
+ " public void foo(String @Annot(3)[] args) {\n" +
+ " }\n" +
+ "}\n",
+ },
+ "");
+ String expectedOutput =
+ " // Field descriptor #6 Ljava/lang/String;\n" +
+ " java.lang.String f;\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @Annot(\n" +
+ " #9 value=(int) 2 (constant type)\n" + // <-2-
+ " target type = 0x13 FIELD\n" +
+ " )\n" +
+ " \n" +
+ " // Method descriptor #12 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [14]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 4]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " Local variable type table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X<T>\n" +
+ " \n" +
+ " // Method descriptor #23 ([Ljava/lang/String;)V\n" +
+ " // Stack: 0, Locals: 2\n" +
+ " public void foo(java.lang.String[] args);\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 7]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 1] local: this index: 0 type: X\n" +
+ " [pc: 0, pc: 1] local: args index: 1 type: java.lang.String[]\n" +
+ " Local variable type table:\n" +
+ " [pc: 0, pc: 1] local: this index: 0 type: X<T>\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @Annot(\n" +
+ " #9 value=(int) 3 (constant type)\n" + // <-3-
+ " target type = 0x16 METHOD_FORMAL_PARAMETER\n" +
+ " method parameter index = 0\n" +
+ " )\n" +
+ "\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @Annot(\n" +
+ " #9 value=(int) 1 (constant type)\n" + // <-1-
+ " target type = 0x0 CLASS_TYPE_PARAMETER\n" +
+ " type parameter index = 0\n" +
+ " )\n" +
+ "}";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
public void test100_pqtr() throws Exception { // PQTR (ParameterizedQualifiedTypeReference)
this.runConformTest(
@@ -6589,6 +6664,16 @@
customOptions);
}
public void testBug485386() {
+ String javaVersion = System.getProperty("java.version");
+ int index = javaVersion.indexOf('.');
+ if (index != -1) {
+ javaVersion = javaVersion.substring(0, index);
+ } else {
+ index = javaVersion.indexOf('-');
+ if (index != -1)
+ javaVersion = javaVersion.substring(0, index);
+ }
+ int v = Integer.parseInt(javaVersion);
runConformTest(
new String[] {
"Test.java",
@@ -6621,7 +6706,7 @@
" }\n" +
"}\n"
},
- "@TestAnn1(value=" + decorateAnnotationValueLiteral("1") + ")");
+ "@TestAnn1(" + (v < 14 ? "value=" : "") + decorateAnnotationValueLiteral("1") + ")");
}
public void testBug492322readFromClass() {
runConformTest(
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
index 0fb0606..9924f61 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
@@ -65,7 +65,7 @@
super(name);
}
- private static final int AST_JLS_LATEST = AST.JLS13;
+ private static final int AST_JLS_LATEST = AST.JLS14;
public ASTNode runConversion(
int astLevel,
@@ -1766,8 +1766,9 @@
SimpleName simpleName = (SimpleName) name;
assertFalse("A var", simpleName.isVar());
}
+ // no longer a preview feature, test is not relevant
@Deprecated
- public void testBug545383_01() throws JavaModelException {
+ public void _testBug545383_01() throws JavaModelException {
String contents =
"class X {\n"+
" public static int foo(int i) {\n"+
@@ -1815,11 +1816,9 @@
parser.setEnvironment(null, null, null, true);
parser.setResolveBindings(false);
Map<String, String> options = getCompilerOptions();
- options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_13);
- options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_13);
- options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_13);
- options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
- options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
parser.setCompilerOptions(options);
ASTNode node = parser.createAST(null);
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 e64a387..b73a84c 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
@@ -45,6 +45,7 @@
public static final int F_11 = 0x100;
public static final int F_12 = 0x200;
public static final int F_13 = 0x400;
+ public static final int F_14 = 0x800;
public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));
private static final int UNINITIALIZED = -1;
@@ -57,6 +58,7 @@
protected static boolean isJRE11Plus = false;
protected static boolean isJRE12Plus = false;
protected static boolean isJRE13Plus = false;
+ protected static boolean isJRE14Plus = false;
protected static boolean reflectNestedClassUseDollar;
/**
@@ -107,6 +109,9 @@
if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_14) != 0) {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14)));
+ }
}
/**
@@ -155,6 +160,9 @@
if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_14) != 0) {
+ suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14)));
+ }
return suite;
}
@@ -162,7 +170,8 @@
possibleComplianceLevels = complianceLevel;
int lessthan9 = F_1_3 | F_1_4 | F_1_5 | F_1_6 | F_1_7 | F_1_8;
isJRE9Plus = !isJRELevel(lessthan9);
- isJRE13Plus = isJRELevel(F_13);
+ isJRE14Plus = isJRELevel(F_14);
+ isJRE13Plus = isJRELevel(F_13) || isJRE14Plus;
isJRE12Plus = isJRE13Plus || isJRELevel(F_12);
isJRE11Plus = isJRE12Plus || isJRELevel(F_11);
}
@@ -323,8 +332,20 @@
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
}
}
+ checkCompliance(evaluationTestClass, minimalCompliance, suite, complianceLevels, AbstractCompilerTest.F_14, ClassFileConstants.MAJOR_VERSION_14, 14);
return suite;
}
+ private static void checkCompliance(Class evaluationTestClass, int minimalCompliance, TestSuite suite,
+ int complianceLevels, int abstractCompilerTestCompliance, int classFileConstantsVersion, int errMessageCompliance) {
+ int lev = complianceLevels & abstractCompilerTestCompliance;
+ if (lev != 0) {
+ if (lev < minimalCompliance) {
+ System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance" + errMessageCompliance + "!");
+ } else {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(classFileConstantsVersion)));
+ }
+ }
+ }
/**
* Build a regression test setup suite for a compliance and a test suite to run.
@@ -381,6 +402,9 @@
*/
public static long highestComplianceLevels() {
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
+ if ((complianceLevels & AbstractCompilerTest.F_14) != 0) {
+ return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14);
+ }
if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13);
}
@@ -440,7 +464,8 @@
public static int getPossibleComplianceLevels() {
if (possibleComplianceLevels == UNINITIALIZED) {
String specVersion = System.getProperty("java.specification.version");
- isJRE13Plus = CompilerOptions.VERSION_13.equals(specVersion);
+ isJRE14Plus = CompilerOptions.VERSION_14.equals(specVersion);
+ isJRE13Plus = isJRE14Plus || CompilerOptions.VERSION_13.equals(specVersion);
isJRE12Plus = isJRE13Plus || CompilerOptions.VERSION_12.equals(specVersion);
isJRE11Plus = isJRE12Plus || CompilerOptions.VERSION_11.equals(specVersion);
isJRE9Plus = isJRE11Plus || CompilerOptions.VERSION_9.equals(specVersion)
@@ -472,6 +497,8 @@
possibleComplianceLevels |= F_12;
} else if (CompilerOptions.VERSION_13.equals(compliance)) {
possibleComplianceLevels |= F_13;
+ } else if (CompilerOptions.VERSION_14.equals(compliance)) {
+ possibleComplianceLevels |= F_14;
} else {
System.out.println("Ignoring invalid compliance (" + compliance + ")");
System.out.print("Use one of ");
@@ -486,7 +513,8 @@
System.out.print(CompilerOptions.VERSION_10 + ", ");
System.out.print(CompilerOptions.VERSION_11 + ", ");
System.out.print(CompilerOptions.VERSION_12 + ", ");
- System.out.println(CompilerOptions.VERSION_13);
+ System.out.print(CompilerOptions.VERSION_13 + ", ");
+ System.out.println(CompilerOptions.VERSION_14);
}
}
if (possibleComplianceLevels == 0) {
@@ -540,6 +568,10 @@
if (canRun13) {
possibleComplianceLevels |= F_13;
}
+ boolean canRun14 = canRun13 && !CompilerOptions.VERSION_13.equals(specVersion);
+ if (canRun14) {
+ possibleComplianceLevels |= F_14;
+ }
} else if ("1.0".equals(specVersion)
|| CompilerOptions.VERSION_1_1.equals(specVersion)
|| CompilerOptions.VERSION_1_2.equals(specVersion)
@@ -564,6 +596,9 @@
possibleComplianceLevels |= F_12;
if (!CompilerOptions.VERSION_12.equals(specVersion)) {
possibleComplianceLevels |= F_13;
+ if (!CompilerOptions.VERSION_13.equals(specVersion)) {
+ possibleComplianceLevels |= F_14;
+ }
}
}
}
@@ -740,7 +775,7 @@
}
protected static String getVersionString(long compliance) {
- String version = "version 13 : 57.0";
+ String version = "version 14 : 58.0";
if (compliance < ClassFileConstants.JDK9) return "version 1.8 : 52.0";
if (compliance == ClassFileConstants.JDK9) return "version 9 : 53.0";
if (compliance == ClassFileConstants.JDK10) return "version 10 : 54.0";
@@ -749,7 +784,7 @@
int major = Integer.parseInt(ver) + ClassFileConstants.MAJOR_VERSION_0;
return "version " + ver + " : " + major + ".0";
}
- if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)) return version; // keep this stmt for search for next bump up
+ if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14)) return version; // keep this stmt for search for next bump up
return version;
}
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 e6a93d4..d101743 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.10.1100.qualifier
+Bundle-Version: 3.10.1200.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 986a7a6..d9bda43 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -15,12 +15,12 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.jdt.core</groupId>
- <version>4.15.0-SNAPSHOT</version>
+ <version>4.16.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.model</artifactId>
- <version>3.10.1100-SNAPSHOT</version>
+ <version>3.10.1200-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
@@ -201,6 +201,37 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-14</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-14</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-14/configure -->
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,14</tycho.surefire.argLine>
+ </properties>
+ </profile>
</profiles>
</project>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java
index de10caa..4d0cc1f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java
@@ -17,7 +17,7 @@
import java.lang.reflect.Method;
import org.eclipse.jdt.core.tests.compiler.parser.ComplianceDiagnoseTest;
-import org.eclipse.jdt.core.tests.dom.ASTConverter13Test;
+import org.eclipse.jdt.core.tests.dom.ASTConverter14Test;
import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
import org.eclipse.jdt.core.tests.model.JavaSearchBugs13Tests;
import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest;
@@ -44,7 +44,7 @@
public static Class[] getConverterTestClasses() {
return new Class[] {
- ASTConverter13Test.class,
+ ASTConverter14Test.class,
ASTRewritingTest.class,
};
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava14Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava14Tests.java
new file mode 100644
index 0000000..e3baeb6
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava14Tests.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2020 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs14Tests;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs14SwitchExpressionTests;
+import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunAllJava14Tests extends TestCase {
+
+ public RunAllJava14Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ JavaSearchBugs14Tests.class,JavaSearchBugs14SwitchExpressionTests.class
+
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+
+ };
+ }
+
+ public static Class[] getCompilerClasses() {
+ return new Class[] {
+
+ };
+ }
+
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunAllJava14Tests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ addTestsToSuite(ts, testClasses);
+ testClasses = getConverterTestClasses();
+ addTestsToSuite(ts, testClasses);
+
+ AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_14);
+ addTestsToSuite(ts, getCompilerClasses());
+ // ComplianceDiagnoseTest is already added to the test suite through getTestSuite
+ ts.addTest(org.eclipse.jdt.core.tests.compiler.parser.TestAll.getTestSuite(false));
+ return ts;
+ }
+ public static void addTestsToSuite(TestSuite suite, Class[] testClasses) {
+
+ for (int i = 0; i < testClasses.length; i++) {
+ Class testClass = testClasses[i];
+ // call the suite() method and add the resulting suite to the suite
+ try {
+ Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$
+ Test test = (Test)suiteMethod.invoke(null, new Object[0]);
+ suite.addTest(test);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ protected void tearDown() throws Exception {
+ ConverterTestSetup.PROJECT_SETUP = false;
+ super.tearDown();
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java
index e8ef362..1ad7a13 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java
@@ -19,7 +19,7 @@
import java.util.Arrays;
import org.eclipse.jdt.core.tests.compiler.regression.SwitchExpressionsYieldTest;
-import org.eclipse.jdt.core.tests.dom.ASTConverter13Test;
+import org.eclipse.jdt.core.tests.dom.ASTConverter14Test;
import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
import org.eclipse.jdt.core.tests.model.JavaSearchBugs13Tests;
import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest;
@@ -43,7 +43,7 @@
public static Class[] getConverterTestClasses() {
return new Class[] {
- ASTConverter13Test.class,
+ ASTConverter14Test.class,
ASTRewritingTest.class,
};
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava14Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava14Tests.java
new file mode 100644
index 0000000..efc1c3f
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava14Tests.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2020 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs14Tests;
+import org.eclipse.jdt.core.tests.model.CompletionTests14;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs14SwitchExpressionTests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunOnlyJava14Tests extends TestCase {
+
+ public RunOnlyJava14Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ JavaSearchBugs14Tests.class,JavaSearchBugs14SwitchExpressionTests.class, CompletionTests14.class
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+
+ };
+ }
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunOnlyJava14Tests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ addTestsToSuite(ts, testClasses);
+ testClasses = getConverterTestClasses();
+ ConverterTestSetup.TEST_SUITES = new ArrayList(Arrays.asList(testClasses));
+ addTestsToSuite(ts, testClasses);
+ return ts;
+ }
+ public static void addTestsToSuite(TestSuite suite, Class[] testClasses) {
+
+ for (int i = 0; i < testClasses.length; i++) {
+ Class testClass = testClasses[i];
+ // call the suite() method and add the resulting suite to the suite
+ try {
+ Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$
+ Test test = (Test)suiteMethod.invoke(null, new Object[0]);
+ suite.addTest(test);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ protected void tearDown() throws Exception {
+ ConverterTestSetup.PROJECT_SETUP = false;
+ super.tearDown();
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
index efec12d..2b7c36b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
@@ -62,7 +62,7 @@
static {
// TESTS_NUMBERS = new int[] { 19 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] {"test0001"};
+// TESTS_NAMES = new String[] {"_test0001"};
}
public static Test suite() {
return buildModelTestSuite(ASTConverter13Test.class);
@@ -81,7 +81,7 @@
/*
* Test that a simple switch expression's return type holds the correct type
*/
- public void test0001() throws JavaModelException {
+ public void _test0001() throws JavaModelException {
String contents =
" public class X {\n" +
" enum Day\n" +
@@ -130,7 +130,7 @@
* Test that a case statement with multiple cases is resolved correctly
* and has the correct source range
*/
- public void test0002() throws JavaModelException {
+ public void _test0002() throws JavaModelException {
String contents =
"public class X {\n" +
" static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
@@ -186,7 +186,7 @@
/* test implicit break statement */
- public void test0003() throws JavaModelException {
+ public void _test0003() throws JavaModelException {
String contents =
"public class X {\n" +
" static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
@@ -237,7 +237,7 @@
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0004() throws JavaModelException {
+ public void _test0004() throws JavaModelException {
String contents =
"public class X {\n" +
" static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
@@ -297,10 +297,10 @@
}
}
@Deprecated
- public void _test0005() throws JavaModelException {
+ public void __test0005() throws JavaModelException {
String contents =
"public class X {\n" +
- " public String test001() {\n" +
+ " public String _test001() {\n" +
" int i = 0;\n" +
" String ret = switch(i%2) {\n" +
" case 0 -> \"odd\";\n" +
@@ -352,10 +352,10 @@
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0006() throws JavaModelException {
+ public void _test0006() throws JavaModelException {
String contents =
"public class X {\n" +
- " public String test001() {\n" +
+ " public String _test001() {\n" +
" int i = 0;\n" +
" String ret = switch(i%2) {\n" +
" case 0 -> {return \"odd\"; }\n" +
@@ -398,7 +398,7 @@
}
}
// Moved over from ASTConverter9Test
- public void testBug531714_015() throws CoreException {
+ public void _testBug531714_015() throws CoreException {
// saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
if (!isJRE13) {
System.err.println("Test "+getName()+" requires a JRE 13");
@@ -486,10 +486,10 @@
}
}
- public void test0007() throws JavaModelException {
+ public void _test0007() throws JavaModelException {
String contents =
"public class X {\n" +
- " public String test001() {\n" +
+ " public String _test001() {\n" +
" String s = \"\"\"\n" +
" <html>\n" +
" <body>\n" +
@@ -541,10 +541,10 @@
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0008() throws JavaModelException {
+ public void _test0008() throws JavaModelException {
String contents =
"public class X {\n" +
- " public String test001() {\n" +
+ " public String _test001() {\n" +
" String s = \"\"\"\n" +
" <html>\n" +
" <body>\n" +
@@ -578,10 +578,10 @@
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0009() throws JavaModelException {
+ public void _test0009() throws JavaModelException {
String contents =
"public class X {\n" +
- " public String test001() {\n" +
+ " public String _test001() {\n" +
" String s = \"\"\"\n" +
" <html>\n" +
" <body>\n" +
@@ -645,7 +645,7 @@
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0010() throws JavaModelException {
+ public void _test0010() throws JavaModelException {
String contents =
"public class test13 {\n" +
" public static void main(String[] args) {\n" +
@@ -683,7 +683,7 @@
}
}
- public void test0011() throws CoreException {
+ public void _test0011() throws CoreException {
// saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
if (!isJRE13) {
System.err.println("Test "+getName()+" requires a JRE 13");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter14Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter14Test.java
new file mode 100644
index 0000000..7654ac0
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter14Test.java
@@ -0,0 +1,784 @@
+/*******************************************************************************
+ * Copyright (c) 2019, 2020 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
+ * 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.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BreakStatement;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.Statement;
+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.TextBlock;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.YieldStatement;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+
+@SuppressWarnings("rawtypes")
+public class ASTConverter14Test extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+ private static final String jclLib = "CONVERTER_JCL14_LIB";
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(getAST14(), false);
+ if (this.ast.apiLevel() == AST.JLS14 ) {
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
+ this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
+ }
+ }
+
+ public ASTConverter14Test(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 19 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] {"test0001"};
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverter14Test.class);
+ }
+
+ static int getAST14() {
+ return AST.JLS14;
+ }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+ /*
+ * Test that a simple switch expression's return type holds the correct type
+ */
+ public void _test0001() throws JavaModelException {
+ String contents =
+ " public class X {\n" +
+ " enum Day\n" +
+ " {\n" +
+ " SUNDAY, MONDAY, TUESDAY, WEDNESDAY,\n" +
+ " THURSDAY, FRIDAY, SATURDAY;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " Day day = Day.SUNDAY;\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ "\n" +
+ " case WEDNESDAY -> {yield 10;}\n" +
+ " default -> {\n" +
+ " int g = day.toString().length();\n" +
+ " yield g;\n" +
+ " }};\n" +
+ " System.out.println(k);\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ VariableDeclarationStatement vStmt1 = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(1);
+ Type type = vStmt1.getType();
+ IBinding binding = type.resolveBinding();
+ assertTrue("null binding", binding != null);
+ assertTrue("binding incorrect", binding.getName().equals("int"));
+ }
+ /*
+ * Test that a case statement with multiple cases is resolved correctly
+ * and has the correct source range
+ */
+ public void _test0002() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String aa(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY ->\n" +
+ " today=\"Weekend\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->\n" +
+ " today=\"Working\";\n" +
+ " default ->\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ " \n" +
+ " String bb(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " today = \"Weekend day\";\n" +
+ " break;\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " today = \"Working day\";\n" +
+ " break;\n" +
+ " default:\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ checkSourceRange((Statement) switchStatement.statements().get(0), "case SATURDAY,SUNDAY ->", contents);
+ checkSourceRange((Statement) switchStatement.statements().get(2), "case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->", contents);
+ }
+
+ /* test implicit break statement */
+
+ public void _test0003() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String aa(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY ->\n" +
+ " today=\"Weekend\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->\n" +
+ " today=\"Working\";\n" +
+ " default ->\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ " \n" +
+ " String bb(Day day) throws Exception {\n" +
+ " String today = \"\";\n" +
+ " today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " yield \"Weekend day\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " yield \"Week day\";\n" +
+ " default:\n" +
+ " yield \"Any day\";\n" +
+ " };\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ checkSourceRange((Statement) switchStatement.statements().get(0), "case SATURDAY,SUNDAY ->", contents);
+
+ }
+
+ public void _test0004() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String bb(Day day) throws Exception {\n" +
+ " String today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " yield \"Weekend day\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " yield \"Week day\";\n" +
+ " default:\n" +
+ " yield \"Any day\";\n" +
+ " };\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("incorrect type", ASTNode.SWITCH_EXPRESSION, initializer.getNodeType());
+ Expression expression = ((SwitchExpression) initializer).getExpression();
+ assertEquals("incorrect type", ASTNode.SIMPLE_NAME, expression.getNodeType());
+ assertEquals("incorrect name", "day", ((SimpleName) expression).getFullyQualifiedName());
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ YieldStatement brStmt = (YieldStatement) statements.get(1);
+ Expression expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ //default case:
+ SwitchCase caseStmt = (SwitchCase) statements.get(4);
+ assertTrue("not default", caseStmt.isDefault());
+ brStmt = (YieldStatement) statements.get(5);
+ expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ }
+ @Deprecated
+ public void _test0005() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " int i = 0;\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 -> \"odd\";\n" +
+ " case 1 -> \"even\";\n" +
+ " default -> \"\";\n" +
+ " };\n" +
+ " return ret;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("incorrect type", ASTNode.SWITCH_EXPRESSION, initializer.getNodeType());
+ Expression expression = ((SwitchExpression) initializer).getExpression();
+ assertEquals("incorrect type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ BreakStatement brStmt = (BreakStatement) statements.get(1);
+ Expression expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ //default case:
+ SwitchCase caseStmt = (SwitchCase) statements.get(4);
+ assertTrue("not default", caseStmt.isDefault());
+ brStmt = (BreakStatement) statements.get(5);
+ expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ }
+ public void _test0006() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " int i = 0;\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 -> {return \"odd\"; }\n" +
+ " case 1 -> \"even\";\n" +
+ " default -> \"\";\n" +
+ " };\n" +
+ " return ret;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ Block block = (Block) statements.get(1);
+ statements = block.statements();
+ assertEquals("incorrect no of statements", 1, statements.size());
+ Statement stmt = (Statement) statements.get(0);
+ assertEquals("incorrect node type", ASTNode.RETURN_STATEMENT, stmt.getNodeType());
+
+ }
+ // Moved over from ASTConverter9Test
+ public void _testBug531714_015() throws CoreException {
+ // saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
+ if (!isJRE14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return;
+ }
+ IJavaProject p = createJavaProject("Foo", new String[] {"src"}, new String[] {jclLib}, "bin", "14"); // FIXME jcl12?
+ try {
+ String source =
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " void testForeach1(int i, List<String> list) {\n" +
+ " for (String s : switch(i) { case 1 -> list; default -> ; }) {\n" +
+ " \n" +
+ " }\n" +
+ " Throwable t = switch (i) {\n" +
+ " case 1 -> new Exception();\n" +
+ " case 2 -> new RuntimeException();\n" + // trigger !typeUniformAcrossAllArms
+ " default -> missing;\n" +
+ " };\n" +
+ " }\n" +
+ " void testForeach0(int i, List<String> list) {\n" + // errors in first arm
+ " for (String s : switch(i) { case 1 -> ; default -> list; }) {\n" +
+ " \n" +
+ " }\n" +
+ " Throwable t = switch (i) {\n" +
+ " case 0 -> missing;\n" +
+ " case 1 -> new Exception();\n" +
+ " default -> new RuntimeException();\n" + // trigger !typeUniformAcrossAllArms
+ " };\n" +
+ " }\n" +
+ " void testForeachAll(int i) {\n" + // only erroneous arms
+ " Throwable t = switch (i) {\n" +
+ " case 0 -> missing;\n" +
+ " default -> absent;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n";
+ createFile("Foo/src/X.java", source);
+ ICompilationUnit cuD = getCompilationUnit("/Foo/src/X.java");
+
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS14);
+ parser.setProject(p);
+ parser.setSource(cuD);
+ parser.setResolveBindings(true);
+ parser.setStatementsRecovery(true);
+ parser.setBindingsRecovery(true);
+ org.eclipse.jdt.core.dom.CompilationUnit cuAST = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
+ IProblem[] problems = cuAST.getProblems();
+ assertProblems("Unexpected problems",
+ "1. ERROR in /Foo/src/X.java (at line 4)\n" +
+ " for (String s : switch(i) { case 1 -> list; default -> ; }) {\n" +
+ " ^^\n" +
+ "Syntax error on token \"->\", Expression expected after this token\n" +
+ "----------\n" +
+ "2. ERROR in /Foo/src/X.java (at line 10)\n" +
+ " default -> missing;\n" +
+ " ^^^^^^^\n" +
+ "missing cannot be resolved to a variable\n" +
+ "----------\n" +
+ "3. ERROR in /Foo/src/X.java (at line 14)\n" +
+ " for (String s : switch(i) { case 1 -> ; default -> list; }) {\n" +
+ " ^^\n" +
+ "Syntax error on token \"->\", Expression expected after this token\n" +
+ "----------\n" +
+ "4. ERROR in /Foo/src/X.java (at line 18)\n" +
+ " case 0 -> missing;\n" +
+ " ^^^^^^^\n" +
+ "missing cannot be resolved to a variable\n" +
+ "----------\n" +
+ "5. ERROR in /Foo/src/X.java (at line 25)\n" +
+ " case 0 -> missing;\n" +
+ " ^^^^^^^\n" +
+ "missing cannot be resolved to a variable\n" +
+ "----------\n" +
+ "6. ERROR in /Foo/src/X.java (at line 26)\n" +
+ " default -> absent;\n" +
+ " ^^^^^^\n" +
+ "absent cannot be resolved to a variable\n" +
+ "----------\n",
+ problems, source.toCharArray());
+ } finally {
+ deleteProject(p);
+ }
+ }
+
+ public void _test0007() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " String s = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " System.out.println(s);" +
+ " return s;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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("Text block statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertTrue("Initializer is not a TextBlock", initializer instanceof TextBlock);
+ String escapedValue = ((TextBlock) initializer).getEscapedValue();
+
+ assertTrue("String should not be empty", escapedValue.length() != 0);
+ assertTrue("String should start with \"\"\"", escapedValue.startsWith("\"\"\""));
+
+ String literal = ((TextBlock) initializer).getLiteralValue();
+ assertEquals("literal value not correct",
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " ",
+ literal);
+
+ }
+ public void _test0008() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " String s = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " System.out.println(s);" +
+ " return s;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/src/X.java", true/*resolve*/);
+ try {
+ buildAST(
+ contents,
+ this.workingCopy);
+ } catch(UnsupportedOperationException e) {
+ fail("Should not throw UnsupportedOperationException");
+ } catch(AssertionFailedError e) {
+ e.printStackTrace();
+ return;
+ }
+ fail("Compilation should not succeed");
+
+ }
+ public void _test0009() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " String s = \"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\";\n" +
+ " System.out.println(s);" +
+ " return s;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/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("Text block statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertTrue("Initializer is not a TextBlock", initializer instanceof TextBlock);
+ ITypeBinding binding = initializer.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong qualified name", "java.lang.String", binding.getQualifiedName());
+
+ String escapedValue = ((TextBlock) initializer).getEscapedValue();
+
+ assertTrue("String should not be empty", escapedValue.length() != 0);
+ assertTrue("String should start with \"\"\"", escapedValue.startsWith("\"\"\""));
+ assertEquals("escaped value not correct",
+ "\"\"\"\n" +
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " \"\"\"",
+ escapedValue);
+
+ String literal = ((TextBlock) initializer).getLiteralValue();
+ assertEquals("literal value not correct",
+ " <html>\n" +
+ " <body>\n" +
+ " <p>Hello, world</p>\n" +
+ " </body>\n" +
+ " </html>\n" +
+ " ",
+ literal);
+ }
+ public void _test0010() throws JavaModelException {
+ String contents =
+ "public class test14 {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"\"\"\n" +
+ " nadknaks vgvh \n" +
+ " \"\"\";\n" +
+ "\n" +
+ " int m = 10;\n" +
+ " m = m* 6;\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter14/src/test14.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("wrong line number", 3, compilationUnit.getLineNumber(node.getStartPosition()));
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("wrong line number", 7, compilationUnit.getLineNumber(node.getStartPosition()));
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("wrong line number", 8, compilationUnit.getLineNumber(node.getStartPosition()));
+ node = getASTNode(compilationUnit, 0, 0, 3);
+ assertEquals("wrong line number", 9, compilationUnit.getLineNumber(node.getStartPosition()));
+ }
+
+ public void _test0011() throws CoreException {
+ // saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
+ if (!isJRE14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return;
+ }
+ String source =
+ "public class Switch {\n" +
+ " public static void main(String[] args) {\n" +
+ " foo(Day.TUESDAY);\n" +
+ " }\n" +
+ "\n" +
+ " private static void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SUNDAY, MONDAY, FRIDAY -> System.out.println(6);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter14/src/Switch.java", true/*resolve*/);
+ try {
+ buildAST(
+ source,
+ this.workingCopy);
+ } catch(UnsupportedOperationException e) {
+ fail("Should not throw UnsupportedOperationException");
+ } catch(AssertionFailedError e) {
+ e.printStackTrace();
+ return;
+ }
+
+ }
+
+ public void testRecord001() throws CoreException {
+ if (!isJRE14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return;
+ }
+ String contents =
+ "public record X() {\n" +
+ " public X {\n" +
+ " System.out.println(\"no error\");\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter14/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);
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ /**
+ * Added for Bug 561193 - [14]record keyword inside method not colored correctly
+ * @throws CoreException
+ */
+ public void testRecord002() throws CoreException {
+ if (!isJRE14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return;
+ }
+ String contents =
+ "public record X(int param1, int param2) {\n" +
+ " public X {\n" +
+ " if (param1 > 5) {\n" +
+ " System.out.println(\"error\");\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter14/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);
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void testRecord003() throws CoreException {
+ if (!isJRE14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return;
+ }
+ String contents =
+ "public record X(int param1, int param2) {\n" +
+ " public X {\n" +
+ " if (param1 > 5) {\n" +
+ " System.out.println(\"error\");\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public X(int a) {\n" +
+ " this.param1 = 6;\n" +
+ " this.param2 = 16;\n" +
+ " a = 6;\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter14/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);
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void testRecord004() throws CoreException {
+ if (!isJRE14) {
+ System.err.println("Test " + getName() + " requires a JRE 14");
+ return;
+ }
+ String contents = "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " record R(int x,int y){}\n" +
+ " R r = new R(100, 200);\n" +
+ " System.out.println(r.x());\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter14/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 = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List<ASTNode> statements = methodDeclaration.getBody().statements();
+ node = statements.get(0);
+ assertEquals("Not a TypDeclaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement tdStmt = (TypeDeclarationStatement) node;
+ node = tdStmt.getDeclaration();
+ assertEquals("Not a RecordDeclaration", ASTNode.RECORD_DECLARATION, node.getNodeType());
+ } 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/dom/ASTConverterBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java
index 34afcd1..5368096 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java
@@ -811,66 +811,40 @@
"}\n");
assertASTResult(
- "===== AST =====\n" +
- "package a;\n" +
- "public class X {\n" +
- " public void takeParam( int i){\n" +
- " }\n" +
- " void test(){\n" +
- " char c=\'a\';\n" +
- " public void takeParam;\n" +
- " int i;\n" +
- " new test(){\n" +
- " char c=\'a\';\n" +
- "{\n" +
- " takeParam((int)c);\n" +
- " }\n" +
- " [*1*]void takeParam(){\n" +
- " }[*1*]\n" +
- " }\n" +
- ";\n" +
- " }\n" +
- "}\n" +
- "\n" +
- "===== Details =====\n" +
- "1:METHOD_DECLARATION,[447,10],,MALFORMED,[null]\n" +
- "===== Problems =====\n" +
- "1. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
- " public void takeParam(int i) {\n" +
- " ^^^^^^^^^\n" +
- "void is an invalid type for the variable takeParam\n" +
- "2. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
- " public void takeParam(int i) {\n" +
- " ^\n" +
- "Syntax error on token \"(\", ; expected\n" +
- "3. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
- " public void takeParam(int i) {\n" +
- " ^\n" +
- "Syntax error on token \")\", ; expected\n" +
- "4. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
- " void test() {\n" +
- " ^^^^\n" +
- "Syntax error on token \"void\", new expected\n" +
- "5. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
- " void test() {\n" +
- " ^^^^\n" +
- "test cannot be resolved to a type\n" +
- "6. ERROR in /Converter15/src/a/X.java (at line 14)\n" +
- " char c = \'a\';\n" +
- " ^\n" +
- "Syntax error on token \";\", { expected after this token\n" +
- "7. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
- " }takeParam((int) c);\n" +
- " ^\n" +
- "Syntax error, insert \"}\" to complete ClassBody\n" +
- "8. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
- " }takeParam((int) c);\n" +
- " ^\n" +
- "Syntax error, insert \";\" to complete Statement\n" +
- "9. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void takeParam( int i){\n" +
+ " }\n" +
+ " void test(){\n" +
+ " char c=\'a\';\n" +
+ " public void takeParam;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:No corresponding node\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
+ " public void takeParam(int i) {\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
+ "2. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
+ " public void takeParam(int i) {\n" +
+ " ^^^^^^^^^\n" +
+ "void is an invalid type for the variable takeParam\n" +
+ "3. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
+ " void test() {\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", record expected\n" +
+ "4. ERROR in /Converter15/src/a/X.java (at line 14)\n" +
+ " char c = \'a\';\n" +
+ " ^\n" +
+ "Syntax error on token \";\", { expected after this token\n" +
+ "5. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
" }takeParam((int) c);\n" +
- " ^^^^^^^^^^\n" +
- "Return type for the method is missing\n",
+ " ^\n" +
+ "Syntax error, insert \"}\" to complete RecordBody\n",
result);
}
/**
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 9e42a36..d18e62a 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
@@ -423,15 +423,15 @@
public void testNodeClassForType() {
//{ObjectTeams: larger range:
/* orig:
- Set classes = new HashSet(100);
+ Set classes = new HashSet(103);
// make sure node types are contiguous starting at 0
int hi = 0;
for (int nodeType = 1; nodeType < 110; nodeType++) {
:giro */
- Set classes = new HashSet(120);
+ Set classes = new HashSet(123);
// make sure node types are contiguous starting at 0
int hi = 0;
- for (int nodeType = 1; nodeType < 120; nodeType++) {
+ for (int nodeType = 1; nodeType < 123; nodeType++) {
// SH}
try {
Class nodeClass = ASTNode.nodeClassForType(nodeType);
@@ -447,9 +447,9 @@
}
// {ObjectTeams: adapted for OT specific ASTNodes
/* orig:
- assertEquals("Wrong last known type", 102, hi); // last known one
+ assertEquals("Wrong last known type", 103, hi); // last known one
:giro */
- assertEquals("Wrong last known type", 118, hi); // last known one
+ assertEquals("Wrong last known type", 119, 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 9a69c2a..eb6b0ac 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
@@ -30,6 +30,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil;
// testing
@@ -1327,6 +1328,7 @@
case JavaCore.VERSION_11: return AST.JLS11;
case JavaCore.VERSION_12: return AST.JLS12;
case JavaCore.VERSION_13: return AST.JLS13;
+ case JavaCore.VERSION_14: return AST.JLS14;
default: return AST.JLS2;
}
}
@@ -8903,6 +8905,7 @@
ASTNode.SWITCH_EXPRESSION,
ASTNode.YIELD_STATEMENT,
ASTNode.TEXT_BLOCK,
+ ASTNode.RECORD_DECLARATION,
//{ObjectTeams:
ASTNode.METHOD_SPEC,
ASTNode.CALLIN_MAPPING_DECLARATION,
@@ -8969,5 +8972,19 @@
}
assertEquals("node types missing in test", Collections.EMPTY_SET, declaredNodeTypes);
}
+
+ @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};
+ for (int level : apilLevels) {
+ try {
+ DOMASTUtil.checkASTLevel(level);
+ } catch (IllegalArgumentException e) {
+ throw new AssertionFailedError("missing support for AST level: " + 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 034a46b..2203a05 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_13)) {
+ if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14)) {
+ JLSLevel = AST_INTERNAL_JLS14;
+ } else if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)) {
JLSLevel = AST_INTERNAL_JLS13;
} else if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)) {
JLSLevel = AST_INTERNAL_JLS12;
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 8bd1281..df8e112 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -106,6 +106,7 @@
this.deleteProject("Converter10"); //$NON-NLS-1$
this.deleteProject("Converter11"); //$NON-NLS-1$
this.deleteProject("Converter13"); //$NON-NLS-1$
+ this.deleteProject("Converter14"); //$NON-NLS-1$
PROJECT_SETUP = false;
} else {
TEST_SUITES.remove(getClass());
@@ -119,6 +120,7 @@
this.deleteProject("Converter10"); //$NON-NLS-1$
this.deleteProject("Converter11"); //$NON-NLS-1$
this.deleteProject("Converter13"); //$NON-NLS-1$
+ this.deleteProject("Converter14"); //$NON-NLS-1$
PROJECT_SETUP = false;
}
}
@@ -196,6 +198,14 @@
new IPath[] {getConverterJCLPath("13"), getConverterJCLSourcePath("13"), getConverterJCLRootSourcePath()},
null);
}
+ } else if ("14".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("CONVERTER_JCL14_LIB") == null) {
+ setupExternalJCL("converterJclMin14");
+ JavaCore.setClasspathVariables(
+ new String[] {"CONVERTER_JCL14_LIB", "CONVERTER_JCL14_SRC", "CONVERTER_JCL14_SRCROOT"},
+ new IPath[] {getConverterJCLPath("14"), getConverterJCLSourcePath("14"), getConverterJCLRootSourcePath()},
+ null);
+ }
} else if (JavaCore.getClasspathVariable("CONVERTER_JCL_LIB") == null) {
setupExternalJCL("converterJclMin");
JavaCore.setClasspathVariables(
@@ -221,6 +231,7 @@
setUpJavaProject("Converter10", "10"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter11", "11"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter13", "13"); //$NON-NLS-1$ //$NON-NLS-2$
+ setUpJavaProject("Converter14", "14"); //$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 cdaed01..cde2ff5 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -52,7 +52,7 @@
TypeAnnotationsConverterTest.class,
ASTConverter18Test.class,
ASTConverter9Test.class,
- ASTConverter13Test.class,
+ ASTConverter14Test.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 3286bd9..43b4907 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
@@ -1612,6 +1612,7 @@
}
public void test140() {
+ setComplianceLevel(CompilerOptions.VERSION_14);
DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
preferences.tab_char = DefaultCodeFormatterOptions.SPACE;
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
@@ -1619,6 +1620,7 @@
}
public void test141() {
+ setComplianceLevel(CompilerOptions.VERSION_14);
DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
preferences.tab_char = DefaultCodeFormatterOptions.SPACE;
preferences.indent_switchstatements_compare_to_cases = false;
@@ -14850,7 +14852,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818a() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_before_comma_in_switch_case_expressions = true;
this.formatterPrefs.insert_space_before_colon_in_case = true;
this.formatterPrefs.indent_switchstatements_compare_to_switch = true;
@@ -14861,7 +14863,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818b() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_after_comma_in_switch_case_expressions = false;
this.formatterPrefs.insert_space_before_closing_paren_in_switch = true;
this.formatterPrefs.indent_switchstatements_compare_to_cases = false;
@@ -14872,7 +14874,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818c() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_before_arrow_in_switch_case = false;
this.formatterPrefs.insert_space_before_opening_paren_in_switch = false;
this.formatterPrefs.indent_breaks_compare_to_cases = false;
@@ -14883,7 +14885,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818d() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_after_arrow_in_switch_case = false;
this.formatterPrefs.insert_space_after_opening_paren_in_switch = true;
this.formatterPrefs.insert_space_before_opening_brace_in_block = false;
@@ -14895,7 +14897,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818e() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_before_arrow_in_switch_default = false;
this.formatterPrefs.insert_space_before_colon_in_default = true;
this.formatterPrefs.parenthesis_positions_in_switch_statement = DefaultCodeFormatterConstants.SEPARATE_LINES;
@@ -14906,7 +14908,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818f() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.insert_space_after_arrow_in_switch_default = false;
this.formatterPrefs.insert_space_before_opening_brace_in_switch = false;
this.formatterPrefs.insert_space_before_opening_brace_in_block = false;
@@ -14917,7 +14919,7 @@
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818g() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
formatSource(input, getCompilationUnit("Formatter", "", "test543818", "G_out.java").getSource());
}
@@ -15230,7 +15232,7 @@
* https://bugs.eclipse.org/390720 - [formatter] Add setting for blank line between case blocks (after break) for switch statement
*/
public void testBug390720a() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.blank_lines_between_statement_groups_in_switch = 2;
formatSourceInWorkspace("test390720", "in.java", "A_out.java");
}
@@ -15238,7 +15240,7 @@
* https://bugs.eclipse.org/390720 - [formatter] Add setting for blank line between case blocks (after break) for switch statement
*/
public void testBug390720b() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
this.formatterPrefs.blank_lines_between_statement_groups_in_switch = ~0;
formatSourceInWorkspace("test390720", "in.java", "B_out.java");
}
@@ -15246,7 +15248,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436a() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15259,7 +15261,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436b() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15272,7 +15274,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436c() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15285,7 +15287,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436d() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15298,7 +15300,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436e() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15311,7 +15313,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436f() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15324,7 +15326,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436g() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15337,7 +15339,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436h() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
@@ -15350,7 +15352,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436i() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
@@ -15363,7 +15365,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436j() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15376,7 +15378,7 @@
* https://bugs.eclipse.org/549436 - [13] Formatter support for JEP 355 Text Block
*/
public void testBug549436k() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_13);
+ setComplianceLevel(CompilerOptions.VERSION_14);
setPageWidth80();
this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
@@ -15496,4 +15498,138 @@
" boolean b = ! a && ! (c || d) && (f != -5);\n" +
"}");
}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155a() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ formatSourceInWorkspace("test553155", "in.java", "A_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155b() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.indent_body_declarations_compare_to_record_header = false;
+ formatSourceInWorkspace("test553155", "in.java", "B_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155c() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.brace_position_for_record_declaration = DefaultCodeFormatterConstants.NEXT_LINE;
+ formatSourceInWorkspace("test553155", "in.java", "C_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155d() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.brace_position_for_record_constructor = DefaultCodeFormatterConstants.NEXT_LINE;
+ formatSourceInWorkspace("test553155", "in.java", "D_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155e() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.parenthesis_positions_in_record_declaration = DefaultCodeFormatterConstants.SEPARATE_LINES;
+ formatSourceInWorkspace("test553155", "in.java", "E_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155f() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_after_comma_in_record_components = false;
+ formatSourceInWorkspace("test553155", "in.java", "F_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155g() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_after_opening_paren_in_record_declaration = true;
+ formatSourceInWorkspace("test553155", "in.java", "G_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155h() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_before_closing_paren_in_record_declaration = true;
+ formatSourceInWorkspace("test553155", "in.java", "H_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155i() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_before_comma_in_record_components = true;
+ formatSourceInWorkspace("test553155", "in.java", "I_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155j() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_before_opening_brace_in_record_constructor = false;
+ formatSourceInWorkspace("test553155", "in.java", "J_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155k() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_before_opening_brace_in_record_declaration = false;
+ formatSourceInWorkspace("test553155", "in.java", "K_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155l() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.insert_space_before_opening_paren_in_record_declaration = true;
+ formatSourceInWorkspace("test553155", "in.java", "L_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155m() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.alignment_for_record_components = Alignment.M_ONE_PER_LINE_SPLIT + + Alignment.M_FORCE;
+ formatSourceInWorkspace("test553155", "in.java", "M_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155n() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.alignment_for_superinterfaces_in_record_declaration = Alignment.M_ONE_PER_LINE_SPLIT + + Alignment.M_FORCE;
+ formatSourceInWorkspace("test553155", "in.java", "N_out.java");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155o() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.keep_record_constructor_on_one_line = DefaultCodeFormatterConstants.ONE_LINE_ALWAYS;
+ String source = "record Range(int lo, int hi) {public Range {foo();}}";
+ formatSource(source,
+ "record Range(int lo, int hi) {\n" +
+ " public Range { foo(); }\n" +
+ "}");
+}
+/**
+ * https://bugs.eclipse.org/553155 - [14] Records - Formatter Support
+ */
+public void testBug553155p() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_14);
+ this.formatterPrefs.keep_record_constructor_on_one_line = DefaultCodeFormatterConstants.ONE_LINE_ALWAYS;
+ this.formatterPrefs.keep_record_declaration_on_one_line = DefaultCodeFormatterConstants.ONE_LINE_ALWAYS;
+ String source = "record Range(int lo, int hi) {public Range {foo();}}";
+ formatSource(source,
+ "record Range(int lo, int hi) { public Range { foo(); } }");
+}
}
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 eae922b..7bf00c1 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,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -79,6 +79,7 @@
protected static boolean isJRE11 = false;
protected static boolean isJRE12 = false;
protected static boolean isJRE13 = false;
+ protected static boolean isJRE14 = false;
protected static String DEFAULT_MODULES = null;
static {
String javaVersion = System.getProperty("java.version");
@@ -92,8 +93,8 @@
}
}
long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion.length() > 3 ? javaVersion.substring(0, 3) : javaVersion);
- if (jdkLevel >= ClassFileConstants.JDK13) {
- isJRE13 = true;
+ if (jdkLevel >= ClassFileConstants.JDK14) {
+ isJRE14 = true;
}
if (jdkLevel >= ClassFileConstants.JDK12) {
isJRE12 = true;
@@ -157,6 +158,12 @@
* to alleviate deprecation warnings once AST.JLS13 is deprecated in future.
*/
protected static final int AST_INTERNAL_JLS13 = AST.JLS13;
+
+ /**
+ * Internal synonym for constant AST.JSL14
+ * to alleviate deprecation warnings once AST.JLS14 is deprecated in future.
+ */
+ protected static final int AST_INTERNAL_JLS14 = AST.JLS14;
/**
* Internal synonym for constant AST.JSL11
@@ -169,7 +176,7 @@
* Internal synonym for the latest AST level.
*
*/
- protected static final int AST_INTERNAL_LATEST = AST.JLS13;
+ protected static final int AST_INTERNAL_LATEST = AST.JLS14;
public static class BasicProblemRequestor implements IProblemRequestor {
public void acceptProblem(IProblem problem) {}
@@ -1520,6 +1527,9 @@
protected IJavaProject createJava11Project(String name, String[] srcFolders) throws CoreException {
return createJava9ProjectWithJREAttributes(name, srcFolders, null, "11");
}
+ protected IJavaProject createJava14Project(String name, String[] srcFolders) throws CoreException {
+ return createJava9ProjectWithJREAttributes(name, srcFolders, null, "14");
+ }
protected IJavaProject createJava9ProjectWithJREAttributes(String name, String[] srcFolders, IClasspathAttribute[] attributes) throws CoreException {
return createJava9ProjectWithJREAttributes(name, srcFolders, attributes, "9");
}
@@ -2112,6 +2122,12 @@
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
javaProject.setOptions(options);
+ } else if ("14".equals(compliance)) {
+ Map options = new HashMap();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14);
+ javaProject.setOptions(options);
}
result[0] = javaProject;
}
@@ -3160,7 +3176,8 @@
return this.currentProject;
}
protected IJavaProject setUpJavaProject(final String projectName, String compliance) throws CoreException, IOException {
- return setUpJavaProject(projectName, compliance, false);
+ this.currentProject = setUpJavaProject(projectName, compliance, false);
+ return this.currentProject;
}
protected IJavaProject setUpJavaProject(final String projectName, String compliance, boolean useFullJCL) throws CoreException, IOException {
// copy files in project from source workspace to target workspace
@@ -3187,7 +3204,6 @@
javaProject.setOption(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.IGNORE);
javaProject.setOption(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.IGNORE);
javaProject.setOption(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING, JavaCore.IGNORE);
-// javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
return javaProject;
}
protected void setUpProjectCompliance(IJavaProject javaProject, String compliance) throws JavaModelException, IOException {
@@ -3210,7 +3226,10 @@
newJclSrcString = "JCL18_SRC"; // Use the same source
}
} else {
- if (compliance.equals("13")) {
+ if (compliance.equals("14")) {
+ newJclLibString = "JCL14_LIB";
+ newJclSrcString = "JCL14_SRC";
+ } else if (compliance.equals("13")) {
newJclLibString = "JCL13_LIB";
newJclSrcString = "JCL13_SRC";
} else if (compliance.equals("12")) {
@@ -3275,11 +3294,12 @@
IPath jcl11Lib = new Path("JCL11_LIB");
IPath jcl12Lib = new Path("JCL12_LIB");
IPath jcl13Lib = new Path("JCL13_LIB");
+ IPath jcl14Lib = new Path("JCL14_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(jclFull);
+ || path.equals(jcl14Lib) || path.equals(jclFull);
}
public void setUpJCLClasspathVariables(String compliance) throws JavaModelException, IOException {
setUpJCLClasspathVariables(compliance, false);
@@ -3358,6 +3378,14 @@
new IPath[] {getExternalJCLPath("13"), getExternalJCLSourcePath("13"), getExternalJCLRootSourcePath()},
null);
}
+ } else if ("14".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("JCL14_LIB") == null) {
+ setupExternalJCL("jclMin14");
+ JavaCore.setClasspathVariables(
+ new String[] {"JCL14_LIB", "JCL14_SRC", "JCL_SRCROOT"},
+ new IPath[] {getExternalJCLPath("14"), getExternalJCLSourcePath("14"), 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/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
index 34262e9..8318f7b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -54,6 +54,8 @@
// Compilation unit tests
CompilationUnitTests.class,
+ // Compilation unitTests (Java 14)
+ CompilationUnitTests14.class,
// Source attachment tests
AttachSourceTests.class,
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index 29a2923..dbdcfb6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -582,8 +582,12 @@
IType type = classFile.getType();
IField field = type.getField("f"); //$NON-NLS-1$
assertNotNull(field);
- String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
- assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
+ try {
+ String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
+ } catch(JavaModelException e) {
+ // Ignore
+ }
} finally {
// restore classpath
if (savedEntries != null) {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests14.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests14.java
new file mode 100644
index 0000000..b7359e5
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests14.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * Copyright (c) 2020 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import junit.framework.Test;
+
+import javax.lang.model.SourceVersion;
+
+import org.eclipse.jdt.core.*;
+
+public class CompilationUnitTests14 extends ModifyingResourceTests {
+ ICompilationUnit cu;
+ ICompilationUnit workingCopy;
+ IJavaProject testProject;
+
+public CompilationUnitTests14(String name) {
+ super(name);
+}
+
+public void setUpSuite() throws Exception {
+ super.setUpSuite();
+
+ final String compliance = "14"; //$NON-NLS-1$
+ this.testProject = createJavaProject("P", new String[] {"src"}, new String[] {getExternalJCLPathString(compliance)}, "bin", compliance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ createFolder("/P/src/p");
+ createFile(
+ "/P/src/p/X.java",
+ "\n\n" + // package now includes comment (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=93880)
+ // => need some empty line at beginning to be able to have cu without any other element (see testGetElementAt())
+ "/* some comment */" +
+ "package p;\n" +
+ "import p2.*;\n" +
+ "import p3.Z;\n" +
+ "public class X implements Runnable {\n" +
+ " public int f1;\n" +
+ " /** @deprecated\n */" +
+ " protected Object f2;\n" +
+ " private X f3;\n" +
+ " java.lang.String f4;\n" +
+ " int f5, f6, f7;\n" +
+ " @Deprecated\n" +
+ " int f8;\n" +
+ " public class Inner {\n" +
+ " class InnerInner {\n" +
+ " }\n" +
+ " }\n" +
+ " public void foo(Y y) throws IOException {\n" +
+ " }\n" +
+ " protected static Object bar() {\n" +
+ " }\n" +
+ " /** @deprecated\n */" +
+ " private int fred() {\n" +
+ " }\n" +
+ " @Deprecated\n" +
+ " private void fred2() {\n" +
+ " }\n" +
+ " void testIsVarArgs(String s, Object ... args) {\n" +
+ " }\n" +
+ " X(String... s) {\n" +
+ " }\n" +
+ " native void foo2();\n" +
+ " volatile void foo3() {}\n" +
+ " strictfp void foo4() {}\n" +
+ "}\n" +
+ "/** @deprecated\n */" +
+ "interface I {\n" +
+ " int run();\n" +
+ "}\n" +
+ "interface I2<E> {\n" +
+ "}\n" +
+ "@Deprecated\n" +
+ "interface I3 {\n" +
+ "}\n" +
+ "class Y<E> implements I2<E> {\n" +
+ "}\n" +
+ "enum Colors {\n" +
+ " BLUE, WHITE, RED;\n" +
+ "}\n" +
+ "@interface /*c*/ Annot {\n" +
+ " String field();\n" +
+ "}\n" +
+ "record Record() {}"
+ );
+ this.testProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ this.cu = getCompilationUnit("/P/src/p/X.java");
+}
+
+
+
+// Use this static initializer to specify subset for tests
+// All specified tests which do not belong to the class are skipped...
+static {
+// TESTS_PREFIX = "testGetChildren";
+// TESTS_NAMES = new String[] { "testDefaultFlag1" };
+// TESTS_NUMBERS = new int[] { 13 };
+// TESTS_RANGE = new int[] { 16, -1 };
+}
+public static Test suite() {
+ return buildModelTestSuite(CompilationUnitTests14.class);
+}
+protected void tearDown() throws Exception {
+ if (this.workingCopy != null)
+ this.workingCopy.discardWorkingCopy();
+ super.tearDown();
+}
+public void tearDownSuite() throws Exception {
+ this.deleteProject("P");
+ super.tearDownSuite();
+}
+
+/**
+ * Ensures that correct number of types with the correct names and modifiers
+ * exist in a compilation unit.
+ */
+public void testGetTypes() throws JavaModelException {
+ if (canRunJava14()) {
+ IType[] types = this.cu.getTypes();
+ String[] typeNames = new String[] {"X", "I", "I2", "I3", "Y", "Colors", "Annot", "Record"};
+ String[] flags = new String[] {"public", "", "", "", "", "", "", ""};
+ boolean[] isClass = new boolean[] {true, false, false, false, true, false, false, false};
+ boolean[] isInterface = new boolean[] {false, true, true, true, false, false, true, false};
+ boolean[] isAnnotation = new boolean[] {false, false, false, false, false, false, true, false};
+ boolean[] isEnum = new boolean[] {false, false, false, false, false, true, false, false};
+ boolean[] isRecord = new boolean[] {false, false, false, false, false, false, false, true};
+ String[] superclassName = new String[] {null, null, null, null, null, null, null, "java.lang.Record"};
+ String[] superclassType = new String[] {null, null, null, null, null, null, null, "Qjava.lang.Record;"};
+ String[][] superInterfaceNames = new String[][] {
+ new String[] {"Runnable"}, new String[0], new String[0], new String[0], new String[] {"I2<E>"}, new String[0], new String[0], new String[0]
+ };
+ String[][] superInterfaceTypes = new String[][] {
+ new String[] {"QRunnable;"}, new String[0], new String[0], new String[0], new String[] {"QI2<QE;>;"}, new String[0], new String[0], new String[0]
+ };
+ String[][] formalTypeParameters = new String[][] {
+ new String[0], new String[0], new String[] {"E"}, new String[0], new String[] {"E"}, new String[0], new String[0], new String[0]
+ };
+
+ assertEquals("Wrong number of types returned", typeNames.length, types.length);
+ for (int i = 0; i < types.length; i++) {
+ assertEquals("Incorrect name for the " + i + " type", typeNames[i], types[i].getElementName());
+ String mod= Flags.toString(types[i].getFlags());
+ assertEquals("Unexpected modifier for " + types[i].getElementName(), flags[i], mod);
+ assertTrue("Type does not exist " + types[i], types[i].exists());
+ assertEquals("Incorrect isClass for the " + i + " type", isClass[i], types[i].isClass());
+ assertEquals("Incorrect isInterface for the " + i + " type", isInterface[i], types[i].isInterface());
+ assertEquals("Incorrect isAnnotation for the " + i + " type", isAnnotation[i], types[i].isAnnotation());
+ assertEquals("Incorrect isEnum for the " + i + " type", isEnum[i], types[i].isEnum());
+ assertEquals("Incorrect isRecord for the " + i + " type", isRecord[i], types[i].isRecord());
+ assertEquals("Incorrect superclassName for the " + i + " type", superclassName[i], types[i].getSuperclassName());
+ assertEquals("Incorrect superclassType for the " + i + " type", superclassType[i], types[i].getSuperclassTypeSignature());
+ assertEquals("Incorrect superInterfaceNames for the " + i + " type", superInterfaceNames[i].length, types[i].getSuperInterfaceNames().length);
+ assertEquals("Incorrect superInterfaceTypes for the " + i + " type", superInterfaceTypes[i].length, types[i].getSuperInterfaceTypeSignatures().length);
+ assertEquals("Incorrect formalTypeParameters for the " + i + " type", formalTypeParameters[i].length, types[i].getTypeParameters().length);
+ }
+ }
+}
+
+public boolean canRunJava14() {
+ try {
+ SourceVersion.valueOf("RELEASE_14");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+}
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java
new file mode 100644
index 0000000..2995832
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java
@@ -0,0 +1,344 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * 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.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+import junit.framework.Test;
+
+public class CompletionTests14 extends AbstractJavaModelCompletionTests {
+
+ static {
+ // TESTS_NAMES = new String[]{"test034"};
+ }
+
+ public CompletionTests14(String name) {
+ super(name);
+ }
+
+ public void setUpSuite() throws Exception {
+ if (COMPLETION_PROJECT == null) {
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "14");
+ } else {
+ setUpProjectCompliance(COMPLETION_PROJECT, "14");
+ }
+ COMPLETION_PROJECT.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ super.setUpSuite();
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(CompletionTests14.class);
+ }
+
+ public void test001() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point() imple {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "implements[KEYWORD]{implements, null, null, implements, null, 49}",
+ requestor.getResults());
+
+ }
+
+ public void test002() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point() exte {\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);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void test003() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U>() imple {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "implements[KEYWORD]{implements, null, null, implements, null, 49}",
+ requestor.getResults());
+ }
+ public void test004() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U>() exte {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test005() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U extends Thread>() imple {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "implements[KEYWORD]{implements, null, null, implements, null, 49}",
+ requestor.getResults());
+
+ }
+ public void test006() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U extends Thread>() /*here*/exte {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test007() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Completion/src/Point.java",
+ "public record Point(int comp) imple {\n" + "}");
+ this.workingCopies[0].getJavaProject(); // assuming single project for all working copies
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("implements[KEYWORD]{implements, null, null, implements, null, 49}", requestor.getResults());
+
+ }
+ public void test008() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point(int comp) exte {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test009() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U>(int comp) imple {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "implements[KEYWORD]{implements, null, null, implements, null, 49}",
+ requestor.getResults());
+ }
+
+ public void test0010() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U>(int comp) exte {\n" +
+ "}");
+ this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test011() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U extends Thread>(int comp) imple {\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);
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "imple";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "implements[KEYWORD]{implements, null, null, implements, null, 49}",
+ requestor.getResults());
+ }
+ finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ public void test012() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point<U extends Thread>(int comp) /*here*/exte {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/exte";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test013() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[1] = getWorkingCopy(
+ "/Completion/src/mypack1/rrr.java",
+ "package mypack1;\n" +
+ "public record rrr() {\n" +
+ "}");
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/mypack1/MyClass.java",
+ "package mypack1;\n" +
+ "public class MyClass extends /*here*/rr {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/rr";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test0014() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "/**\n" +
+ " * \n" +
+ " * @par \n" +
+ " *\n"+
+ " */\n" +
+ "public record Point() {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "par";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+
+ public void test0015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "/**\n" +
+ " * \n" +
+ " * @par \n" +
+ " *\n"+
+ " */\n" +
+ "public record Point(int a) {\n" +
+ "}");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "par";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "param[JAVADOC_BLOCK_TAG]{@param, null, null, param, null, 38}",
+ requestor.getResults());
+ }
+
+ public void testBug560781() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Point.java",
+ "public record Point(int comp_) { \n" +
+ "}\n"+
+ "class MyClass extends /*here*/Poin \n"
+ );
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/*here*/Poin";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults("", requestor.getResults());
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
index 3dbfe28..bd0dbec 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2019 IBM Corporation and others.
+ * Copyright (c) 2016, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1624,4 +1624,26 @@
deleteProject(project1);
}
}
+public void testBug560606() throws CoreException {
+ IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL19_LIB", "org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, "bin", "9");
+ try {
+ project1.open(null);
+ createFile("/Completion9_1/src/module-info.java",
+ "module first {}\n");
+
+ CompletionResult result = complete(
+ "/Completion9_1/src/bug560606/Test.java",
+ "package bug560606;\n" +
+ "import java.util.Coll;\n" +
+ "public class Test {\n" +
+ "}\n",
+ "import java.util.Coll");
+
+ assertResults(
+ "Collection[TYPE_REF]{Collection, java.util, Ljava.util.Collection;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}",
+ result.proposals);
+ } finally {
+ deleteProject(project1);
+ }
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java
index 0c932c7..6311ed7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019 IBM Corporation and others.
+ * Copyright (c) 2019, 2020 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
@@ -17,7 +17,6 @@
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.IJavaSearchScope;
@@ -31,1017 +30,241 @@
public class JavaSearchBugs13Tests 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 JavaSearchBugs13Tests(String name) {
- super(name);
- this.endChar = "";
-}
-public static Test suite() {
- return buildModelTestSuite(JavaSearchBugs13Tests.class, BYTECODE_DECLARATION_ORDER);
-}
-class TestCollector extends JavaSearchResultCollector {
- public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
- super.acceptSearchMatch(searchMatch);
+ // 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"};
}
-}
-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(']');
+
+ public JavaSearchBugs13Tests(String name) {
+ super(name);
+ this.endChar = "";
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(JavaSearchBugs13Tests.class, BYTECODE_DECLARATION_ORDER);
+ }
+
+ class TestCollector extends JavaSearchResultCollector {
+ public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
+ super.acceptSearchMatch(searchMatch);
}
}
-}
-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) {
+ 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(other.getElementName());
+ this.line.append(localElement.getElementName());
this.line.append(" on ");
- this.line.append(other.getParent().getElementName());
+ this.line.append(localElement.getParent().getElementName());
} else {
- this.line.append(other.getElementName());
+ this.line.append(localElement.getElementName());
}
+ this.line.append(']');
}
- this.line.append(']');
}
}
-}
-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() {};
+ 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(']');
+ }
+ }
}
- return getWorkingCopy(path, source, this.wcOwner);
-}
-@Override
-public void setUpSuite() throws Exception {
- super.setUpSuite();
- JAVA_PROJECT = setUpJavaProject("JavaSearchBugs", "13");
-}
-public void tearDownSuite() throws Exception {
- deleteProject("JavaSearchBugs");
- super.tearDownSuite();
-}
-protected void setUp () throws Exception {
- super.setUp();
- this.resultCollector = new TestCollector();
- this.resultCollector.showAccuracy(true);
-}
-//copy from JavaSearchBugs12Tests starts ( after deleting break with value tests since that is discarded)
-
-public void testBug542559_001() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- " int switch_expr_field = 10;\n" +
- " int twice(int i) {\n" +
- " int tw = switch (i) {\n" +
- " case 0 -> switch_expr_field * 0;\n" +
- " case 1 -> 2;\n" +
- " default -> 3;\n" +
- " };\n" +
- " return tw;\n" +
- " }\n" +
- " public static void main(String... args) {\n" +
- " System.out.print(new X().twice(3));\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("switch_expr_field", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ 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);
+ }
-/*
- * java search reference for an integer in default block of switch expression
- */
-public void testBug542559_004() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- " int switch_expr_field = 10;\n" +
- " int twice(int i) {\n" +
- " int tw = switch (i) {\n" +
- " case 0 -> switch_expr_field * 0;\n" +
- " case 1 -> 2;\n" +
- " default ->{ \n" +
- " switch_expr_field*9; \n" +
- " }};\n" +
- " return tw;\n" +
- " }\n" +
- " public static void main(String... args) {\n" +
- " System.out.print(new X().twice(3));\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("switch_expr_field", FIELD, REFERENCES);
+ 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", "13");
+ }
+
+ public void tearDownSuite() throws Exception {
+ deleteProject("JavaSearchBugs");
+ super.tearDownSuite();
+ }
+
+ protected void setUp () throws Exception {
+ super.setUp();
+ this.resultCollector = new TestCollector();
+ this.resultCollector.showAccuracy(true);
+ }
+
+ // all preview related Java 13 switch expression tests deleted
+ // enabled preview and moved to JavaSearchBugs14SwitchExpressionTests
+
+ public void testBug549413_017() throws CoreException {
+ //select local variable and find the declaration
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) {\n"+
+ " int yield = 100;\n"+
+ " int r = switch(i) {\n"+
+ " default -> {yield /* here*/ yield + yield + yield * yield;}\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}\n"
+ );
+
+ String str = this.workingCopies[0].getSource();
+ String selection = "/* here*/ yield";
+ 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 int X.twice(int) [switch_expr_field] EXACT_MATCH\n" +
- "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ "src/X.java int X.foo(int).yield [yield] EXACT_MATCH");
}
-}
-/*
- * java search reference for an integer in default of switch expression
- */
-public void testBug542559_005() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- " int switch_expr_field = 10;\n" +
- " int twice(int i) {\n" +
- " int tw = switch (i) {\n" +
- " case 0 -> switch_expr_field * 0;\n" +
- " case 1 -> 2;\n" +
- " default -> switch_expr_field*9;\n" +
- " };\n" +
- " return tw;\n" +
- " }\n" +
- " public static void main(String... args) {\n" +
- " System.out.print(new X().twice(3));\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("switch_expr_field", FIELD, REFERENCES);
+
+ public void testBug549413_018() throws CoreException {
+ //select local variable and find the declaration
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) {\n"+
+ " int localVar = 100;\n"+
+ " int r = switch(i) {\n"+
+ " default -> {yield /* here*/ localVar + localVar + localVar * localVar;}\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}\n"
+ );
+
+ String str = this.workingCopies[0].getSource();
+ String selection = "/* here*/ localVar";
+ 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 int X.twice(int) [switch_expr_field] EXACT_MATCH\n" +
- "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ "src/X.java int X.foo(int).localVar [localVar] EXACT_MATCH");
}
-}
+
+ // add non-preview stuff involving yield field and method
+ public void testBug549413_019() throws CoreException {
+ //old style switch case without preview search for yield field.
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n"+
+ " static int yield;\n"+
+ " public static int yield() { \n"+
+ " return 7; \n"+
+ " } \n"+
+ " public static void main(String[] args) { \n"+
+ " int week = 1; \n"+
+ " switch (week) { \n"+
+ " case 1: \n"+
+ " yield = 88; \n"+
+ " break; \n"+
+ " case 2: \n"+
+ " yield = yield();\n"+
+ " break; \n"+
+ " default: \n"+
+ " yield = 88; \n"+
+ " break; \n" +
+ " } \n" +
+ " System.out.println(yield); \n"+
+ " }\n"+
+ "}\n"
+ );
-/*
- * java search reference for simple multi constant case statement for enum
- */
-public void testBug542559_006() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- "enum Day { SATURDAY, SUNDAY, MONDAY;}\n" +
- "public static void bar(Day day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUNDAY: \n" +
- " System.out.println(Day.SUNDAY);\n" +
- " break;\n" +
- " case MONDAY : System.out.println(Day.MONDAY);\n" +
- " break;\n" +
- " }\n" +
- " }" +
- " public static void main(String[] args) {\n" +
- " bar(Day.SATURDAY);\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("SATURDAY", FIELD, REFERENCES);
- assertSearchResults(
- "src/X.java void X.bar(Day) [SATURDAY] EXACT_MATCH\n"+
- "src/X.java void X.main(String[]) [SATURDAY] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ try {
+ search("yield", FIELD, REFERENCES);
+ assertSearchResults("src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
+ "src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
+ "src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
+ "src/X.java void X.main(String[]) [yield] EXACT_MATCH");
+ } finally {
+ }
}
-}
-/*
- * java search reference for simple multi constant case statement for enum, 2nd case
- */
-public void testBug542559_007() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- "enum Day { SATURDAY, SUNDAY, MONDAY;}\n" +
- "public static void bar(Day day) {\n" +
- " switch (day) {\n" +
- " case SATURDAY, SUNDAY: \n" +
- " System.out.println(Day.SUNDAY);\n" +
- " break;\n" +
- " case MONDAY : System.out.println(Day.MONDAY);\n" +
- " break;\n" +
- " }\n" +
- " }" +
- " public static void main(String[] args) {\n" +
- " bar(Day.SATURDAY);\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("SUNDAY", FIELD, REFERENCES);
- assertSearchResults(
- "src/X.java void X.bar(Day) [SUNDAY] EXACT_MATCH\n"+
- "src/X.java void X.bar(Day) [SUNDAY] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+
+ public void testBug549413_020() throws CoreException {
+ //old style switch case without preview search for yield method.
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n"+
+ " static int yield;\n"+
+ " public static int yield() { \n"+
+ " return 7; \n"+
+ " } \n"+
+ " public static void main(String[] args) { \n"+
+ " int week = 1; \n"+
+ " switch (week) { \n"+
+ " case 1: \n"+
+ " yield = 88; \n"+
+ " break; \n"+
+ " case 2: \n"+
+ " yield = yield();\n"+
+ " break; \n"+
+ " default: \n"+
+ " yield = 88; \n"+
+ " break; \n" +
+ " } \n" +
+ " System.out.println(yield); \n"+
+ " }\n"+
+ "}\n"
+ );
+
+ try {
+ search("yield", METHOD, REFERENCES);
+ assertSearchResults("src/X.java void X.main(String[]) [yield()] EXACT_MATCH");
+ } finally {
+ }
}
}
-
-/*
- * java search reference for class file reference in switch expression
- */
-public void testBug542559_008() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X2.java",
- "public class X2 {\n" +
- " String s = new String(); \n" +
- " int switch_expr_field = 10;\n" +
- " int twice(int i) {\n" +
- " int tw = switch (i) {\n" +
- " case 0 -> switch_expr_field * 0;\n" +
- " case 1 -> 2;\n" +
- " default -> new X2().toString().length();\n" +
- " };\n" +
- " return tw;\n" +
- " }\n" +
- " public static void main(String... args) {\n" +
- " System.out.print(new X2().twice(3));\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("X2", CLASS, REFERENCES);
- assertSearchResults(
- "src/X2.java int X2.twice(int) [X2] EXACT_MATCH\n"+
- "src/X2.java void X2.main(String ...) [X2] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-
-/*
- * java search a method reference in switch expression
- */
-public void testBug542559_0012() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "import java.util.function.Supplier;\n" +
- "interface I0 { void i(); }\n" +
- "interface I1 extends I0 {}\n" +
- "interface I2 extends I0 {}\n" +
- "public class X {\n" +
- " I1 n1() { return null; }\n" +
- " <I extends I2> I n2() { return null; }\n" +
- " <M> M m(Supplier<M> m) { return m.get(); }\n" +
- " void test(int i, boolean b) {\n" +
- " m(switch (i) {\n" +
- " case 1 -> this::n1;\n" +
- " default -> this::n2;\n" +
- " }).i(); \n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " try {\n" +
- " new X().test(1, true);\n" +
- " } catch (NullPointerException e) {\n" +
- " System.out.println(\"NPE as expected\");\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("n1", METHOD, REFERENCES);
- assertSearchResults("src/X.java void X.test(int, boolean) [n1] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-// copy from JavaSearchBugs12Tests ends
-
-public void testBug549413_001() throws CoreException {
- // field reference in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- "int switch_expr_field = 10; \n" +
- "public static int foo(int val) {\n" +
- "int k = switch (val) {\n" +
- "case 1 -> { yield switch_expr_field; }\n" +
- "default -> { yield 2; }\n" +
- "};\n" +
- "return k;\n" +
- "}\n" +
- " public static void main(String... args) {\n" +
- " System.out.println(X.foo(2));\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("switch_expr_field", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [switch_expr_field] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_002() throws CoreException {
- //field all occurrences in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- "int switch_expr_field = 10; \n" +
- "public static int foo(int val) {\n" +
- "int k = switch (val) {\n" +
- "case 1 -> { yield switch_expr_field; }\n" +
- "default -> { yield 2; }\n" +
- "};\n" +
- "return k;\n" +
- "}\n" +
- " public static void main(String... args) {\n" +
- " System.out.println(X.foo(2));\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("switch_expr_field", FIELD, ALL_OCCURRENCES);
- assertSearchResults("src/X.java X.switch_expr_field [switch_expr_field] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [switch_expr_field] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_003() throws CoreException {
- //METHOD named yield - all occurrences in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " public static int yield() {\n"+
- " return 1;\n"+
- " }\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int val) {\n"+
- " int k = switch (val) {\n"+
- " case 1 -> { yield 1; }\n"+
- " default -> { yield 2; }\n"+
- " };\n"+
- " return k;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(1));\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("yield", METHOD, ALL_OCCURRENCES);
- assertSearchResults("src/X.java int X.yield() [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_004() throws CoreException {
- //METHOD yield - references in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " public static int yield() {\n"+
- " return 1;\n"+
- " }\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int val) {\n"+
- " int k = switch (val) {\n"+
- " case 1 -> { yield X.yield(); }\n"+
- " default -> { yield 2; }\n"+
- " };\n"+
- " return k;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(1));\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("yield", METHOD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield()] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_005() throws CoreException {
- //field yield - references in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " public static int yield;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int val) {\n"+
- " int k = switch (val) {\n"+
- " case 1 -> { yield yield; }\n"+
- " default -> { yield 2; }\n"+
- " };\n"+
- " return k;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(1));\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_006() throws CoreException {
- //field yield - all occurrence in yield
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " public static int yield;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int val) {\n"+
- " int k = switch (val) {\n"+
- " case 1 -> { yield yield; }\n"+
- " default -> { yield 2; }\n"+
- " };\n"+
- " return k;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(1));\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("yield", FIELD, ALL_OCCURRENCES);
- assertSearchResults("src/X.java X.yield [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_007() throws CoreException {
- //field yield - all reference of identifier in yield statement
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " public static int yield;\n"+
- " public static int abc;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int val) {\n"+
- " int k = switch (val) {\n"+
- " case 1 -> { abc=0;yield yield; }\n"+
- " default -> { yield 2; }\n"+
- " };\n"+
- " return k;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(1));\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("abc", FIELD, ALL_OCCURRENCES);
- assertSearchResults("src/X.java X.abc [abc] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [abc] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_008() throws CoreException {
- //field yield - all reference of identifier in yield statement ( yield -1 without braces)
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " static int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default -> yield - 1;\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public int yield() {\n"+
- " return 0;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_009() throws CoreException {
- //field yield - all reference of identifier in yield statement ( yield -1 with braces)
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default ->{ yield - 1;}\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public int yield() {\n"+
- " return 0;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_010() throws CoreException {
- //method - break label
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " static int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default -> X.yield();\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static int yield() {\n"+
- " yield: while (X.yield == 100) {\n"+
- " yield = 256;\n"+
- " break yield;\n"+
- " }\n"+
- " return yield;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", METHOD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield()] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_011() throws CoreException {
- //break label in combination with yield field
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " static int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default -> X.yield();\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static int yield() {\n"+
- " yield: while (X.yield == 100) {\n"+
- " yield = 256;\n"+
- " break yield;\n"+
- " }\n"+
- " return yield;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.yield() [yield] EXACT_MATCH\n" +
- "src/X.java int X.yield() [yield] EXACT_MATCH\n" +
- "src/X.java int X.yield() [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_012() throws CoreException {
- //field yield - multiple yield references
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " static int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default -> {yield yield + yield + yield * yield;}\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_013() throws CoreException {
- //field yield -another yield field test
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " static int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " default ->0 + yield + 10;\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_014() throws CoreException {
- //field yield - ternary operator
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " case 0 : yield 100;\n"+
- " case 1 : yield yield;\n"+
- " default: yield 0;\n"+
- " };\n"+
- " return r > 100 ? yield + 1 : yield + 200;\n"+
- " }\n"+
- " public static void main(String[] args) {\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_015() throws CoreException {
- //field yield - another test case
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " case 0 : yield 100;\n"+
- " case 1 : yield yield;\n"+
- " default: yield 0;\n"+
- " };\n"+
- " return r > 100 ? yield() + 1 : yield + 200;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " }\n"+
- " public static int yield() {\n"+
- " return 1;\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("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [yield] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-
-public void testBug549413_016() throws CoreException {
- //method yield -method references
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " int yield = 100;\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public int foo(int i) {\n"+
- " int r = switch(i) {\n"+
- " case 0 : yield 100;\n"+
- " case 1 : yield yield;\n"+
- " default: yield 0;\n"+
- " };\n"+
- " return r > 100 ? yield() + 1 : yield + 200;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " }\n"+
- " public static int yield() {\n"+
- " return 1;\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("yield", METHOD, REFERENCES);
- assertSearchResults("src/X.java int X.foo(int) [yield()] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-public void testBug549413_017() throws CoreException {
- //select local variable and find the declaration
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- "\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int yield = 100;\n"+
- " int r = switch(i) {\n"+
- " default -> {yield /* here*/ yield + yield + yield * yield;}\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\n"+
- " }\n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/ yield";
- 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 int X.foo(int).yield [yield] EXACT_MATCH");
-}
-
-
-public void testBug549413_018() throws CoreException {
- //select local variable and find the declaration
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static int foo(int i) {\n"+
- " int localVar = 100;\n"+
- " int r = switch(i) {\n"+
- " default -> {yield /* here*/ localVar + localVar + localVar * localVar;}\n"+
- " };\n"+
- " return r;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.println(X.foo(0));\n"+
- " }\n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/ localVar";
- 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 int X.foo(int).localVar [localVar] EXACT_MATCH");
-}
-// add non-preview stuff involving yield field and method
-
-public void testBug549413_019() throws CoreException {
- //old style switch case without preview search for yield field.
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " static int yield;\n"+
- " public static int yield() { \n"+
- " return 7; \n"+
- " } \n"+
- " public static void main(String[] args) { \n"+
- " int week = 1; \n"+
- " switch (week) { \n"+
- " case 1: \n"+
- " yield = 88; \n"+
- " break; \n"+
- " case 2: \n"+
- " yield = yield();\n"+
- " break; \n"+
- " default: \n"+
- " yield = 88; \n"+
- " break; \n" +
- " } \n" +
- " System.out.println(yield); \n"+
- " }\n"+
- "}\n"
-);
-
-
- try {
- search("yield", FIELD, REFERENCES);
- assertSearchResults("src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
- "src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
- "src/X.java void X.main(String[]) [yield] EXACT_MATCH\n" +
- "src/X.java void X.main(String[]) [yield] EXACT_MATCH");
- } finally {
- }
-}
-
-public void testBug549413_020() throws CoreException {
- //old style switch case without preview search for yield method.
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n"+
- " static int yield;\n"+
- " public static int yield() { \n"+
- " return 7; \n"+
- " } \n"+
- " public static void main(String[] args) { \n"+
- " int week = 1; \n"+
- " switch (week) { \n"+
- " case 1: \n"+
- " yield = 88; \n"+
- " break; \n"+
- " case 2: \n"+
- " yield = yield();\n"+
- " break; \n"+
- " default: \n"+
- " yield = 88; \n"+
- " break; \n" +
- " } \n" +
- " System.out.println(yield); \n"+
- " }\n"+
- "}\n"
-);
-
-
- try {
- search("yield", METHOD, REFERENCES);
- assertSearchResults("src/X.java void X.main(String[]) [yield()] EXACT_MATCH");
- } finally {
- }
-}
-
-}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs14SwitchExpressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs14SwitchExpressionTests.java
new file mode 100644
index 0000000..0db06df
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs14SwitchExpressionTests.java
@@ -0,0 +1,1053 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+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.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.TypeReferenceMatch;
+
+import junit.framework.Test;
+
+/**
+ * Moved from JavaSearchBugs13Tests
+ * All preview option disabled
+ * @author vikchand
+ *
+ */
+public class JavaSearchBugs14SwitchExpressionTests 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 JavaSearchBugs14SwitchExpressionTests(String name) {
+ super(name);
+ this.endChar = "";
+}
+public static Test suite() {
+ return buildModelTestSuite(JavaSearchBugs14SwitchExpressionTests.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(']');
+ }
+ }
+}
+
+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", "14");
+}
+public void tearDownSuite() throws Exception {
+ deleteProject("JavaSearchBugs");
+ super.tearDownSuite();
+}
+protected void setUp () throws Exception {
+ super.setUp();
+ this.resultCollector = new TestCollector();
+ this.resultCollector.showAccuracy(true);
+}
+
+//copy from JavaSearchBugs12Tests starts ( after deleting break with value tests since that is discarded)
+
+public void testBug542559_001() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ " int switch_expr_field = 10;\n" +
+ " int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> switch_expr_field * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(new X().twice(3));\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.DISABLED);
+ search("switch_expr_field", FIELD, REFERENCES);
+ assertSearchResults("src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH");
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+}
+
+
+/*
+ * java search reference for an integer in default block of switch expression
+ */
+public void testBug542559_004() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ " int switch_expr_field = 10;\n" +
+ " int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> switch_expr_field * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default ->{ \n" +
+ " switch_expr_field*9; \n" +
+ " }};\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(new X().twice(3));\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.DISABLED);
+ search("switch_expr_field", FIELD, REFERENCES);
+ assertSearchResults(
+ "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH\n" +
+ "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH"
+ );
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+}
+
+/*
+ * java search reference for an integer in default of switch expression
+ */
+public void testBug542559_005() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ " int switch_expr_field = 10;\n" +
+ " int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> switch_expr_field * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> switch_expr_field*9;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(new X().twice(3));\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.DISABLED);
+ search("switch_expr_field", FIELD, REFERENCES);
+ assertSearchResults(
+ "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH\n" +
+ "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH"
+ );
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+}
+
+/*
+ * java search reference for simple multi constant case statement for enum
+ */
+public void testBug542559_006() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " case MONDAY : System.out.println(Day.MONDAY);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] args) {\n" +
+ " bar(Day.SATURDAY);\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.DISABLED);
+ search("SATURDAY", FIELD, REFERENCES);
+ assertSearchResults(
+ "src/X.java void X.bar(Day) [SATURDAY] EXACT_MATCH\n"+
+ "src/X.java void X.main(String[]) [SATURDAY] EXACT_MATCH"
+ );
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+}
+/*
+ * java search reference for simple multi constant case statement for enum, 2nd case
+ */
+public void testBug542559_007() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "public class X {\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " case MONDAY : System.out.println(Day.MONDAY);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] args) {\n" +
+ " bar(Day.SATURDAY);\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.DISABLED);
+ search("SUNDAY", FIELD, REFERENCES);
+ assertSearchResults(
+ "src/X.java void X.bar(Day) [SUNDAY] EXACT_MATCH\n"+
+ "src/X.java void X.bar(Day) [SUNDAY] EXACT_MATCH"
+ );
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+}
+
+/*
+ * java search reference for class file reference in switch expression
+ */
+public void testBug542559_008() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X2.java",
+ "public class X2 {\n" +
+ " String s = new String(); \n" +
+ " int switch_expr_field = 10;\n" +
+ " int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> switch_expr_field * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> new X2().toString().length();\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(new X2().twice(3));\n" +
+ " }\n" +
+ "}\n"
+ );
+ IJavaProject javaProject = this.workingCop